Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop
This commit is contained in:
commit
1a851ccf95
1 changed files with 50 additions and 7 deletions
|
|
@ -12,6 +12,7 @@ import {
|
|||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
|
|
@ -254,8 +255,12 @@ export class ProfileController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Get()
|
||||
async listProfile() {
|
||||
const profile = await this.profileRepository.find({
|
||||
async listProfile(
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("keyword") keyword?: string,
|
||||
) {
|
||||
const [profile, total] = await this.profileRepository.findAndCount({
|
||||
select: [
|
||||
"id",
|
||||
"prefix",
|
||||
|
|
@ -267,16 +272,54 @@ export class ProfileController extends Controller {
|
|||
"posTypeId",
|
||||
],
|
||||
order: { createdAt: "ASC" },
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
});
|
||||
if (keyword != undefined && keyword !== "") {
|
||||
const formattedKeyword = keyword.toLowerCase().replace(/\s+/g, "");
|
||||
const filteredProfile = profile.filter(
|
||||
(x) =>
|
||||
(
|
||||
x.prefix +
|
||||
x.firstName +
|
||||
x.lastName
|
||||
)
|
||||
.replace(/\s+/g, "")
|
||||
.includes(formattedKeyword) ||
|
||||
x.citizenId?.toString().includes(keyword) ||
|
||||
x.position?.toString().includes(keyword)
|
||||
);
|
||||
|
||||
const formattedData = filteredProfile.map((item) => ({
|
||||
id: item.id,
|
||||
prefix: item.prefix,
|
||||
firstName: item.firstName,
|
||||
lastName: item.lastName,
|
||||
citizenId: item.citizenId,
|
||||
position: item.position,
|
||||
posLevelId: item.posLevelId,
|
||||
posTypeId: item.posTypeId
|
||||
}));
|
||||
|
||||
return new HttpSuccess({ data: formattedData, total: formattedData.length });
|
||||
}
|
||||
|
||||
if (!profile) {
|
||||
return new HttpSuccess([]);
|
||||
}
|
||||
try {
|
||||
return new HttpSuccess(profile);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
const formattedData = profile.map((item) => ({
|
||||
id: item.id,
|
||||
prefix: item.prefix,
|
||||
firstName: item.firstName,
|
||||
lastName: item.lastName,
|
||||
citizenId: item.citizenId,
|
||||
position: item.position,
|
||||
posLevelId: item.posLevelId,
|
||||
posTypeId: item.posTypeId
|
||||
}));
|
||||
return new HttpSuccess({ data: formattedData, total });
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue