Fix ออกคำสั่งแต่รูปภาพไม่เพิ่ม + เพิ่มสิทธิ์แสดงรายชื่อลูกจ้างประจำตามสิทธิ์เจ้่าหน้าที่
This commit is contained in:
parent
9cda6e176e
commit
23aeb8864a
3 changed files with 147 additions and 15 deletions
|
|
@ -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(() => {});
|
||||
}
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -190,10 +190,103 @@ export class OrganizationDotnetController extends Controller {
|
|||
citizenId?: string | null;
|
||||
firstName?: string | null;
|
||||
lastName?: string | null;
|
||||
role?: string | null;
|
||||
nodeId?: string | null;
|
||||
node?: number | null;
|
||||
},
|
||||
) {
|
||||
const profileRepository = AppDataSource.getRepository(ProfileEmployee);
|
||||
const queryBuilder = profileRepository
|
||||
// const profileRepository = AppDataSource.getRepository(ProfileEmployee);
|
||||
// const queryBuilder = profileRepository
|
||||
// .createQueryBuilder("profile")
|
||||
// .leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||
// .leftJoinAndSelect("profile.posType", "posType")
|
||||
// .leftJoinAndSelect("profile.profileSalary", "profileSalary")
|
||||
// .leftJoinAndSelect("profile.current_holders", "current_holders")
|
||||
// .leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
|
||||
// .leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
|
||||
// .leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
|
||||
// .leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
||||
// .leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
||||
// .orderBy("profileSalary.order", "DESC");
|
||||
|
||||
// if (body.citizenId || body.firstName || body.lastName) {
|
||||
// queryBuilder.where(
|
||||
// new Brackets((qb) => {
|
||||
// if (body.citizenId) {
|
||||
// qb.orWhere("profile.citizenId LIKE :citizenId", { citizenId: `%${body.citizenId}%` });
|
||||
// }
|
||||
// if (body.firstName) {
|
||||
// qb.orWhere("profile.firstName LIKE :firstName", { firstName: `%${body.firstName}%` });
|
||||
// }
|
||||
// if (body.lastName) {
|
||||
// qb.orWhere("profile.lastName LIKE :lastName", { lastName: `%${body.lastName}%` });
|
||||
// }
|
||||
// }),
|
||||
// );
|
||||
// }
|
||||
|
||||
// const profileEmp = await queryBuilder.getMany();
|
||||
|
||||
let condition = "1=1";
|
||||
let conditionParams = {};
|
||||
if (body.role === "CHILD") {
|
||||
switch (body.node) {
|
||||
case 0:
|
||||
condition = "orgRoot.ancestorDNA = :nodeId";
|
||||
break;
|
||||
case 1:
|
||||
condition = "orgChild1.ancestorDNA = :nodeId";
|
||||
break;
|
||||
case 2:
|
||||
condition = "orgChild2.ancestorDNA = :nodeId";
|
||||
break;
|
||||
case 3:
|
||||
condition = "orgChild3.ancestorDNA = :nodeId";
|
||||
break;
|
||||
case 4:
|
||||
condition = "orgChild4.ancestorDNA = :nodeId";
|
||||
break;
|
||||
default:
|
||||
condition = "1=1";
|
||||
break;
|
||||
}
|
||||
conditionParams = { nodeId: body.nodeId };
|
||||
}
|
||||
else if (body.role === "ROOT") {
|
||||
condition = "orgRoot.ancestorDNA = :nodeId";
|
||||
conditionParams = { nodeId: body.nodeId };
|
||||
}
|
||||
else if (body.role === "NORMAL") {
|
||||
switch (body.node) {
|
||||
case 0:
|
||||
condition = "orgRoot.ancestorDNA = :nodeId AND current_holders.orgChild1 IS NULL";
|
||||
break;
|
||||
case 1:
|
||||
condition = "orgChild1.ancestorDNA = :nodeId AND current_holders.orgChild2 IS NULL";
|
||||
break;
|
||||
case 2:
|
||||
condition = "orgChild2.ancestorDNA = :nodeId AND current_holders.orgChild3 IS NULL";
|
||||
break;
|
||||
case 3:
|
||||
condition = "orgChild3.ancestorDNA = :nodeId AND current_holders.orgChild4 IS NULL";
|
||||
break;
|
||||
case 4:
|
||||
condition = "orgChild4.ancestorDNA = :nodeId";
|
||||
break;
|
||||
default:
|
||||
condition = "1=1";
|
||||
break;
|
||||
}
|
||||
conditionParams = { nodeId: body.nodeId };
|
||||
}
|
||||
|
||||
const findRevision = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true },
|
||||
});
|
||||
if (!findRevision) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
|
||||
}
|
||||
const profileEmp = await this.profileEmpRepo
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("profile.posType", "posType")
|
||||
|
|
@ -204,10 +297,8 @@ export class OrganizationDotnetController extends Controller {
|
|||
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
|
||||
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
||||
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
||||
.orderBy("profileSalary.order", "DESC");
|
||||
|
||||
if (body.citizenId || body.firstName || body.lastName) {
|
||||
queryBuilder.where(
|
||||
.where("current_holders.orgRevisionId = :orgRevisionId", { orgRevisionId: findRevision.id })
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
if (body.citizenId) {
|
||||
qb.orWhere("profile.citizenId LIKE :citizenId", { citizenId: `%${body.citizenId}%` });
|
||||
|
|
@ -219,14 +310,10 @@ export class OrganizationDotnetController extends Controller {
|
|||
qb.orWhere("profile.lastName LIKE :lastName", { lastName: `%${body.lastName}%` });
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const profileEmp = await queryBuilder.getMany();
|
||||
|
||||
const findRevision = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true },
|
||||
});
|
||||
)
|
||||
.andWhere(condition, conditionParams)
|
||||
.orderBy("profileSalary.order", "DESC")
|
||||
.getMany()
|
||||
|
||||
const profileEmp_ = await Promise.all(
|
||||
profileEmp.map((item: ProfileEmployee) => {
|
||||
|
|
|
|||
|
|
@ -857,6 +857,7 @@ export class CreateProfileAllFields {
|
|||
currentZipCode: string | null;
|
||||
amount?: Double | null;
|
||||
amountSpecial?: Double | null;
|
||||
objectRefId?: string | null;
|
||||
}
|
||||
|
||||
export type UpdateProfile = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue