แก้บักตำแหน่ง
This commit is contained in:
parent
ff46ce568b
commit
121c7f56e8
1 changed files with 102 additions and 102 deletions
|
|
@ -98,7 +98,7 @@ export class PositionController extends Controller {
|
|||
if (!checkPosLevelId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosLevelId");
|
||||
}
|
||||
const _null:any = null;
|
||||
const _null: any = null;
|
||||
if (posDict.posExecutiveId == "") {
|
||||
posDict.posExecutiveId = _null;
|
||||
}
|
||||
|
|
@ -139,95 +139,94 @@ export class PositionController extends Controller {
|
|||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* API แก้ไขตำแหน่ง
|
||||
*
|
||||
* @summary แก้ไขตำแหน่ง (ADMIN)
|
||||
* @summary แก้ไขตำแหน่ง (ADMIN)
|
||||
*
|
||||
*/
|
||||
@Put("position/{id}")
|
||||
@Example([
|
||||
{
|
||||
positionName: "นักบริหาร",
|
||||
positionField: "บริหาร",
|
||||
posTypeId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
||||
posLevelId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
||||
posExecutiveId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
||||
positionExecutiveField: "นักบริหาร",
|
||||
positionArea: "บริหาร",
|
||||
},
|
||||
])
|
||||
async updatePosition(
|
||||
@Path() id : string,
|
||||
@Body()
|
||||
requestBody: UpdatePosDict,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
|
||||
const posDict = await this.posDictRepository.findOne({
|
||||
where:{id:id}
|
||||
@Put("position/{id}")
|
||||
@Example([
|
||||
{
|
||||
positionName: "นักบริหาร",
|
||||
positionField: "บริหาร",
|
||||
posTypeId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
||||
posLevelId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
||||
posExecutiveId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
||||
positionExecutiveField: "นักบริหาร",
|
||||
positionArea: "บริหาร",
|
||||
},
|
||||
])
|
||||
async updatePosition(
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: UpdatePosDict,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const posDict = await this.posDictRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!posDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
const checkPosTypeId = await this.posTypeRepository.findOne({
|
||||
where: { id: requestBody.posTypeId },
|
||||
});
|
||||
if (!checkPosTypeId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosTypeId");
|
||||
}
|
||||
|
||||
const checkPosLevelId = await this.posLevelRepository.findOne({
|
||||
where: { id: requestBody.posLevelId },
|
||||
});
|
||||
if (!checkPosLevelId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosLevelId");
|
||||
}
|
||||
|
||||
const _null: any = null;
|
||||
if (requestBody.posExecutiveId == "") {
|
||||
requestBody.posExecutiveId = _null;
|
||||
}
|
||||
|
||||
if (requestBody.posExecutiveId != null) {
|
||||
const checkPosExecutiveId = await this.posExecutiveRepository.findOne({
|
||||
where: { id: requestBody.posExecutiveId },
|
||||
});
|
||||
if (!posDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
const checkPosTypeId = await this.posTypeRepository.findOne({
|
||||
where: { id: posDict.posTypeId },
|
||||
});
|
||||
if (!checkPosTypeId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosTypeId");
|
||||
}
|
||||
|
||||
const checkPosLevelId = await this.posLevelRepository.findOne({
|
||||
where: { id: posDict.posLevelId },
|
||||
});
|
||||
if (!checkPosLevelId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosLevelId");
|
||||
}
|
||||
|
||||
const _null:any = null;
|
||||
if (posDict.posExecutiveId == "") {
|
||||
posDict.posExecutiveId = _null;
|
||||
}
|
||||
|
||||
if (posDict.posExecutiveId != null) {
|
||||
const checkPosExecutiveId = await this.posExecutiveRepository.findOne({
|
||||
where: { id: posDict.posExecutiveId },
|
||||
});
|
||||
if (!checkPosExecutiveId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosExecutiveId");
|
||||
}
|
||||
}
|
||||
|
||||
const rowRepeated = await this.posDictRepository.findOne({
|
||||
where: {
|
||||
id: Not(id),
|
||||
posDictName: posDict.posDictName,
|
||||
posDictField: posDict.posDictField,
|
||||
posTypeId: posDict.posTypeId,
|
||||
posLevelId: posDict.posLevelId,
|
||||
posExecutiveId: String(posDict.posExecutiveId),
|
||||
posDictExecutiveField: posDict.posDictExecutiveField,
|
||||
posDictArea: posDict.posDictArea,
|
||||
isSpecial: posDict.isSpecial
|
||||
},
|
||||
});
|
||||
if (rowRepeated) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ข้อมูล Row นี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
try {
|
||||
posDict.lastUpdateUserId = request.user.sub;
|
||||
posDict.lastUpdateFullName = request.user.name;
|
||||
this.posDictRepository.merge(posDict, requestBody);
|
||||
await this.posDictRepository.save(posDict);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
if (!checkPosExecutiveId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosExecutiveId");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const rowRepeated = await this.posDictRepository.findOne({
|
||||
where: {
|
||||
id: Not(id),
|
||||
posDictName: requestBody.posDictName,
|
||||
posDictField: requestBody.posDictField,
|
||||
posTypeId: requestBody.posTypeId,
|
||||
posLevelId: requestBody.posLevelId,
|
||||
posExecutiveId: String(requestBody.posExecutiveId),
|
||||
posDictExecutiveField: requestBody.posDictExecutiveField,
|
||||
posDictArea: requestBody.posDictArea,
|
||||
isSpecial: requestBody.isSpecial,
|
||||
},
|
||||
});
|
||||
if (rowRepeated) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ข้อมูล Row นี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
try {
|
||||
posDict.lastUpdateUserId = request.user.sub;
|
||||
posDict.lastUpdateFullName = request.user.name;
|
||||
this.posDictRepository.merge(posDict, requestBody);
|
||||
await this.posDictRepository.save(posDict);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API ลบตำแหน่ง
|
||||
*
|
||||
|
|
@ -608,25 +607,26 @@ export class PositionController extends Controller {
|
|||
posMaster.lastUpdateUserId = request.user.sub;
|
||||
posMaster.lastUpdateFullName = request.user.name;
|
||||
await this.posMasterRepository.save(posMaster);
|
||||
|
||||
requestBody.positions.forEach(async (x: any) => {
|
||||
const position = Object.assign(new Position());
|
||||
position.positionName = x.posDictName;
|
||||
position.positionField = x.posDictField;
|
||||
position.posTypeId = x.posTypeId;
|
||||
position.posLevelId = x.posLevelId;
|
||||
position.posExecutiveId = x.posExecutiveId;
|
||||
position.positionExecutiveField = x.posDictExecutiveField;
|
||||
position.positionArea = x.posDictArea;
|
||||
position.isSpecial = x.isSpecial;
|
||||
position.positionIsSelected = false;
|
||||
position.posMasterId = posMaster.id;
|
||||
position.createdUserId = request.user.sub;
|
||||
position.createdFullName = request.user.name;
|
||||
position.lastUpdateUserId = request.user.sub;
|
||||
position.lastUpdateFullName = request.user.name;
|
||||
await this.positionRepository.save(position);
|
||||
});
|
||||
await Promise.all(
|
||||
requestBody.positions.map(async (x: any) => {
|
||||
const position = Object.assign(new Position());
|
||||
position.positionName = x.posDictName;
|
||||
position.positionField = x.posDictField;
|
||||
position.posTypeId = x.posTypeId;
|
||||
position.posLevelId = x.posLevelId;
|
||||
position.posExecutiveId = x.posExecutiveId;
|
||||
position.positionExecutiveField = x.posDictExecutiveField;
|
||||
position.positionArea = x.posDictArea;
|
||||
position.isSpecial = x.isSpecial;
|
||||
position.positionIsSelected = false;
|
||||
position.posMasterId = posMaster.id;
|
||||
position.createdUserId = request.user.sub;
|
||||
position.createdFullName = request.user.name;
|
||||
position.lastUpdateUserId = request.user.sub;
|
||||
position.lastUpdateFullName = request.user.name;
|
||||
await this.positionRepository.save(position);
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess(posMaster.id);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue