This commit is contained in:
AdisakKanthawilang 2024-06-13 17:38:01 +07:00
parent e6539edaec
commit 52e0141de4
3 changed files with 52 additions and 14 deletions

View file

@ -1934,6 +1934,8 @@ export class ProfileController extends Controller {
*/
@Post("search-personal")
async getProfileBySearchKeyword(
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Body()
body: {
fieldName: string;
@ -1941,9 +1943,12 @@ export class ProfileController extends Controller {
},
) {
let findProfile: any;
let total: any;
const skip = (page - 1) * pageSize;
const take = pageSize;
switch (body.fieldName) {
case "idcard":
findProfile = await this.profileRepo.find({
case "citizenId":
[findProfile, total] = await this.profileRepo.find({
where: { citizenId: Like(`%${body.keyword}%`) },
relations: [
"posType",
@ -1956,11 +1961,13 @@ export class ProfileController extends Controller {
"current_holders.orgChild3",
"current_holders.orgChild4",
],
skip,
take,
});
break;
case "firstname":
findProfile = await this.profileRepo.find({
[findProfile, total] = await this.profileRepo.find({
where: { firstName: Like(`%${body.keyword}%`) },
relations: [
"posType",
@ -1973,11 +1980,13 @@ export class ProfileController extends Controller {
"current_holders.orgChild3",
"current_holders.orgChild4",
],
skip,
take,
});
break;
case "lastname":
findProfile = await this.profileRepo.find({
[findProfile, total] = await this.profileRepo.find({
where: { lastName: Like(`%${body.keyword}%`) },
relations: [
"posType",
@ -1990,11 +1999,13 @@ export class ProfileController extends Controller {
"current_holders.orgChild3",
"current_holders.orgChild4",
],
skip,
take,
});
break;
default:
findProfile = await this.profileRepo.find({
[findProfile, total] = await this.profileRepo.find({
relations: [
"posType",
"posLevel",
@ -2006,6 +2017,8 @@ export class ProfileController extends Controller {
"current_holders.orgChild3",
"current_holders.orgChild4",
],
skip,
take,
});
break;
}
@ -2095,7 +2108,7 @@ export class ProfileController extends Controller {
firstName: item.firstName,
lastName: item.lastName,
position: item.position,
idcard: item.citizenId,
citizenId: item.citizenId,
email: item.email,
phone: item.phone,
name: fullName,
@ -2157,7 +2170,7 @@ export class ProfileController extends Controller {
}),
);
return new HttpSuccess(mapDataProfile);
return new HttpSuccess({ data: mapDataProfile, total });
}
/**

View file

@ -1356,6 +1356,8 @@ export class ProfileEmployeeController extends Controller {
*/
@Post("search-personal")
async getProfileBySearchKeyword(
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Body()
body: {
fieldName: string;
@ -1363,9 +1365,12 @@ export class ProfileEmployeeController extends Controller {
},
) {
let findProfile: any;
let total: any;
const skip = (page - 1) * pageSize;
const take = pageSize;
switch (body.fieldName) {
case "idcard":
findProfile = await this.profileRepo.find({
case "citizenId":
[findProfile, total] = await this.profileRepo.find({
where: { citizenId: Like(`%${body.keyword}%`) },
relations: [
"posType",
@ -1378,11 +1383,13 @@ export class ProfileEmployeeController extends Controller {
"current_holders.orgChild3",
"current_holders.orgChild4",
],
skip,
take,
});
break;
case "firstname":
findProfile = await this.profileRepo.find({
[findProfile, total] = await this.profileRepo.find({
where: { firstName: Like(`%${body.keyword}%`) },
relations: [
"posType",
@ -1395,11 +1402,13 @@ export class ProfileEmployeeController extends Controller {
"current_holders.orgChild3",
"current_holders.orgChild4",
],
skip,
take,
});
break;
case "lastname":
findProfile = await this.profileRepo.find({
[findProfile, total] = await this.profileRepo.find({
where: { lastName: Like(`%${body.keyword}%`) },
relations: [
"posType",
@ -1412,11 +1421,13 @@ export class ProfileEmployeeController extends Controller {
"current_holders.orgChild3",
"current_holders.orgChild4",
],
skip,
take,
});
break;
default:
findProfile = await this.profileRepo.find({
[findProfile, total] = await this.profileRepo.find({
relations: [
"posType",
"posLevel",
@ -1428,6 +1439,8 @@ export class ProfileEmployeeController extends Controller {
"current_holders.orgChild3",
"current_holders.orgChild4",
],
skip,
take,
});
break;
}
@ -1517,7 +1530,7 @@ export class ProfileEmployeeController extends Controller {
firstName: item.firstName,
lastName: item.lastName,
position: item.position,
idcard: item.citizenId,
citizenId: item.citizenId,
email: item.email,
phone: item.phone,
name: fullName,
@ -1579,7 +1592,7 @@ export class ProfileEmployeeController extends Controller {
}),
);
return new HttpSuccess(mapDataProfile);
return new HttpSuccess({ data: mapDataProfile, total });
}
/**

View file

@ -33,6 +33,7 @@ import {
import { AppDataSource } from "../database/data-source";
import { Profile } from "../entities/Profile";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import { IsNull } from "typeorm";
// import * as io from "../lib/websocket";
// import elasticsearch from "../elasticsearch";
// import { StorageFolder } from "../interfaces/storage-fs";
@ -184,6 +185,17 @@ export class KeycloakController extends Controller {
async deleteUser(@Path() userId: string) {
const result = await deleteUser(userId);
if (!result) throw new Error("Failed. Cannot delete userId.");
const profile = await this.profileRepo.findOne({
where: {
id: userId,
},
});
if (profile) {
profile.keycloak = "";
await this.profileRepo.save(profile);
}
}
// @Security("bearerAuth", ["system", "admin"])