Merge branch 'adiDev' into develop
# Conflicts: # src/controllers/PositionController.ts
This commit is contained in:
commit
a0f8c05134
1 changed files with 174 additions and 110 deletions
|
|
@ -33,6 +33,7 @@ import { OrgChild2 } from "../entities/OrgChild2";
|
|||
import { OrgChild3 } from "../entities/OrgChild3";
|
||||
import { OrgChild4 } from "../entities/OrgChild4";
|
||||
import { Position } from "../entities/Position";
|
||||
import { Brackets } from "typeorm/browser";
|
||||
@Route("api/v1/org/pos")
|
||||
@Tags("Position")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -736,119 +737,182 @@ export class PositionController extends Controller {
|
|||
try {
|
||||
let typeCondition: any = {};
|
||||
let checkChildConditions: any = {};
|
||||
|
||||
if (body.type === 0) {
|
||||
typeCondition = {
|
||||
orgRootId: body.id,
|
||||
};
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild1Id: IsNull(),
|
||||
};
|
||||
}
|
||||
} else if (body.type === 1) {
|
||||
typeCondition = {
|
||||
orgChild1Id: body.id,
|
||||
};
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild2Id: IsNull(),
|
||||
};
|
||||
}
|
||||
} else if (body.type === 2) {
|
||||
typeCondition = {
|
||||
orgChild2Id: body.id,
|
||||
};
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild3Id: IsNull(),
|
||||
};
|
||||
}
|
||||
} else if (body.type === 3) {
|
||||
typeCondition = {
|
||||
orgChild3Id: body.id,
|
||||
};
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild4Id: IsNull(),
|
||||
};
|
||||
}
|
||||
} else if (body.type === 4) {
|
||||
typeCondition = {
|
||||
orgChild4Id: body.id,
|
||||
};
|
||||
}
|
||||
const keywordCondition = {}
|
||||
? {
|
||||
posMasterNoPrefix: Like(`%${body.keyword}%`),
|
||||
positionName: Like(`%${body.keyword}%`),
|
||||
posTypeName: Like(`%${body.keyword}%`),
|
||||
posLevelName: Like(`%${body.keyword}%`),
|
||||
}
|
||||
: {};
|
||||
|
||||
const posMaster = await this.posMasterRepository.find({
|
||||
where: {
|
||||
...typeCondition,
|
||||
...checkChildConditions,
|
||||
// ...keywordCondition,
|
||||
},
|
||||
order: { posMasterOrder: "ASC" },
|
||||
relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4"],
|
||||
skip: (body.page - 1) * body.pageSize,
|
||||
take: body.pageSize,
|
||||
});
|
||||
const total = posMaster.length;
|
||||
|
||||
// if (!posMaster || posMaster.length === 0) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
//******** ของตั้ม(เก่า) *********//
|
||||
// if (body.type === 0) {
|
||||
// typeCondition = {
|
||||
// orgRootId: body.id,
|
||||
// };
|
||||
// if (!body.isAll) {
|
||||
// checkChildConditions = {
|
||||
// orgChild1Id: IsNull(),
|
||||
// };
|
||||
// }
|
||||
// } else if (body.type === 1) {
|
||||
// typeCondition = {
|
||||
// orgChild1Id: body.id,
|
||||
// };
|
||||
// if (!body.isAll) {
|
||||
// checkChildConditions = {
|
||||
// orgChild2Id: IsNull(),
|
||||
// };
|
||||
// }
|
||||
// } else if (body.type === 2) {
|
||||
// typeCondition = {
|
||||
// orgChild2Id: body.id,
|
||||
// };
|
||||
// if (!body.isAll) {
|
||||
// checkChildConditions = {
|
||||
// orgChild3Id: IsNull(),
|
||||
// };
|
||||
// }
|
||||
// } else if (body.type === 3) {
|
||||
// typeCondition = {
|
||||
// orgChild3Id: body.id,
|
||||
// };
|
||||
// if (!body.isAll) {
|
||||
// checkChildConditions = {
|
||||
// orgChild4Id: IsNull(),
|
||||
// };
|
||||
// }
|
||||
// } else if (body.type === 4) {
|
||||
// typeCondition = {
|
||||
// orgChild4Id: body.id,
|
||||
// };
|
||||
// }
|
||||
|
||||
const formattedData = await Promise.all(
|
||||
posMaster.map(async (posMaster) => {
|
||||
const positions = await this.positionRepository.find({
|
||||
where: { posMasterId: posMaster.id },
|
||||
relations: ["posLevel", "posType", "posExecutive"],
|
||||
});
|
||||
// const keywordPosMasterCondition = body.keyword
|
||||
// ? {
|
||||
// posMasterNoPrefix: Like(`%${body.keyword}%`),
|
||||
// positionName: Like(`%${body.keyword}%`),
|
||||
// posTypeName: Like(`%${body.keyword}%`),
|
||||
// posLevelName: Like(`%${body.keyword}%`),
|
||||
// }
|
||||
// : {};
|
||||
//******** จบของตั้ม(เก่า) *********//
|
||||
|
||||
return {
|
||||
id: posMaster.id,
|
||||
posMasterNoPrefix: posMaster.posMasterNoPrefix,
|
||||
posMasterNo: posMaster.posMasterNo,
|
||||
posMasterNoSuffix: posMaster.posMasterNoSuffix,
|
||||
orgShortname:
|
||||
body.type === 0
|
||||
? posMaster.orgRoot.orgRootShortName
|
||||
: body.type === 1
|
||||
? posMaster.orgChild1.orgChild1ShortName
|
||||
: body.type === 2
|
||||
? posMaster.orgChild2.orgChild2ShortName
|
||||
: body.type === 3
|
||||
? posMaster.orgChild3.orgChild3ShortName
|
||||
: body.type === 4
|
||||
? posMaster.orgChild4.orgChild4ShortName
|
||||
: "-",
|
||||
// profileIdCurrentHolder: posMaster.profileIdCurrentHolder,
|
||||
// profileIdNextHolder: posMaster.profileIdNextHolder,
|
||||
positions: positions.map((position) => ({
|
||||
id: position.id,
|
||||
positionName: position.positionName,
|
||||
positionField: position.positionField,
|
||||
posTypeId: position.posTypeId,
|
||||
posTypeName: position.posType == null ? null : position.posType.posTypeName,
|
||||
posLevelId: position.posLevelId,
|
||||
posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName,
|
||||
posExecutiveId: position.posExecutiveId,
|
||||
posExecutiveName:
|
||||
position.posExecutive == null ? null : position.posExecutive.posExecutiveName,
|
||||
positionExecutiveField: position.positionExecutiveField,
|
||||
positionArea: position.positionArea,
|
||||
positionIsSelected: position.positionIsSelected,
|
||||
})),
|
||||
};
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess({ data: formattedData, total });
|
||||
//******** ของมอส *********//
|
||||
// return {
|
||||
// id: posMaster.id,
|
||||
// posMasterNoPrefix: posMaster.posMasterNoPrefix,
|
||||
// posMasterNo: posMaster.posMasterNo,
|
||||
// posMasterNoSuffix: posMaster.posMasterNoSuffix,
|
||||
// orgShortname:
|
||||
// body.type === 0
|
||||
// ? posMaster.orgRoot.orgRootShortName
|
||||
// : body.type === 1
|
||||
// ? posMaster.orgChild1.orgChild1ShortName
|
||||
// : body.type === 2
|
||||
// ? posMaster.orgChild2.orgChild2ShortName
|
||||
// : body.type === 3
|
||||
// ? posMaster.orgChild3.orgChild3ShortName
|
||||
// : body.type === 4
|
||||
// ? posMaster.orgChild4.orgChild4ShortName
|
||||
// : "-",
|
||||
// profileIdCurrentHolder: posMaster.profileIdCurrentHolder,
|
||||
// profileIdNextHolder: posMaster.profileIdNextHolder,
|
||||
// positions: positions.map((position) => ({
|
||||
// id: position.id,
|
||||
// positionName: position.positionName,
|
||||
// positionField: position.positionField,
|
||||
// posTypeId: position.posTypeId,
|
||||
// posTypeName: position.posType == null ? null : position.posType.posTypeName,
|
||||
// posLevelId: position.posLevelId,
|
||||
// posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName,
|
||||
// posExecutiveId: position.posExecutiveId,
|
||||
// posExecutiveName:
|
||||
// position.posExecutive == null ? null : position.posExecutive.posExecutiveName,
|
||||
// positionExecutiveField: position.positionExecutiveField,
|
||||
// positionArea: position.positionArea,
|
||||
// positionIsSelected: position.positionIsSelected,
|
||||
// })),
|
||||
// };
|
||||
// }),
|
||||
// );
|
||||
// return new HttpSuccess({ data: formattedData, total });
|
||||
//******** จบของมอส *********//
|
||||
let data = AppDataSource.getRepository(PosMaster)
|
||||
.createQueryBuilder("posMaster")
|
||||
.leftJoin("posMaster.positions", "position")
|
||||
.leftJoin("position.posType", "posType")
|
||||
.leftJoin("position.posLevel", "posLevel")
|
||||
.andWhere("posMaster.posMasterNoPrefix LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("position.positionName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("posType.posTypeName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("posLevel.posLevelName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orderBy("posMaster.posMasterOrder", "ASC")
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize);
|
||||
|
||||
if (body.type === 0) {
|
||||
data = data.andWhere("posMaster.orgRootId = :orgRootId", { orgRootId: body.id });
|
||||
if (!body.isAll) {
|
||||
data = data.andWhere("posMaster.orgChild1Id IS NULL");
|
||||
}
|
||||
} else if (body.type === 1) {
|
||||
data = data.andWhere("posMaster.orgChild1Id = :orgChild1Id", { orgChild1Id: body.id });
|
||||
if (!body.isAll) {
|
||||
data = data.andWhere("posMaster.orgChild2Id IS NULL");
|
||||
}
|
||||
} else if (body.type === 2) {
|
||||
data = data.andWhere("posMaster.orgChild2Id = :orgChild2Id", { orgChild2Id: body.id });
|
||||
if (!body.isAll) {
|
||||
data = data.andWhere("posMaster.orgChild3Id IS NULL");
|
||||
}
|
||||
} else if (body.type === 3) {
|
||||
data = data.andWhere("posMaster.orgChild3Id = :orgChild3Id", { orgChild3Id: body.id });
|
||||
if (!body.isAll) {
|
||||
data = data.andWhere("posMaster.orgChild4Id IS NULL");
|
||||
}
|
||||
} else if (body.type === 4) {
|
||||
data = data.andWhere("posMaster.orgChild4Id = :orgChild4Id", { orgChild4Id: body.id });
|
||||
}
|
||||
|
||||
const [posMaster, total] = await data.getManyAndCount();
|
||||
|
||||
// const posMaster = await this.posMasterRepository.find({
|
||||
// where: {
|
||||
// ...typeCondition,
|
||||
// ...checkChildConditions,
|
||||
// },
|
||||
// order: { posMasterOrder: "ASC" },
|
||||
// skip: (body.page - 1) * body.pageSize,
|
||||
// take: body.pageSize,
|
||||
// });
|
||||
// const total = posMaster.length;
|
||||
|
||||
const formattedData = await Promise.all(
|
||||
posMaster.map(async (posMaster) => {
|
||||
const positions = await this.positionRepository.find({
|
||||
where: {
|
||||
posMasterId: posMaster.id,
|
||||
},
|
||||
relations: ["posLevel", "posType", "posExecutive"],
|
||||
});
|
||||
|
||||
return {
|
||||
id: posMaster.id,
|
||||
posMasterNoPrefix: posMaster.posMasterNoPrefix,
|
||||
posMasterNo: posMaster.posMasterNo,
|
||||
posMasterNoSuffix: posMaster.posMasterNoSuffix,
|
||||
positions: positions.map((position) => ({
|
||||
id: position.id,
|
||||
positionName: position.positionName,
|
||||
positionField: position.positionField,
|
||||
posTypeId: position.posTypeId,
|
||||
posTypeName: position.posType == null ? null : position.posType.posTypeName,
|
||||
posLevelId: position.posLevelId,
|
||||
posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName,
|
||||
posExecutiveId: position.posExecutiveId,
|
||||
posExecutiveName:
|
||||
position.posExecutive == null ? null : position.posExecutive.posExecutiveName,
|
||||
positionExecutiveField: position.positionExecutiveField,
|
||||
positionArea: position.positionArea,
|
||||
positionIsSelected: position.positionIsSelected,
|
||||
})),
|
||||
};
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess({ data: formattedData, total });
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue