no message

This commit is contained in:
kittapath 2024-11-21 18:20:29 +07:00
parent 2d2f35847a
commit 5e7fa0eddf
2 changed files with 110 additions and 72 deletions

View file

@ -30,6 +30,10 @@ import permission from "../interfaces/permission";
import { PermissionOrg } from "../entities/PermissionOrg"; import { PermissionOrg } from "../entities/PermissionOrg";
import { setLogDataDiff } from "../interfaces/utils"; import { setLogDataDiff } from "../interfaces/utils";
import { sendToQueueOrg } from "../services/rabbitmq"; import { sendToQueueOrg } from "../services/rabbitmq";
import { PosMasterAssign } from "../entities/PosMasterAssign";
import { PosMasterAct } from "../entities/PosMasterAct";
import { EmployeePosition } from "../entities/EmployeePosition";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
@Route("api/v1/org") @Route("api/v1/org")
@Tags("Organization") @Tags("Organization")
@ -47,8 +51,12 @@ export class OrganizationController extends Controller {
private child3Repository = AppDataSource.getRepository(OrgChild3); private child3Repository = AppDataSource.getRepository(OrgChild3);
private child4Repository = AppDataSource.getRepository(OrgChild4); private child4Repository = AppDataSource.getRepository(OrgChild4);
private posMasterRepository = AppDataSource.getRepository(PosMaster); private posMasterRepository = AppDataSource.getRepository(PosMaster);
private posMasterActRepository = AppDataSource.getRepository(PosMasterAct);
private posMasterAssignRepository = AppDataSource.getRepository(PosMasterAssign);
private positionRepository = AppDataSource.getRepository(Position); private positionRepository = AppDataSource.getRepository(Position);
private profileRepo = AppDataSource.getRepository(Profile); private profileRepo = AppDataSource.getRepository(Profile);
private employeePosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
private employeePositionRepository = AppDataSource.getRepository(EmployeePosition);
/** /**
* API * API
@ -653,20 +661,32 @@ export class OrganizationController extends Controller {
const _orgRevisions = await this.orgRevisionRepository.find({ const _orgRevisions = await this.orgRevisionRepository.find({
where: [{ orgRevisionIsDraft: true, id: Not(revision.id) }], where: [{ orgRevisionIsDraft: true, id: Not(revision.id) }],
}); });
const _roots = await this.orgRootRepository.find({
where: [{ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }],
});
const _posMasters = await this.posMasterRepository.find({ const _posMasters = await this.posMasterRepository.find({
where: [{ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }], where: [{ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }],
}); });
const _positions = await this.positionRepository.find({ const _employeePosMasters = await this.employeePosMasterRepository.find({
where: [{ posMasterId: In(_posMasters.map((x) => x.id)) }], where: [{ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }],
});
await this.positionRepository.delete({ posMasterId: In(_posMasters.map((x) => x.id)) });
await this.employeePositionRepository.delete({
posMasterId: In(_employeePosMasters.map((x) => x.id)),
});
await this.posMasterAssignRepository.delete({ posMasterId: In(_posMasters.map((x) => x.id)) });
await this.posMasterActRepository.delete({ posMasterId: In(_posMasters.map((x) => x.id)) });
await this.posMasterActRepository.delete({
posMasterChildId: In(_posMasters.map((x) => x.id)),
}); });
await this.positionRepository.remove(_positions);
await this.posMasterRepository.remove(_posMasters); await this.posMasterRepository.remove(_posMasters);
await this.employeePosMasterRepository.remove(_employeePosMasters);
await this.child4Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }); await this.child4Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
await this.child3Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }); await this.child3Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
await this.child2Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }); await this.child2Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
await this.child1Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }); await this.child1Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
await this.permissionOrgRepository.delete({ await this.permissionOrgRepository.delete({
orgRootId: In(_posMasters.map((x) => x.orgRootId)), orgRootId: In(_roots.map((x) => x.id)),
}); });
await this.orgRootRepository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }); await this.orgRootRepository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
await this.orgRevisionRepository.remove(_orgRevisions); await this.orgRevisionRepository.remove(_orgRevisions);

View file

@ -1293,9 +1293,9 @@ export class PositionController extends Controller {
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
@Body() @Body()
body: { body: {
id: string; id: string | null;
revisionId: string; revisionId: string;
type: number; type: number | null;
isAll: boolean; isAll: boolean;
isBlank: boolean; isBlank: boolean;
page: number; page: number;
@ -1307,75 +1307,76 @@ export class PositionController extends Controller {
let checkChildConditions: any = {}; let checkChildConditions: any = {};
let keywordAsInt: any; let keywordAsInt: any;
let searchShortName = ""; let searchShortName = "";
let labelName = "";
let searchShortName0 = `CONCAT(orgRoot.orgRootShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName0 = `CONCAT(orgRoot.orgRootShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
let searchShortName1 = `CONCAT(orgChild1.orgChild1ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName1 = `CONCAT(orgChild1.orgChild1ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
let searchShortName3 = `CONCAT(orgChild3.orgChild3ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName3 = `CONCAT(orgChild3.orgChild3ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
let searchShortName4 = `CONCAT(orgChild4.orgChild4ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName4 = `CONCAT(orgChild4.orgChild4ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
if (body.type === 0) { if (body.type != null && body.id != null) {
typeCondition = { if (body.type === 0) {
orgRootId: body.id, typeCondition = {
}; orgRootId: body.id,
if (!body.isAll) {
checkChildConditions = {
orgChild1Id: IsNull(),
}; };
searchShortName = `CONCAT(orgRoot.orgRootShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; if (!body.isAll) {
} else { checkChildConditions = {
} orgChild1Id: IsNull(),
if (body.isBlank == true) { };
typeCondition.current_holderId = IsNull(); searchShortName = `CONCAT(orgRoot.orgRootShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
} } else {
} else if (body.type === 1) { }
typeCondition = { if (body.isBlank == true) {
orgChild1Id: body.id, typeCondition.current_holderId = IsNull();
}; }
if (!body.isAll) { } else if (body.type === 1) {
checkChildConditions = { typeCondition = {
orgChild2Id: IsNull(), orgChild1Id: body.id,
}; };
searchShortName = `CONCAT(orgChild1.orgChild1ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; if (!body.isAll) {
} else { checkChildConditions = {
} orgChild2Id: IsNull(),
if (body.isBlank == true) { };
typeCondition.current_holderId = IsNull(); searchShortName = `CONCAT(orgChild1.orgChild1ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
} } else {
} else if (body.type === 2) { }
typeCondition = { if (body.isBlank == true) {
orgChild2Id: body.id, typeCondition.current_holderId = IsNull();
}; }
if (!body.isAll) { } else if (body.type === 2) {
checkChildConditions = { typeCondition = {
orgChild3Id: IsNull(), orgChild2Id: body.id,
}; };
searchShortName = `CONCAT(orgChild2.orgChild2ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; if (!body.isAll) {
} else { checkChildConditions = {
} orgChild3Id: IsNull(),
if (body.isBlank == true) { };
typeCondition.current_holderId = IsNull(); searchShortName = `CONCAT(orgChild2.orgChild2ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
} } else {
} else if (body.type === 3) { }
typeCondition = { if (body.isBlank == true) {
orgChild3Id: body.id, typeCondition.current_holderId = IsNull();
}; }
if (!body.isAll) { } else if (body.type === 3) {
checkChildConditions = { typeCondition = {
orgChild4Id: IsNull(), orgChild3Id: body.id,
}; };
searchShortName = `CONCAT(orgChild3.orgChild3ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; if (!body.isAll) {
} else { checkChildConditions = {
} orgChild4Id: IsNull(),
if (body.isBlank == true) { };
typeCondition.current_holderId = IsNull(); searchShortName = `CONCAT(orgChild3.orgChild3ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
} } else {
} else if (body.type === 4) { }
typeCondition = { if (body.isBlank == true) {
orgChild4Id: body.id, typeCondition.current_holderId = IsNull();
}; }
searchShortName = `CONCAT(orgChild4.orgChild4ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; } else if (body.type === 4) {
if (body.isBlank == true) { typeCondition = {
typeCondition.current_holderId = IsNull(); orgChild4Id: body.id,
};
searchShortName = `CONCAT(orgChild4.orgChild4ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
if (body.isBlank == true) {
typeCondition.current_holderId = IsNull();
}
} }
} }
let findPosition: any; let findPosition: any;
@ -1464,11 +1465,26 @@ export class PositionController extends Controller {
.andWhere(revisionCondition); .andWhere(revisionCondition);
}), }),
) )
// .orWhere(
// new Brackets((qb) => {
// qb.andWhere(
// body.keyword != null && body.keyword != ""
// ? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'`
// : "1=1",
// {
// keyword: `%${body.keyword}%`,
// },
// )
// .andWhere(checkChildConditions)
// .andWhere(typeCondition)
// .andWhere(revisionCondition);
// }),
// )
.orWhere( .orWhere(
new Brackets((qb) => { new Brackets((qb) => {
qb.andWhere( qb.andWhere(
body.keyword != null && body.keyword != "" body.keyword != null && body.keyword != ""
? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'` ? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'`
: "1=1", : "1=1",
{ {
keyword: `%${body.keyword}%`, keyword: `%${body.keyword}%`,
@ -1483,7 +1499,7 @@ export class PositionController extends Controller {
new Brackets((qb) => { new Brackets((qb) => {
qb.andWhere( qb.andWhere(
body.keyword != null && body.keyword != "" body.keyword != null && body.keyword != ""
? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'` ? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN next_holder.citizenId ELSE current_holder.citizenId END LIKE '%${body.keyword}%'`
: "1=1", : "1=1",
{ {
keyword: `%${body.keyword}%`, keyword: `%${body.keyword}%`,
@ -1581,8 +1597,8 @@ export class PositionController extends Controller {
}, },
relations: ["posLevel", "posType", "posExecutive"], relations: ["posLevel", "posType", "posExecutive"],
order: { order: {
posType:{posTypeRank: "ASC"}, posType: { posTypeRank: "ASC" },
posLevel:{posLevelRank: "ASC"} posLevel: { posLevelRank: "ASC" },
}, },
}); });
@ -1679,6 +1695,8 @@ export class PositionController extends Controller {
profilePostype: type == null || type.posTypeName == null ? null : type.posTypeName, profilePostype: type == null || type.posTypeName == null ? null : type.posTypeName,
profilePoslevel: level == null || level.posLevelName == null ? null : level.posLevelName, profilePoslevel: level == null || level.posLevelName == null ? null : level.posLevelName,
authRoleId: posMaster.authRoleId, authRoleId: posMaster.authRoleId,
profileIdNextHolder: posMaster.next_holderId,
profileIdCurrentHolder: posMaster.current_holderId,
authRoleName: authRoleName:
authRoleName == null || authRoleName.roleName == null ? null : authRoleName.roleName, authRoleName == null || authRoleName.roleName == null ? null : authRoleName.roleName,
isPosMasterAssign: posMaster.posMasterAssigns.length > 0 ? true : false, isPosMasterAssign: posMaster.posMasterAssigns.length > 0 ? true : false,
@ -2008,8 +2026,8 @@ export class PositionController extends Controller {
}, },
relations: ["posLevel", "posType", "posExecutive"], relations: ["posLevel", "posType", "posExecutive"],
order: { order: {
posType:{posTypeRank: "ASC"}, posType: { posTypeRank: "ASC" },
posLevel:{posLevelRank: "ASC"} posLevel: { posLevelRank: "ASC" },
}, },
}); });