no message

This commit is contained in:
Kittapath 2024-06-25 10:21:30 +07:00
parent b11be3364f
commit 568d326797
6 changed files with 643 additions and 31 deletions

View file

@ -30,6 +30,9 @@ import { OrgChild4 } from "../entities/OrgChild4";
import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position";
import { log } from "console";
import CallAPI from "../interfaces/call-api";
import { ProfileSalary } from "../entities/ProfileSalary";
import { Profile } from "../entities/Profile";
@Route("api/v1/org")
@Tags("Organization")
@ -48,6 +51,8 @@ export class OrganizationController extends Controller {
private child4Repository = AppDataSource.getRepository(OrgChild4);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private positionRepository = AppDataSource.getRepository(Position);
private salaryRepository = AppDataSource.getRepository(ProfileSalary);
private profileRepo = AppDataSource.getRepository(Profile);
/**
* API
@ -1601,7 +1606,7 @@ export class OrganizationController extends Controller {
* @param {string} id Id revison
*/
@Get("get/publish")
async runPublish() {
async runPublish(@Request() request: { user: Record<string, any> }) {
const today = new Date();
today.setHours(0, 0, 0, 0); // Set time to the beginning of the day
const orgRevisionPublish = await this.orgRevisionRepository
@ -1631,14 +1636,73 @@ export class OrganizationController extends Controller {
const posMaster = await this.posMasterRepository.find({
where: { orgRevisionId: orgRevisionDraft.id },
relations: [
"orgRoot",
"orgChild4",
"orgChild3",
"orgChild2",
"orgChild1",
"positions",
"positions.posLevel",
"positions.posType",
"positions.posExecutive",
],
});
posMaster.forEach(async (item) => {
// if(item.next_holderId != null){
item.current_holderId = item.next_holderId;
item.next_holderId = null;
await this.posMasterRepository.save(item);
// }
});
await Promise.all(
posMaster.map(async (item) => {
// if(item.next_holderId != null){
if (item.next_holderId != null) {
const profile = await this.profileRepo.findOne({
where: { id: item.next_holderId == null ? "" : item.next_holderId },
});
const position = await item.positions.find((x) => x.positionIsSelected == true);
const _null: any = null;
if (profile != null) {
profile.posLevelId = position?.posLevelId ?? _null;
profile.posTypeId = position?.posTypeId ?? _null;
profile.position = position?.positionName ?? _null;
await this.profileRepo.save(profile);
}
const profileSalary = await this.salaryRepository.findOne({
where: { profileId: item.next_holderId },
order: { createdAt: "DESC" },
});
const shortName =
item != null && item.orgChild4 != null
? `${item.orgChild4.orgChild4ShortName}${item.posMasterNo}`
: item != null && item?.orgChild3 != null
? `${item.orgChild3.orgChild3ShortName}${item.posMasterNo}`
: item != null && item?.orgChild2 != null
? `${item.orgChild2.orgChild2ShortName}${item.posMasterNo}`
: item != null && item?.orgChild1 != null
? `${item.orgChild1.orgChild1ShortName}${item.posMasterNo}`
: item != null && item?.orgRoot != null
? `${item.orgRoot.orgRootShortName}${item.posMasterNo}`
: null;
// await new CallAPI().PostData(request, "org/profile/salary", {
// profileId: item.next_holderId,
// date: new Date(),
// amount: profileSalary?.amount ?? null,
// positionSalaryAmount: profileSalary?.positionSalaryAmount ?? null,
// mouthSalaryAmount: profileSalary?.mouthSalaryAmount ?? null,
// posNo: shortName,
// position: position?.positionName ?? _null,
// positionLine: position?.positionField ?? _null,
// positionPathSide: position?.positionArea ?? _null,
// positionExecutive: position?.posExecutive?.posExecutiveName ?? _null,
// positionType: position?.posType?.posTypeName ?? _null,
// positionLevel: position?.posLevel?.posLevelName ?? _null,
// refCommandNo: null,
// templateDoc: "ปรับโครงสร้าง",
// });
}
item.current_holderId = item.next_holderId;
item.next_holderId = null;
await this.posMasterRepository.save(item);
// }
}),
);
return new HttpSuccess();
}
@ -3363,6 +3427,15 @@ export class OrganizationController extends Controller {
*/
@Get("approver/{id}")
async getUserRootOrg(@Path() id: string, @Request() request: { user: Record<string, any> }) {
if (id == "00000000-0000-0000-0000-000000000000") {
const maps = {
id: "00000000-0000-0000-0000-000000000000",
name: "",
positionName: "ปลัดกรุงเทพมหานคร",
};
return new HttpSuccess(maps);
}
const root = await this.orgRootRepository.findOne({
where: { id: id },
});
@ -3374,9 +3447,9 @@ export class OrganizationController extends Controller {
if (!posMaster) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
const maps = posMaster.map((posMaster) => ({
Id: posMaster.current_holder.id,
Name: `${posMaster.current_holder.prefix}${posMaster.current_holder.firstName} ${posMaster.current_holder.lastName}`,
PositionName: posMaster.current_holder.position,
id: posMaster.current_holder.id,
name: `${posMaster.current_holder.prefix}${posMaster.current_holder.firstName} ${posMaster.current_holder.lastName}`,
positionName: posMaster.current_holder.position,
}));
return new HttpSuccess(maps);