Fix ออกคำสั่งแต่รูปภาพไม่เพิ่ม + เพิ่มสิทธิ์แสดงรายชื่อลูกจ้างประจำตามสิทธิ์เจ้่าหน้าที่

This commit is contained in:
Bright 2025-07-11 10:34:43 +07:00
parent 9cda6e176e
commit 23aeb8864a
3 changed files with 147 additions and 15 deletions

View file

@ -89,6 +89,7 @@ import { OrgRoot } from "../entities/OrgRoot";
import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster";
import { ProfileInsignia, CreateProfileInsignia } from "../entities/ProfileInsignia";
import { ProfileInsigniaHistory } from "../entities/ProfileInsigniaHistory";
import { ProfileAvatar } from "../entities/ProfileAvatar";
@Route("api/v1/org/command")
@Tags("Command")
@Security("bearerAuth")
@ -141,6 +142,7 @@ export class CommandController extends Controller {
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
private avatarRepository = AppDataSource.getRepository(ProfileAvatar);
/**
* API list
@ -5510,7 +5512,7 @@ export class CommandController extends Controller {
let profile: any = await this.profileRepository.findOne({
where: { citizenId: item.bodyProfile.citizenId /*, isActive: true */ },
relations: ["roleKeycloaks", "profileInsignias"],
relations: ["roleKeycloaks", "profileInsignias", "profileAvatars"],
});
let _oldInsigniaIds: string[] = [];
if (!profile) {
@ -5961,6 +5963,48 @@ export class CommandController extends Controller {
await this.insigniaHistoryRepo.save(history, { data: req });
}
}
// เพิ่มรูปภาพโปรไฟล์
if (item.bodyProfile.objectRefId) {
const _profileAvatar = new ProfileAvatar();
Object.assign(_profileAvatar, {
...meta,
profileId: profile.id,
profileEmployeeId: undefined
});
if (profile.profileAvatars && profile.profileAvatars.length > 0) {
await Promise.all(
profile.profileAvatars.map(async (item: any) => {
item.isActive = false;
await this.avatarRepository.save(item);
}),
);
}
await this.avatarRepository.save(_profileAvatar);
let avatar = `ทะเบียนประวัติ/โปรไฟล์/${profile.id}`;
let fileName = `profile-${_profileAvatar.id}`;
_profileAvatar.isActive = true;
_profileAvatar.avatar = avatar;
_profileAvatar.avatarName = fileName;
await this.avatarRepository.save(_profileAvatar, { data: req });
profile.avatar = avatar;
profile.avatarName = fileName;
await this.profileRepository.save(profile, { data: req });
const checkAvatar = await this.avatarRepository.findOne({
where: { avatar: avatar, avatarName: fileName }
})
if (checkAvatar && checkAvatar.profileId == null) {
checkAvatar.profileId = profile.id
await this.avatarRepository.save(checkAvatar);
}
//duplicate รูปภาพโปรไฟล์โดยอิงจากรูปภาพเดิม
await new CallAPI()
.PostData(req, `/salary/file/avatar/${item.bodyProfile.objectRefId}`, {
prefix: avatar,
fileName: fileName,
})
.then(() => {})
.catch(() => {});
}
}
}),
);