มอบหมาย

This commit is contained in:
kittapath 2024-10-07 17:00:54 +07:00
parent c43eeb9066
commit 7b5e6e5fb0
8 changed files with 279 additions and 2 deletions

View file

@ -42,6 +42,9 @@ import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
import { request } from "axios";
import { setLogDataDiff } from "../interfaces/utils";
import { PosMasterAssign } from "../entities/PosMasterAssign";
import { CommandSys } from "../entities/CommandSys";
import { Assign } from "../entities/Assign";
@Route("api/v1/org/pos")
@Tags("Position")
@Security("bearerAuth")
@ -67,6 +70,8 @@ export class PositionController extends Controller {
private child3Repository = AppDataSource.getRepository(OrgChild3);
private child4Repository = AppDataSource.getRepository(OrgChild4);
private authRoleRepo = AppDataSource.getRepository(AuthRole);
private posMasterAssignRepo = AppDataSource.getRepository(PosMasterAssign);
private assignRepo = AppDataSource.getRepository(Assign);
/**
* API
@ -150,6 +155,73 @@ export class PositionController extends Controller {
return new HttpSuccess(posDict.id);
}
/**
* API
*
* @summary
*
*/
@Post("assign")
async createPositionMasterAssgin(
@Body()
requestBody: {
assignIds: string[];
posMasterId: string;
},
@Request() request: RequestWithUser,
) {
const posMaster = await this.posMasterRepository.findOne({
where: { id: requestBody.posMasterId },
});
if (!posMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
}
await this.posMasterAssignRepo.delete({ posMasterId: posMaster.id });
const assigns = await this.assignRepo.find({
where: { id: In(requestBody.assignIds) },
});
await Promise.all(
await assigns.map(async (x) => {
let _posMasterAssign = await this.posMasterAssignRepo.findOne({
where: { posMasterId: requestBody.posMasterId, assignId: x.id },
});
if (_posMasterAssign == null) {
const posMasterAssign = new PosMasterAssign();
posMasterAssign.posMasterId = requestBody.posMasterId;
posMasterAssign.assignId = x.id;
posMasterAssign.createdUserId = request.user.sub;
posMasterAssign.createdFullName = request.user.name;
posMasterAssign.lastUpdateUserId = request.user.sub;
posMasterAssign.lastUpdateFullName = request.user.name;
posMasterAssign.createdAt = new Date();
posMasterAssign.lastUpdatedAt = new Date();
await this.posMasterAssignRepo.save(posMasterAssign);
}
}),
);
return new HttpSuccess();
}
/**
* API
*
* @summary
*
* @param {string} id Id posMaster
*/
@Delete("assign/{id}")
async deletePositionMasterAssgin(@Path() id: string, @Request() request: RequestWithUser) {
const posMaster = await this.posMasterRepository.findOne({
where: { id: id },
});
if (!posMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
}
await this.posMasterAssignRepo.delete({ posMasterId: posMaster.id });
return new HttpSuccess();
}
/**
* API
*
@ -990,7 +1062,7 @@ export class PositionController extends Controller {
posMaster.createdAt = new Date();
posMaster.lastUpdatedAt = new Date();
await this.posMasterRepository.save(posMaster, { data: request });
setLogDataDiff( request, { before, after: posMaster });
setLogDataDiff(request, { before, after: posMaster });
await this.positionRepository.delete({ posMasterId: posMaster.id });
await Promise.all(
@ -1256,6 +1328,8 @@ export class PositionController extends Controller {
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
.leftJoinAndSelect("posMaster.next_holder", "next_holder")
.leftJoinAndSelect("posMaster.orgRevision", "orgRevision")
.leftJoinAndSelect("posMaster.posMasterAssigns", "posMasterAssigns")
.leftJoinAndSelect("posMasterAssigns.assign", "assign")
.where(conditions)
.andWhere(
new Brackets((qb) => {
@ -1446,6 +1520,14 @@ export class PositionController extends Controller {
authRoleId: posMaster.authRoleId,
authRoleName:
authRoleName == null || authRoleName.roleName == null ? null : authRoleName.roleName,
isPosMasterAssign: posMaster.posMasterAssigns.length > 0 ? true : false,
posMasterAssigns: posMaster.posMasterAssigns.map((x) => ({
id: x.id,
assignId: x.assignId,
commandSysId: x.assign.commandSysId,
name: x.assign.name,
description: x.assign.description,
})),
positions: positions.map((position: any) => ({
id: position.id,
positionName: position.positionName,
@ -3000,7 +3082,7 @@ export class PositionController extends Controller {
dataMaster.isSit = requestBody.isSit;
dataMaster.next_holderId = requestBody.profileId;
await this.posMasterRepository.save(dataMaster, { data: request });
setLogDataDiff( request, { before, after: dataMaster });
setLogDataDiff(request, { before, after: dataMaster });
return new HttpSuccess();
}