fix bug ผู้ดำเนินการแสดงซ้ำ #2355
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m17s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m17s
This commit is contained in:
parent
41f3c5ca54
commit
5d68a245a8
1 changed files with 70 additions and 65 deletions
|
|
@ -2621,74 +2621,79 @@ export class CommandController extends Controller {
|
|||
await this.commandRepository.save(command);
|
||||
}
|
||||
// insert commandOperator
|
||||
if (request.user.sub) {
|
||||
const profile = await this.profileRepository.findOne({
|
||||
where: { keycloak: request.user.sub },
|
||||
relations: {
|
||||
posLevel: true,
|
||||
posType: true,
|
||||
current_holders: {
|
||||
orgRevision: true,
|
||||
orgRoot: true,
|
||||
orgChild1: true,
|
||||
orgChild2: true,
|
||||
orgChild3: true,
|
||||
orgChild4: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
if (profile) {
|
||||
const currentHolder = profile!.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
);
|
||||
|
||||
const posNo =
|
||||
currentHolder != null && currentHolder.orgChild4 != null
|
||||
? `${currentHolder.orgChild4.orgChild4ShortName} ${currentHolder.posMasterNo}`
|
||||
: currentHolder != null && currentHolder.orgChild3 != null
|
||||
? `${currentHolder.orgChild3.orgChild3ShortName} ${currentHolder.posMasterNo}`
|
||||
: currentHolder != null && currentHolder.orgChild2 != null
|
||||
? `${currentHolder.orgChild2.orgChild2ShortName} ${currentHolder.posMasterNo}`
|
||||
: currentHolder != null && currentHolder.orgChild1 != null
|
||||
? `${currentHolder.orgChild1.orgChild1ShortName} ${currentHolder.posMasterNo}`
|
||||
: currentHolder != null && currentHolder?.orgRoot != null
|
||||
? `${currentHolder.orgRoot.orgRootShortName} ${currentHolder.posMasterNo}`
|
||||
: null;
|
||||
|
||||
const position = await this.positionRepository.findOne({
|
||||
where: {
|
||||
positionIsSelected: true,
|
||||
posMaster: {
|
||||
orgRevisionId: currentHolder?.orgRevisionId,
|
||||
current_holderId: profile!.id,
|
||||
const checkCommandOperator = await this.commandOperatorRepository.findOne({
|
||||
where: { commandId: command.id, roleName: "เจ้าหน้าที่ดำเนินการ" },
|
||||
});
|
||||
if (!checkCommandOperator) {
|
||||
if (request.user.sub) {
|
||||
const profile = await this.profileRepository.findOne({
|
||||
where: { keycloak: request.user.sub },
|
||||
relations: {
|
||||
posLevel: true,
|
||||
posType: true,
|
||||
current_holders: {
|
||||
orgRevision: true,
|
||||
orgRoot: true,
|
||||
orgChild1: true,
|
||||
orgChild2: true,
|
||||
orgChild3: true,
|
||||
orgChild4: true,
|
||||
},
|
||||
},
|
||||
order: { createdAt: "DESC" },
|
||||
relations: { posExecutive: true },
|
||||
});
|
||||
const operator = Object.assign(new CommandOperator(), {
|
||||
profileId: profile?.id,
|
||||
prefix: profile?.prefix,
|
||||
firstName: profile?.firstName,
|
||||
lastName: profile?.lastName,
|
||||
posNo: posNo,
|
||||
posType: profile?.posType?.posTypeName ?? null,
|
||||
posLevel: profile?.posLevel?.posLevelName ?? null,
|
||||
position: position?.positionName ?? null,
|
||||
positionExecutive: position?.posExecutive?.posExecutiveName ?? null,
|
||||
roleName: "เจ้าหน้าที่ดำเนินการ",
|
||||
orderNo: 1,
|
||||
commandId: command.id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
createdAt: now,
|
||||
lastUpdateUserId: request.user.sub,
|
||||
lastUpdateFullName: request.user.name,
|
||||
lastUpdatedAt: now,
|
||||
});
|
||||
await this.commandOperatorRepository.save(operator);
|
||||
if (profile) {
|
||||
const currentHolder = profile!.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
);
|
||||
|
||||
const posNo =
|
||||
currentHolder != null && currentHolder.orgChild4 != null
|
||||
? `${currentHolder.orgChild4.orgChild4ShortName} ${currentHolder.posMasterNo}`
|
||||
: currentHolder != null && currentHolder.orgChild3 != null
|
||||
? `${currentHolder.orgChild3.orgChild3ShortName} ${currentHolder.posMasterNo}`
|
||||
: currentHolder != null && currentHolder.orgChild2 != null
|
||||
? `${currentHolder.orgChild2.orgChild2ShortName} ${currentHolder.posMasterNo}`
|
||||
: currentHolder != null && currentHolder.orgChild1 != null
|
||||
? `${currentHolder.orgChild1.orgChild1ShortName} ${currentHolder.posMasterNo}`
|
||||
: currentHolder != null && currentHolder?.orgRoot != null
|
||||
? `${currentHolder.orgRoot.orgRootShortName} ${currentHolder.posMasterNo}`
|
||||
: null;
|
||||
|
||||
const position = await this.positionRepository.findOne({
|
||||
where: {
|
||||
positionIsSelected: true,
|
||||
posMaster: {
|
||||
orgRevisionId: currentHolder?.orgRevisionId,
|
||||
current_holderId: profile!.id,
|
||||
},
|
||||
},
|
||||
order: { createdAt: "DESC" },
|
||||
relations: { posExecutive: true },
|
||||
});
|
||||
const operator = Object.assign(new CommandOperator(), {
|
||||
profileId: profile?.id,
|
||||
prefix: profile?.prefix,
|
||||
firstName: profile?.firstName,
|
||||
lastName: profile?.lastName,
|
||||
posNo: posNo,
|
||||
posType: profile?.posType?.posTypeName ?? null,
|
||||
posLevel: profile?.posLevel?.posLevelName ?? null,
|
||||
position: position?.positionName ?? null,
|
||||
positionExecutive: position?.posExecutive?.posExecutiveName ?? null,
|
||||
roleName: "เจ้าหน้าที่ดำเนินการ",
|
||||
orderNo: 1,
|
||||
commandId: command.id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
createdAt: now,
|
||||
lastUpdateUserId: request.user.sub,
|
||||
lastUpdateFullName: request.user.name,
|
||||
lastUpdatedAt: now,
|
||||
});
|
||||
await this.commandOperatorRepository.save(operator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue