Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 55s

* develop:
  sort
  sort org command
  fix
  sort probation
  no message
  no message
  fix
  sort แก้ไขทะเบียนประวัติ ตำแหน่ง/เงินเดือน
  #1409 แก้เป็นส่ง refId ของคำสั่งขอลาออกไปค้นที่ command ก่อนอัพ status = CANCEL
  api add permission org
  add-role-staff/user
  API อัพเดทสถานะ CANCEL คำสั่งยกเลิกการลาออก, คำสั่งยกเลิกการลาออกลูกจ้าง #1409
  fix
  sort admin
  sort admin
  no message
  บัญชี 2 แบบร่าง ข้อมูลแสดงไม่ครบ #164
This commit is contained in:
Warunee Tamkoo 2025-09-30 16:25:03 +07:00
commit 2256ef88bf
12 changed files with 617 additions and 92 deletions

View file

@ -160,6 +160,8 @@ export class CommandController extends Controller {
@Get("list") @Get("list")
async GetResult( async GetResult(
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
@Query("sortBy") sortBy?: string,
@Query("descending") descending?: boolean,
@Query("page") page: number = 1, @Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query() keyword: string = "", @Query() keyword: string = "",
@ -262,14 +264,9 @@ export class CommandController extends Controller {
yearKeyword = match[1].trim(); yearKeyword = match[1].trim();
} }
let yearInBC = yearKeyword ? parseInt(yearKeyword) - 543 : null; let yearInBC = yearKeyword ? parseInt(yearKeyword) - 543 : null;
//
// console.log("k>>",keyword); // const [commands, total] = await this.commandRepository
// console.log("bk>>",baseKeyword); let query = await this.commandRepository
// console.log("yk>>",yearKeyword);
// console.log("yi>>",yearInBC);
const [commands, total] = await this.commandRepository
.createQueryBuilder("command") .createQueryBuilder("command")
.leftJoinAndSelect("command.commandType", "commandType") .leftJoinAndSelect("command.commandType", "commandType")
.andWhere( .andWhere(
@ -339,6 +336,15 @@ export class CommandController extends Controller {
}), }),
) )
.orderBy("command.createdAt", "DESC") .orderBy("command.createdAt", "DESC")
if (sortBy) {
query = query.orderBy(
`command.${sortBy}`,
descending ? "DESC" : "ASC"
);
}
let [commands, total] = await query
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();
@ -3012,6 +3018,38 @@ export class CommandController extends Controller {
return new HttpSuccess(_data); return new HttpSuccess(_data);
} }
/**
* API CANCEL ,
*
* @summary API CANCEL ,
*
*/
@Post("cancel-resign")
public async command41Excecute(
@Request() req: RequestWithUser,
@Body()
body: {
resignId: string[];
},
) {
const _refId = Array.from(new Set(body.resignId));
// 1. ดึง commandRecive ที่ refId ตรงกับ resignId
const commandRecives = await this.commandReciveRepository.find({
select: ["commandId"],
where: { refId: In(_refId) },
});
// 2. ดึง commandId ที่ไม่ซ้ำ
const commandIds = Array.from(new Set(commandRecives.map(x => x.commandId).filter(Boolean)));
// 3. อัปเดต status ของ command
if (commandIds.length > 0) {
await this.commandRepository.update(
{ id: In(commandIds) },
{ status: "CANCEL" }
);
}
return new HttpSuccess();
}
@Post("excexute/salary-current") @Post("excexute/salary-current")
public async newSalaryAndUpdateCurrent( public async newSalaryAndUpdateCurrent(
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@ -3443,6 +3481,7 @@ export class CommandController extends Controller {
orgChild2New?: string | null; orgChild2New?: string | null;
orgChild3New?: string | null; orgChild3New?: string | null;
orgChild4New?: string | null; orgChild4New?: string | null;
resignId?: string | null;
}[]; }[];
}, },
) { ) {
@ -3507,6 +3546,19 @@ export class CommandController extends Controller {
if (code && ["C-PM-08", "C-PM-17", "C-PM-18"].includes(code)) { if (code && ["C-PM-08", "C-PM-17", "C-PM-18"].includes(code)) {
removePostMasterAct(profile.id); removePostMasterAct(profile.id);
} }
//ออกคำสั่งยกเลิกลาออกต้องอัพเดทสถานะคำสั่งลาออกเป็น CANCEL
else if (item.resignId && code && ["C-PM-41"].includes(code)) {
const commandRecive = await this.commandReciveRepository.findOne({
select: ["commandId"],
where: { refId: item.resignId },
});
if (commandRecive && commandRecive.commandId) {
await this.commandRepository.update(
{ id: commandRecive?.commandId },
{ status: "CANCEL" }
);
}
}
let _commandYear = item.commandYear; let _commandYear = item.commandYear;
if (item.commandYear) { if (item.commandYear) {
_commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543; _commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543;
@ -3773,6 +3825,7 @@ export class CommandController extends Controller {
commandCode?: string | null; commandCode?: string | null;
commandName?: string | null; commandName?: string | null;
remark: string | null; remark: string | null;
resignId: string | null;
}[]; }[];
}, },
) { ) {
@ -3828,6 +3881,20 @@ export class CommandController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const code = _command?.commandType?.code;
//ออกคำสั่งยกเลิกลาออกต้องอัพเดทสถานะคำสั่งลาออกเป็น CANCEL
if (item.resignId && code && ["C-PM-42"].includes(code)) {
const commandRecive = await this.commandReciveRepository.findOne({
select: ["commandId"],
where: { refId: item.resignId },
});
if (commandRecive && commandRecive.commandId) {
await this.commandRepository.update(
{ id: commandRecive?.commandId },
{ status: "CANCEL" }
);
}
}
let _commandYear = item.commandYear; let _commandYear = item.commandYear;
if (item.commandYear) { if (item.commandYear) {
_commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543; _commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543;

View file

@ -127,6 +127,8 @@ export class DevelopmentRequestController extends Controller {
@Query("keyword") keyword: string = "", @Query("keyword") keyword: string = "",
@Query("page") page: number = 1, @Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query("sortBy") sortBy?: string,
@Query("descending") descending?: boolean,
) { ) {
let data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER"); let data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER");
const orgRevisionPublish = await this.orgRevisionRepository const orgRevisionPublish = await this.orgRevisionRepository
@ -134,7 +136,7 @@ export class DevelopmentRequestController extends Controller {
.where("orgRevision.orgRevisionIsDraft = false") .where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true") .andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne(); .getOne();
const [lists, total] = await AppDataSource.getRepository(DevelopmentRequest) let query = await AppDataSource.getRepository(DevelopmentRequest)
.createQueryBuilder("developmentRequest") .createQueryBuilder("developmentRequest")
.leftJoinAndSelect("developmentRequest.profile", "profile") .leftJoinAndSelect("developmentRequest.profile", "profile")
.leftJoinAndSelect("profile.current_holders", "current_holders") .leftJoinAndSelect("profile.current_holders", "current_holders")
@ -249,9 +251,20 @@ export class DevelopmentRequestController extends Controller {
}), }),
) )
.orderBy("developmentRequest.createdAt", "DESC") .orderBy("developmentRequest.createdAt", "DESC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount(); if (sortBy) {
query = query.orderBy(
`developmentRequest.${sortBy}`,
descending ? "DESC" : "ASC"
);
}
const [lists, total] = await query
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const _data = lists.map((item) => ({ ...item, profile: null })); const _data = lists.map((item) => ({ ...item, profile: null }));
return new HttpSuccess({ data: _data, total }); return new HttpSuccess({ data: _data, total });
} }

View file

@ -30,6 +30,7 @@ import { checkQueueInProgress, setLogDataDiff } from "../interfaces/utils";
import { sendToQueueOrg, sendToQueueOrgDraft } from "../services/rabbitmq"; import { sendToQueueOrg, sendToQueueOrgDraft } from "../services/rabbitmq";
import { PosType } from "../entities/PosType"; import { PosType } from "../entities/PosType";
import { PosLevel } from "../entities/PosLevel"; import { PosLevel } from "../entities/PosLevel";
import { PermissionOrg } from "../entities/PermissionOrg";
@Route("api/v1/org") @Route("api/v1/org")
@Tags("Organization") @Tags("Organization")
@ -49,6 +50,7 @@ export class OrganizationController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile); private profileRepo = AppDataSource.getRepository(Profile);
private posTypeRepository = AppDataSource.getRepository(PosType); private posTypeRepository = AppDataSource.getRepository(PosType);
private posLevelRepository = AppDataSource.getRepository(PosLevel); private posLevelRepository = AppDataSource.getRepository(PosLevel);
private permissionOrgRepository = AppDataSource.getRepository(PermissionOrg);
/** /**
* API * API
@ -7869,4 +7871,48 @@ export class OrganizationController extends Controller {
posLevelNameOrder: posLevel.map((x) => x.posLevelName), posLevelNameOrder: posLevel.map((x) => x.posLevelName),
}); });
} }
/**
* API
*
* @summary - (ADMIN)
*
*/
@Get("root/add/permission/{child1Id}")
async addRootPermission(@Path() child1Id: string, @Request() request: RequestWithUser) {
const profiles = await this.profileRepo.find({
where: {
keycloak: Not(IsNull()),
current_holders: {
orgChild1Id: child1Id,
},
},
});
const orgRoots = await this.orgRootRepository.find({
where: {
orgRevision: {
orgRevisionIsDraft: true,
orgRevisionIsCurrent: false,
},
},
});
for await (const root of orgRoots) {
const _permissionOrg = profiles.map((profile) => {
const permission = new PermissionOrg();
permission.orgRootId = root.id;
permission.profileId = profile.id;
permission.createdUserId = request.user.sub;
permission.createdFullName = request.user.name;
permission.lastUpdateUserId = request.user.sub;
permission.lastUpdateFullName = request.user.name;
permission.createdAt = new Date();
permission.lastUpdatedAt = new Date();
return permission;
});
await this.permissionOrgRepository.save(_permissionOrg);
}
return new HttpSuccess();
}
} }

View file

@ -2585,6 +2585,8 @@ export class ProfileController extends Controller {
keyword: string; keyword: string;
page: number; page: number;
pageSize: number; pageSize: number;
sortBy?: string;
descending?: boolean;
}, },
) { ) {
let posMaster = await this.posMasterRepo.findOne({ let posMaster = await this.posMasterRepo.findOne({
@ -2672,7 +2674,7 @@ export class ProfileController extends Controller {
// condition.isDirector = true; // condition.isDirector = true;
// // conditionNow.isDirector = true; // // conditionNow.isDirector = true;
// } // }
const [lists, total] = await AppDataSource.getRepository(viewDirectorActing) let query = await AppDataSource.getRepository(viewDirectorActing)
.createQueryBuilder("viewDirectorActing") .createQueryBuilder("viewDirectorActing")
// .andWhere(condition) // .andWhere(condition)
.andWhere( .andWhere(
@ -2724,9 +2726,19 @@ export class ProfileController extends Controller {
); );
}), }),
) )
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize) if (body.sortBy) {
.getManyAndCount(); query = query.orderBy(
`viewDirectorActing.${body.sortBy}`,
body.descending ? "DESC" : "ASC"
);
}
const [lists, total] = await query
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
return new HttpSuccess({ data: lists, total }); return new HttpSuccess({ data: lists, total });
} else { } else {
// const posMaster = await this.posMasterRepo.findOne({ // const posMaster = await this.posMasterRepo.findOne({
@ -2764,7 +2776,7 @@ export class ProfileController extends Controller {
// condition.isDirector = true; // condition.isDirector = true;
// // conditionNow.isDirector = true; // // conditionNow.isDirector = true;
// } // }
const [lists, total] = await AppDataSource.getRepository(viewDirector) let query = await AppDataSource.getRepository(viewDirector)
.createQueryBuilder("viewDirector") .createQueryBuilder("viewDirector")
// .andWhere(condition) // .andWhere(condition)
.andWhere( .andWhere(
@ -2816,9 +2828,19 @@ export class ProfileController extends Controller {
); );
}), }),
) )
if (body.sortBy) {
query = query.orderBy(
`viewDirector.${body.sortBy}`,
body.descending ? "DESC" : "ASC"
);
}
const [lists, total] = await query
.skip((body.page - 1) * body.pageSize) .skip((body.page - 1) * body.pageSize)
.take(body.pageSize) .take(body.pageSize)
.getManyAndCount(); .getManyAndCount();
return new HttpSuccess({ data: lists, total }); return new HttpSuccess({ data: lists, total });
} }
} }
@ -8545,6 +8567,8 @@ export class ProfileController extends Controller {
keyword?: string; keyword?: string;
system?: string; system?: string;
}, },
@Query("sortBy") sortBy?: string,
@Query("descending") descending?: boolean
) { ) {
// ค้นหารายชื่อถ้าไม่ส่ง system มาให้ default ตามทะเบียนประวัติ // ค้นหารายชื่อถ้าไม่ส่ง system มาให้ default ตามทะเบียนประวัติ
let _system: string = "SYS_REGISTRY_OFFICER"; let _system: string = "SYS_REGISTRY_OFFICER";
@ -8616,7 +8640,7 @@ export class ProfileController extends Controller {
break; break;
} }
const [findProfile, total] = await this.profileRepo let query = await this.profileRepo
.createQueryBuilder("profile") .createQueryBuilder("profile")
.leftJoinAndSelect("profile.posType", "posType") .leftJoinAndSelect("profile.posType", "posType")
.leftJoinAndSelect("profile.posLevel", "posLevel") .leftJoinAndSelect("profile.posLevel", "posLevel")
@ -8672,6 +8696,27 @@ export class ProfileController extends Controller {
qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` }); qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` });
}), }),
) )
if (sortBy) {
if(sortBy === "name"){
query = query
.orderBy(`profile.prefix`,descending ? "DESC" : "ASC")
.addOrderBy(`profile.firstName`,descending ? "DESC" : "ASC")
.addOrderBy(`profile.lastName`,descending ? "DESC" : "ASC")
}else if(sortBy === "organization"){
query = query.orderBy(
`orgRoot.orgRootName`,
descending ? "DESC" : "ASC"
);
}else{
query = query.orderBy(
`profile.${sortBy}`,
descending ? "DESC" : "ASC"
);
}
}
const [findProfile, total] = await query
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();
@ -9103,6 +9148,8 @@ export class ProfileController extends Controller {
page: number; page: number;
pageSize: number; pageSize: number;
keyword?: string; keyword?: string;
sortBy?: string;
descending?: boolean;
}, },
) { ) {
let _data: any = { let _data: any = {
@ -9116,7 +9163,7 @@ export class ProfileController extends Controller {
if (!request.user.role.includes("SUPER_ADMIN")) { if (!request.user.role.includes("SUPER_ADMIN")) {
_data = await new permission().PermissionOrgCreate(request, "SYS_PROBATION"); _data = await new permission().PermissionOrgCreate(request, "SYS_PROBATION");
} }
const [findProfile, total] = await AppDataSource.getRepository(Profile) let query = await AppDataSource.getRepository(Profile)
.createQueryBuilder("profile") .createQueryBuilder("profile")
.leftJoinAndSelect("profile.profileSalary", "profileSalary") .leftJoinAndSelect("profile.profileSalary", "profileSalary")
.leftJoinAndSelect("profile.posLevel", "posLevel") .leftJoinAndSelect("profile.posLevel", "posLevel")
@ -9230,7 +9277,39 @@ export class ProfileController extends Controller {
); );
}), }),
) )
.orderBy("profile.citizenId", "ASC")
if (body.sortBy) {
if(body.sortBy === "posLevelName"){
query = query.orderBy(
`posLevel.posLevelName`,
body.descending ? "DESC" : "ASC"
);
}else if(body.sortBy === "posTypeName"){
query = query.orderBy(
`posType.posTypeName`,
body.descending ? "DESC" : "ASC"
);
}else if(body.sortBy === "commandNo"){
query = query.orderBy(
`profileSalary.commandNo`,
body.descending ? "DESC" : "ASC"
);
}else if(body.sortBy === "orgRootName"){
query = query.orderBy(
`orgRoot.orgRootName`,
body.descending ? "DESC" : "ASC"
);
}else{
query = query.orderBy(
`profile.${body.sortBy}`,
body.descending ? "DESC" : "ASC"
);
}
}else{
query = query.orderBy("profile.citizenId", "ASC")
}
const [findProfile, total] = await query
.skip((body.page - 1) * body.pageSize) .skip((body.page - 1) * body.pageSize)
.take(body.pageSize) .take(body.pageSize)
.getManyAndCount(); .getManyAndCount();

View file

@ -58,11 +58,13 @@ export class ProfileDevelopmentController extends Controller {
@Query("page") page: number = 1, @Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query() searchKeyword: string = "", @Query() searchKeyword: string = "",
@Query("sortBy") sortBy?: string,
@Query("descending") descending?: boolean,
) { ) {
let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_OFFICER"); let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_OFFICER");
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const [profileDevelopment, total] = await AppDataSource.getRepository(ProfileDevelopment) let query = await AppDataSource.getRepository(ProfileDevelopment)
.createQueryBuilder("profileDevelopment") .createQueryBuilder("profileDevelopment")
.where({ profileId: profileId }) .where({ profileId: profileId })
.andWhere( .andWhere(
@ -102,9 +104,19 @@ export class ProfileDevelopmentController extends Controller {
}), }),
) )
.orderBy("profileDevelopment.createdAt", "ASC") .orderBy("profileDevelopment.createdAt", "ASC")
if (sortBy) {
query = query.orderBy(
`profileDevelopment.${sortBy}`,
descending ? "DESC" : "ASC"
);
}
const [profileDevelopment, total] = await query
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();
return new HttpSuccess({ data: profileDevelopment, total }); return new HttpSuccess({ data: profileDevelopment, total });
} }

View file

@ -56,11 +56,14 @@ export class ProfileDevelopmentEmployeeController extends Controller {
@Query("page") page: number = 1, @Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query() searchKeyword: string = "", @Query() searchKeyword: string = "",
@Query("sortBy") sortBy?: string,
@Query("descending") descending?: boolean,
) { ) {
let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_EMP"); let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_EMP");
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId);
const [profileDevelopment, total] = await AppDataSource.getRepository(ProfileDevelopment)
let query = await AppDataSource.getRepository(ProfileDevelopment)
.createQueryBuilder("profileDevelopment") .createQueryBuilder("profileDevelopment")
.where({ profileEmployeeId: profileId }) .where({ profileEmployeeId: profileId })
.andWhere( .andWhere(
@ -100,9 +103,19 @@ export class ProfileDevelopmentEmployeeController extends Controller {
}), }),
) )
.orderBy("profileDevelopment.createdAt", "ASC") .orderBy("profileDevelopment.createdAt", "ASC")
if (sortBy) {
query = query.orderBy(
`profileDevelopment.${sortBy}`,
descending ? "DESC" : "ASC"
);
}
const [profileDevelopment, total] = await query
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();
return new HttpSuccess({ data: profileDevelopment, total }); return new HttpSuccess({ data: profileDevelopment, total });
} }

View file

@ -116,6 +116,8 @@ export class ProfileEditController extends Controller {
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword: string = "", @Query("keyword") keyword: string = "",
@Query("status") status: string = "", @Query("status") status: string = "",
@Query("sortBy") sortBy?: string,
@Query("descending") descending?: boolean,
) { ) {
let data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER"); let data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER");
const orgRevisionPublish = await this.orgRevisionRepository const orgRevisionPublish = await this.orgRevisionRepository
@ -123,7 +125,7 @@ export class ProfileEditController extends Controller {
.where("orgRevision.orgRevisionIsDraft = false") .where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true") .andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne(); .getOne();
let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit) let query = await AppDataSource.getRepository(ProfileEdit)
.createQueryBuilder("ProfileEdit") .createQueryBuilder("ProfileEdit")
.leftJoinAndSelect("ProfileEdit.profile", "profile") .leftJoinAndSelect("ProfileEdit.profile", "profile")
.leftJoinAndSelect("profile.current_holders", "current_holders") .leftJoinAndSelect("profile.current_holders", "current_holders")
@ -214,10 +216,27 @@ export class ProfileEditController extends Controller {
); );
}), }),
) )
.orderBy("ProfileEdit.createdAt", "DESC") .orderBy("ProfileEdit.createdAt", "DESC")
.skip((page - 1) * pageSize)
.take(pageSize) if (sortBy) {
.getManyAndCount(); if(sortBy == "fullname"){
query = query.orderBy(
`profile.firstName`,
descending ? "DESC" : "ASC"
);
}else{
query = query.orderBy(
`ProfileEdit.${sortBy}`,
descending ? "DESC" : "ASC"
);
}
}
const [getProfileEdit, total] = await query
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const _data = getProfileEdit.map((item) => ({ const _data = getProfileEdit.map((item) => ({
id: item.id, id: item.id,
idcard: item.profile.citizenId, idcard: item.profile.citizenId,

View file

@ -110,6 +110,8 @@ export class ProfileEditEmployeeController extends Controller {
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword: string = "", @Query("keyword") keyword: string = "",
@Query("status") status: string = "", @Query("status") status: string = "",
@Query("sortBy") sortBy?: string,
@Query("descending") descending?: boolean,
) { ) {
let data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_EMP"); let data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_EMP");
const orgRevisionPublish = await this.orgRevisionRepository const orgRevisionPublish = await this.orgRevisionRepository
@ -117,7 +119,8 @@ export class ProfileEditEmployeeController extends Controller {
.where("orgRevision.orgRevisionIsDraft = false") .where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true") .andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne(); .getOne();
let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit)
let query = await AppDataSource.getRepository(ProfileEdit)
.createQueryBuilder("ProfileEdit") .createQueryBuilder("ProfileEdit")
.leftJoinAndSelect("ProfileEdit.profileEmployee", "profileEmployee") .leftJoinAndSelect("ProfileEdit.profileEmployee", "profileEmployee")
.leftJoinAndSelect("profileEmployee.current_holders", "current_holders") .leftJoinAndSelect("profileEmployee.current_holders", "current_holders")
@ -209,9 +212,25 @@ export class ProfileEditEmployeeController extends Controller {
}), }),
) )
.orderBy("ProfileEdit.createdAt", "DESC") .orderBy("ProfileEdit.createdAt", "DESC")
.skip((page - 1) * pageSize)
.take(pageSize) if (sortBy) {
.getManyAndCount(); if(sortBy == "fullname"){
query = query.orderBy(
`profileEmployee.firstName`,
descending ? "DESC" : "ASC"
);
}else{
query = query.orderBy(
`ProfileEdit.${sortBy}`,
descending ? "DESC" : "ASC"
);
}
}
let [getProfileEdit, total] = await query
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const _data = getProfileEdit.map((item) => ({ const _data = getProfileEdit.map((item) => ({
id: item.id, id: item.id,

View file

@ -1504,6 +1504,8 @@ export class ProfileEmployeeTempController extends Controller {
@Query() isProbation?: boolean, @Query() isProbation?: boolean,
@Query() isRetire?: boolean, @Query() isRetire?: boolean,
@Query() type?: string, @Query() type?: string,
@Query("sortBy") sortBy?: string,
@Query("descending") descending?: boolean,
) { ) {
let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_TEMP"); let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_TEMP");
let queryLike = let queryLike =
@ -1525,7 +1527,8 @@ export class ProfileEmployeeTempController extends Controller {
if (!findRevision) { if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
} }
const [record, total] = await this.profileRepo
let query = await this.profileRepo
.createQueryBuilder("profileEmployee") .createQueryBuilder("profileEmployee")
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel") .leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
.leftJoinAndSelect("profileEmployee.posType", "posType") .leftJoinAndSelect("profileEmployee.posType", "posType")
@ -1638,9 +1641,36 @@ export class ProfileEmployeeTempController extends Controller {
} }
}), }),
) )
.skip((page - 1) * pageSize)
.take(pageSize) if (sortBy) {
.getManyAndCount(); if(sortBy == "posLevel"){
query = query.orderBy(
`posLevel.posLevelName`,
descending ? "DESC" : "ASC"
);
}else if(sortBy == "posType"){
query = query.orderBy(
`posType.posTypeName`,
descending ? "DESC" : "ASC"
);
}else if(sortBy == "govAge"){
query = query.orderBy(
`profileEmployee.dateAppoint`,
descending ? "DESC" : "ASC"
);
}else{
query = query.orderBy(
`profileEmployee.${sortBy}`,
descending ? "DESC" : "ASC"
);
}
}
const [record, total] = await query
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const data = await Promise.all( const data = await Promise.all(
record.map((_data) => { record.map((_data) => {
const shortName = const shortName =

View file

@ -64,6 +64,8 @@ export class ProfileSalaryTempController extends Controller {
@Query() searchKeyword: string = "", @Query() searchKeyword: string = "",
@Query() statusCheckEdit?: string | null, @Query() statusCheckEdit?: string | null,
@Query() rootId?: string, @Query() rootId?: string,
@Query("sortBy") sortBy?: string,
@Query("descending") descending?: boolean,
) { ) {
if (type.trim().toUpperCase() == "OFFICER") { if (type.trim().toUpperCase() == "OFFICER") {
let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER"); let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER");
@ -78,7 +80,7 @@ export class ProfileSalaryTempController extends Controller {
if (!findRevision) { if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
} }
const [record, total] = await this.profileRepo let query = await this.profileRepo
.createQueryBuilder("profile") .createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel") .leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType") .leftJoinAndSelect("profile.posType", "posType")
@ -321,17 +323,51 @@ export class ProfileSalaryTempController extends Controller {
rootId: rootId, rootId: rootId,
}) })
.addSelect("CASE WHEN current_holders.posMasterNo IS NULL THEN 1 ELSE 0 END", "sort_order") .addSelect("CASE WHEN current_holders.posMasterNo IS NULL THEN 1 ELSE 0 END", "sort_order")
.orderBy("sort_order", "ASC") // .orderBy(`${sortBy}`, sort)
if (sortBy) {
if(sortBy == "posLevel"){
query = query.orderBy(
`posLevel.posLevelName`,
descending ? "DESC" : "ASC"
);
}else if(sortBy == "posType"){
query = query.orderBy(
`posType.posTypeName`,
descending ? "DESC" : "ASC"
);
}else if(sortBy == "posExecutive"){
query = query.orderBy(
`posExecutive.posExecutiveName`,
descending ? "DESC" : "ASC"
);
}else if(sortBy == "posNo"){
query = query.orderBy("orgChild4.orgChild4ShortName",descending ? "DESC" : "ASC")
.addOrderBy("orgChild3.orgChild3ShortName",descending ? "DESC" : "ASC")
.addOrderBy("orgChild2.orgChild2ShortName",descending ? "DESC" : "ASC")
.addOrderBy("orgChild1.orgChild1ShortName",descending ? "DESC" : "ASC")
.addOrderBy("orgRoot.orgRootShortName",descending ? "DESC" : "ASC")
.addOrderBy("current_holders.posMasterNo",descending ? "DESC" : "ASC")
}else{
query = query.orderBy(
`profile.${sortBy}`,
descending ? "DESC" : "ASC"
);
}
}else{
query = query.orderBy("sort_order", "ASC")
.addOrderBy("orgRoot.orgRootOrder", "ASC") .addOrderBy("orgRoot.orgRootOrder", "ASC")
.addOrderBy("orgChild1.orgChild1Order", "ASC") .addOrderBy("orgChild1.orgChild1Order", "ASC")
.addOrderBy("orgChild2.orgChild2Order", "ASC") .addOrderBy("orgChild2.orgChild2Order", "ASC")
.addOrderBy("orgChild3.orgChild3Order", "ASC") .addOrderBy("orgChild3.orgChild3Order", "ASC")
.addOrderBy("orgChild4.orgChild4Order", "ASC") .addOrderBy("orgChild4.orgChild4Order", "ASC")
.addOrderBy("current_holders.posMasterNo", "ASC") .addOrderBy("current_holders.posMasterNo", "ASC")
// .orderBy(`${sortBy}`, sort) }
.skip((page - 1) * pageSize)
.take(pageSize) const [record, total] = await query
.getManyAndCount(); .skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const data = await Promise.all( const data = await Promise.all(
record.map((_data) => { record.map((_data) => {
@ -465,7 +501,7 @@ export class ProfileSalaryTempController extends Controller {
if (!findRevision) { if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
} }
const [record, total] = await this.profileEmployeeRepo let query = await this.profileEmployeeRepo
.createQueryBuilder("profileEmployee") .createQueryBuilder("profileEmployee")
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel") .leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
.leftJoinAndSelect("profileEmployee.posType", "posType") .leftJoinAndSelect("profileEmployee.posType", "posType")
@ -721,9 +757,35 @@ export class ProfileSalaryTempController extends Controller {
}) })
.orderBy("current_holders.posMasterNo", "ASC") .orderBy("current_holders.posMasterNo", "ASC")
// .orderBy(`${sortBy}`, sort) // .orderBy(`${sortBy}`, sort)
.skip((page - 1) * pageSize)
.take(pageSize) if (sortBy) {
.getManyAndCount(); if(sortBy == "posLevel"){
query = query.orderBy(
`posLevel.posLevelName`,
descending ? "DESC" : "ASC"
);
}else if(sortBy == "posType"){
query = query.orderBy(
`posType.posTypeName`,
descending ? "DESC" : "ASC"
);
}else if(sortBy == "posNo"){
query = query.orderBy(
`orgRoot.orgRootShortName`,
descending ? "DESC" : "ASC"
);
}else{
query = query.orderBy(
`profileEmployee.${sortBy}`,
descending ? "DESC" : "ASC"
);
}
}
const [record, total] = await query
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const data = await Promise.all( const data = await Promise.all(
record.map((_data) => { record.map((_data) => {
const shortName = const shortName =

View file

@ -4592,11 +4592,6 @@ export class ReportController extends Controller {
(x: any) => (x: any) =>
x.orgRevisionId == orgRevisionActive.id && x.ancestorDNA == posMaster.ancestorDNA, x.orgRevisionId == orgRevisionActive.id && x.ancestorDNA == posMaster.ancestorDNA,
); );
if (positionMasterOld && positionMasterOld.positions) {
profilePositionName = [
...new Set(positionMasterOld.positions.map((x: any) => x.positionName)),
];
}
if (positionMasterOld && positionMasterOld.positions) { if (positionMasterOld && positionMasterOld.positions) {
profilePositionName = [ profilePositionName = [
...new Set(positionMasterOld.positions.map((x: any) => x.positionName)), ...new Set(positionMasterOld.positions.map((x: any) => x.positionName)),
@ -4684,6 +4679,11 @@ export class ReportController extends Controller {
} }
} }
} }
if (positionMasterProfileOld == null && posMaster.next_holder != null
&& posMaster.next_holder.current_holders == null
) {
positionMasterProfileOld = positionMasterOld
}
let node = { let node = {
posMasterOrder: posMaster.posMasterOrder, // posMasterOrder: posMaster.posMasterOrder, //
isSit: posMaster.isSit, // isSit: posMaster.isSit, //
@ -4783,17 +4783,23 @@ export class ReportController extends Controller {
? positionMasterOld == null ? positionMasterOld == null
? posType.join(" หรือ ") ? posType.join(" หรือ ")
: profilePosType.join(" หรือ ") : profilePosType.join(" หรือ ")
: posMaster.next_holder.posType == null : positionMasterProfileOld == null
? "-" ? "-"
: posMaster.next_holder.posType.posTypeName, // : posMaster.next_holder.posType.posTypeName,
: positionMasterProfileOld.positions.find(
(x: any) => x.positionIsSelected == true,
)?.posType?.posTypeName,
profilePosLevel: profilePosLevel:
posMaster.next_holder == null posMaster.next_holder == null
? positionMasterOld == null ? positionMasterOld == null
? posLevel.join(" หรือ ") ? posLevel.join(" หรือ ")
: profilePosLevel.join(" หรือ ") : profilePosLevel.join(" หรือ ")
: posMaster.next_holder.posLevel == null : positionMasterProfileOld == null
? "-" ? "-"
: posMaster.next_holder.posLevel.posLevelName, // : posMaster.next_holder.posLevel.posLevelName,
: positionMasterProfileOld.positions.find(
(x: any) => x.positionIsSelected == true,
)?.posLevel?.posLevelName,
profilePosExecutive: profilePosExecutive:
posMaster.next_holder == null posMaster.next_holder == null
? positionMasterOld == null ? positionMasterOld == null
@ -4811,12 +4817,18 @@ export class ReportController extends Controller {
if (_node == null) { if (_node == null) {
const head = { const head = {
posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()),
profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), profileFullname:
posMaster.next_holder == null
? Extension.ToThaiNumber(node.profileOrgName.toString())
: Extension.ToThaiNumber(node.orgTreeName.toString()),
posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()),
positionName: "", positionName: "",
posType: "", posType: "",
posLevel: "", posLevel: "",
profilePosMasterNo: Extension.ToThaiNumber(node.profileOrgShortName.toString()), profilePosMasterNo:
posMaster.next_holder == null
? Extension.ToThaiNumber(node.profileOrgShortName.toString())
: Extension.ToThaiNumber(node.orgTreeShortName.toString()),
profilePosExecutive: "", profilePosExecutive: "",
profilePositionName: "", profilePositionName: "",
profilePosType: "", profilePosType: "",
@ -5087,7 +5099,11 @@ export class ReportController extends Controller {
} }
} }
} }
if (positionMasterProfileOld == null && posMaster.next_holder != null
&& posMaster.next_holder.current_holders == null
) {
positionMasterProfileOld = positionMasterOld
}
let node = { let node = {
posMasterOrder: posMaster.posMasterOrder, // posMasterOrder: posMaster.posMasterOrder, //
isSit: posMaster.isSit, // isSit: posMaster.isSit, //
@ -5188,17 +5204,23 @@ export class ReportController extends Controller {
? positionMasterOld == null ? positionMasterOld == null
? posType.join(" หรือ ") ? posType.join(" หรือ ")
: profilePosType.join(" หรือ ") : profilePosType.join(" หรือ ")
: posMaster.next_holder.posType == null : positionMasterProfileOld == null
? "-" ? "-"
: posMaster.next_holder.posType.posTypeName, // : posMaster.next_holder.posType.posTypeName,
: positionMasterProfileOld.positions.find(
(x: any) => x.positionIsSelected == true,
)?.posType?.posTypeName,
profilePosLevel: profilePosLevel:
posMaster.next_holder == null posMaster.next_holder == null
? positionMasterOld == null ? positionMasterOld == null
? posLevel.join(" หรือ ") ? posLevel.join(" หรือ ")
: profilePosLevel.join(" หรือ ") : profilePosLevel.join(" หรือ ")
: posMaster.next_holder.posLevel == null : positionMasterProfileOld == null
? "-" ? "-"
: posMaster.next_holder.posLevel.posLevelName, // : posMaster.next_holder.posLevel.posLevelName,
: positionMasterProfileOld.positions.find(
(x: any) => x.positionIsSelected == true,
)?.posLevel?.posLevelName,
profilePosExecutive: profilePosExecutive:
posMaster.next_holder == null posMaster.next_holder == null
? positionMasterOld == null ? positionMasterOld == null
@ -5216,12 +5238,18 @@ export class ReportController extends Controller {
if (_node == null) { if (_node == null) {
const head = { const head = {
posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()),
profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), profileFullname:
posMaster.next_holder == null
? Extension.ToThaiNumber(node.profileOrgName.toString())
: Extension.ToThaiNumber(node.orgTreeName.toString()),
posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()),
positionName: "", positionName: "",
posType: "", posType: "",
posLevel: "", posLevel: "",
profilePosMasterNo: Extension.ToThaiNumber(node.profileOrgShortName.toString()), profilePosMasterNo:
posMaster.next_holder == null
? Extension.ToThaiNumber(node.profileOrgShortName.toString())
: Extension.ToThaiNumber(node.orgTreeShortName.toString()),
profilePosExecutive: "", profilePosExecutive: "",
profilePositionName: "", profilePositionName: "",
profilePosType: "", profilePosType: "",
@ -5499,7 +5527,11 @@ export class ReportController extends Controller {
} }
} }
} }
if (positionMasterProfileOld == null && posMaster.next_holder != null
&& posMaster.next_holder.current_holders == null
) {
positionMasterProfileOld = positionMasterOld
}
let node = { let node = {
posMasterOrder: posMaster.posMasterOrder, // posMasterOrder: posMaster.posMasterOrder, //
isSit: posMaster.isSit, // isSit: posMaster.isSit, //
@ -5600,17 +5632,23 @@ export class ReportController extends Controller {
? positionMasterOld == null ? positionMasterOld == null
? posType.join(" หรือ ") ? posType.join(" หรือ ")
: profilePosType.join(" หรือ ") : profilePosType.join(" หรือ ")
: posMaster.next_holder.posType == null : positionMasterProfileOld == null
? "-" ? "-"
: posMaster.next_holder.posType.posTypeName, // : posMaster.next_holder.posType.posTypeName,
: positionMasterProfileOld.positions.find(
(x: any) => x.positionIsSelected == true,
)?.posType?.posTypeName,
profilePosLevel: profilePosLevel:
posMaster.next_holder == null posMaster.next_holder == null
? positionMasterOld == null ? positionMasterOld == null
? posLevel.join(" หรือ ") ? posLevel.join(" หรือ ")
: profilePosLevel.join(" หรือ ") : profilePosLevel.join(" หรือ ")
: posMaster.next_holder.posLevel == null : positionMasterProfileOld == null
? "-" ? "-"
: posMaster.next_holder.posLevel.posLevelName, // : posMaster.next_holder.posLevel.posLevelName,
: positionMasterProfileOld.positions.find(
(x: any) => x.positionIsSelected == true,
)?.posLevel?.posLevelName,
profilePosExecutive: profilePosExecutive:
posMaster.next_holder == null posMaster.next_holder == null
? positionMasterOld == null ? positionMasterOld == null
@ -5628,12 +5666,18 @@ export class ReportController extends Controller {
if (_node == null) { if (_node == null) {
const head = { const head = {
posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()),
profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), profileFullname:
posMaster.next_holder == null
? Extension.ToThaiNumber(node.profileOrgName.toString())
: Extension.ToThaiNumber(node.orgTreeName.toString()),
posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()),
positionName: "", positionName: "",
posType: "", posType: "",
posLevel: "", posLevel: "",
profilePosMasterNo: Extension.ToThaiNumber(node.profileOrgShortName.toString()), profilePosMasterNo:
posMaster.next_holder == null
? Extension.ToThaiNumber(node.profileOrgShortName.toString())
: Extension.ToThaiNumber(node.orgTreeShortName.toString()),
profilePosExecutive: "", profilePosExecutive: "",
profilePositionName: "", profilePositionName: "",
profilePosType: "", profilePosType: "",
@ -5912,7 +5956,11 @@ export class ReportController extends Controller {
} }
} }
} }
if (positionMasterProfileOld == null && posMaster.next_holder != null
&& posMaster.next_holder.current_holders == null
) {
positionMasterProfileOld = positionMasterOld
}
let node = { let node = {
posMasterOrder: posMaster.posMasterOrder, // posMasterOrder: posMaster.posMasterOrder, //
isSit: posMaster.isSit, // isSit: posMaster.isSit, //
@ -6013,17 +6061,23 @@ export class ReportController extends Controller {
? positionMasterOld == null ? positionMasterOld == null
? posType.join(" หรือ ") ? posType.join(" หรือ ")
: profilePosType.join(" หรือ ") : profilePosType.join(" หรือ ")
: posMaster.next_holder.posType == null : positionMasterProfileOld == null
? "-" ? "-"
: posMaster.next_holder.posType.posTypeName, // : posMaster.next_holder.posType.posTypeName,
: positionMasterProfileOld.positions.find(
(x: any) => x.positionIsSelected == true,
)?.posType?.posTypeName,
profilePosLevel: profilePosLevel:
posMaster.next_holder == null posMaster.next_holder == null
? positionMasterOld == null ? positionMasterOld == null
? posLevel.join(" หรือ ") ? posLevel.join(" หรือ ")
: profilePosLevel.join(" หรือ ") : profilePosLevel.join(" หรือ ")
: posMaster.next_holder.posLevel == null : positionMasterProfileOld == null
? "-" ? "-"
: posMaster.next_holder.posLevel.posLevelName, // : posMaster.next_holder.posLevel.posLevelName,
: positionMasterProfileOld.positions.find(
(x: any) => x.positionIsSelected == true,
)?.posLevel?.posLevelName,
profilePosExecutive: profilePosExecutive:
posMaster.next_holder == null posMaster.next_holder == null
? positionMasterOld == null ? positionMasterOld == null
@ -6041,12 +6095,18 @@ export class ReportController extends Controller {
if (_node == null) { if (_node == null) {
const head = { const head = {
posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()),
profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), profileFullname:
posMaster.next_holder == null
? Extension.ToThaiNumber(node.profileOrgName.toString())
: Extension.ToThaiNumber(node.orgTreeName.toString()),
posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()),
positionName: "", positionName: "",
posType: "", posType: "",
posLevel: "", posLevel: "",
profilePosMasterNo: Extension.ToThaiNumber(node.profileOrgShortName.toString()), profilePosMasterNo:
posMaster.next_holder == null
? Extension.ToThaiNumber(node.profileOrgShortName.toString())
: Extension.ToThaiNumber(node.orgTreeShortName.toString()),
profilePosExecutive: "", profilePosExecutive: "",
profilePositionName: "", profilePositionName: "",
profilePosType: "", profilePosType: "",
@ -6332,7 +6392,11 @@ export class ReportController extends Controller {
} }
} }
} }
if (positionMasterProfileOld == null && posMaster.next_holder != null
&& posMaster.next_holder.current_holders == null
) {
positionMasterProfileOld = positionMasterOld
}
let node = { let node = {
posMasterOrder: posMaster.posMasterOrder, // posMasterOrder: posMaster.posMasterOrder, //
isSit: posMaster.isSit, // isSit: posMaster.isSit, //
@ -6433,17 +6497,23 @@ export class ReportController extends Controller {
? positionMasterOld == null ? positionMasterOld == null
? posType.join(" หรือ ") ? posType.join(" หรือ ")
: profilePosType.join(" หรือ ") : profilePosType.join(" หรือ ")
: posMaster.next_holder.posType == null : positionMasterProfileOld == null
? "-" ? "-"
: posMaster.next_holder.posType.posTypeName, // : posMaster.next_holder.posType.posTypeName,
: positionMasterProfileOld.positions.find(
(x: any) => x.positionIsSelected == true,
)?.posType?.posTypeName,
profilePosLevel: profilePosLevel:
posMaster.next_holder == null posMaster.next_holder == null
? positionMasterOld == null ? positionMasterOld == null
? posLevel.join(" หรือ ") ? posLevel.join(" หรือ ")
: profilePosLevel.join(" หรือ ") : profilePosLevel.join(" หรือ ")
: posMaster.next_holder.posLevel == null : positionMasterProfileOld == null
? "-" ? "-"
: posMaster.next_holder.posLevel.posLevelName, // : posMaster.next_holder.posLevel.posLevelName,
: positionMasterProfileOld.positions.find(
(x: any) => x.positionIsSelected == true,
)?.posLevel?.posLevelName,
profilePosExecutive: profilePosExecutive:
posMaster.next_holder == null posMaster.next_holder == null
? positionMasterOld == null ? positionMasterOld == null
@ -6461,12 +6531,18 @@ export class ReportController extends Controller {
if (_node == null) { if (_node == null) {
const head = { const head = {
posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()),
profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), profileFullname:
posMaster.next_holder == null
? Extension.ToThaiNumber(node.profileOrgName.toString())
: Extension.ToThaiNumber(node.orgTreeName.toString()),
posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()),
positionName: "", positionName: "",
posType: "", posType: "",
posLevel: "", posLevel: "",
profilePosMasterNo: Extension.ToThaiNumber(node.profileOrgShortName.toString()), profilePosMasterNo:
posMaster.next_holder == null
? Extension.ToThaiNumber(node.profileOrgShortName.toString())
: Extension.ToThaiNumber(node.orgTreeShortName.toString()),
profilePosExecutive: "", profilePosExecutive: "",
profilePositionName: "", profilePositionName: "",
profilePosType: "", profilePosType: "",

View file

@ -852,10 +852,15 @@ export class KeycloakController extends Controller {
// _item.birthDate.toISOString().slice(5, 7) + // _item.birthDate.toISOString().slice(5, 7) +
// gregorianYear; // gregorianYear;
// password = formattedDate; // password = formattedDate;
const _date = new Date(_item.birthDate.toDateString()).getDate().toString().padStart(2, "0"); const _date = new Date(_item.birthDate.toDateString())
const _month = (new Date(_item.birthDate.toDateString()).getMonth()+1).toString().padStart(2, "0"); .getDate()
const _year = (new Date(_item.birthDate.toDateString()).getFullYear()+543); .toString()
password = `${_date}${_month}${_year}` .padStart(2, "0");
const _month = (new Date(_item.birthDate.toDateString()).getMonth() + 1)
.toString()
.padStart(2, "0");
const _year = new Date(_item.birthDate.toDateString()).getFullYear() + 543;
password = `${_date}${_month}${_year}`;
} }
const checkUser = await getUserByUsername(_item.citizenId); const checkUser = await getUserByUsername(_item.citizenId);
let userId: any = ""; let userId: any = "";
@ -918,10 +923,15 @@ export class KeycloakController extends Controller {
// _item.birthDate.toISOString().slice(5, 7) + // _item.birthDate.toISOString().slice(5, 7) +
// gregorianYear; // gregorianYear;
// password = formattedDate; // password = formattedDate;
const _date = new Date(_item.birthDate.toDateString()).getDate().toString().padStart(2, "0"); const _date = new Date(_item.birthDate.toDateString())
const _month = (new Date(_item.birthDate.toDateString()).getMonth()+1).toString().padStart(2, "0"); .getDate()
const _year = (new Date(_item.birthDate.toDateString()).getFullYear()+543); .toString()
password = `${_date}${_month}${_year}` .padStart(2, "0");
const _month = (new Date(_item.birthDate.toDateString()).getMonth() + 1)
.toString()
.padStart(2, "0");
const _year = new Date(_item.birthDate.toDateString()).getFullYear() + 543;
password = `${_date}${_month}${_year}`;
} }
const checkUser = await getUserByUsername(_item.citizenId); const checkUser = await getUserByUsername(_item.citizenId);
let userId: any = ""; let userId: any = "";
@ -990,4 +1000,83 @@ export class KeycloakController extends Controller {
} }
return; return;
} }
@Post("add-role-staff/user/{child1Id}")
@Security("bearerAuth", ["system", "admin"])
async addroleStaffToUser(
@Path() child1Id: string,
@Request() request: { user: { sub: string; preferred_username: string } },
) {
const profiles = await this.profileRepo.find({
where: {
keycloak: Not(IsNull()),
current_holders: {
orgChild1Id: child1Id,
},
},
relations: ["roleKeycloaks"],
});
// return profiles.length;
for await (const _item of profiles) {
let password = _item.citizenId;
if (_item.birthDate != null) {
const _date = new Date(_item.birthDate.toDateString())
.getDate()
.toString()
.padStart(2, "0");
const _month = (new Date(_item.birthDate.toDateString()).getMonth() + 1)
.toString()
.padStart(2, "0");
const _year = new Date(_item.birthDate.toDateString()).getFullYear() + 543;
password = `${_date}${_month}${_year}`;
}
const checkUser = await getUserByUsername(_item.citizenId);
let userId: any = "";
if (checkUser.length == 0) {
userId = await createUser(_item.citizenId, password, {
firstName: _item.firstName,
lastName: _item.lastName,
});
if (typeof userId !== "string") {
throw new Error(userId.errorMessage);
}
} else {
userId = checkUser[0].id;
}
const list = await getRoles();
if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server.");
const resultUser = await addUserRoles(
userId,
list.filter((v) => v.id == "8a1a0dc9-304c-4e5b-a90a-65f841048212"),
);
const resultStaff = await addUserRoles(
userId,
list.filter((v) => v.id == "f1fff8db-0795-47c1-9952-f3c18d5b6172"),
);
// if (!resultUser) {
// throw new Error("Failed. Cannot set user's role.");
// }
// if (!resultStaff) {
// throw new Error("Failed. Cannot set staff's role.");
// }
if (typeof userId === "string") {
_item.keycloak = userId;
}
const roleKeycloakUser = await this.roleKeycloakRepo.find({
where: { id: "8a1a0dc9-304c-4e5b-a90a-65f841048212" },
});
const roleKeycloakStaff = await this.roleKeycloakRepo.find({
where: { id: "f1fff8db-0795-47c1-9952-f3c18d5b6172" },
});
if (_item) {
_item.roleKeycloaks = Array.from(new Set([...roleKeycloakUser, ...roleKeycloakStaff]));
this.profileRepo.save(_item);
}
}
return "";
}
} }