edit position
This commit is contained in:
parent
7f01e34045
commit
352ced8053
2 changed files with 98 additions and 10 deletions
|
|
@ -22,7 +22,7 @@ import HttpStatusCode from "../interfaces/http-status";
|
||||||
import { PosExecutive } from "../entities/PosExecutive";
|
import { PosExecutive } from "../entities/PosExecutive";
|
||||||
import { PosType } from "../entities/PosType";
|
import { PosType } from "../entities/PosType";
|
||||||
import { PosLevel } from "../entities/PosLevel";
|
import { PosLevel } from "../entities/PosLevel";
|
||||||
import { CreatePosDict, PosDict } from "../entities/PosDict";
|
import { CreatePosDict, PosDict, UpdatePosDict } from "../entities/PosDict";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { Equal, ILike, In, IsNull, Like, Not, Brackets } from "typeorm";
|
import { Equal, ILike, In, IsNull, Like, Not, Brackets } from "typeorm";
|
||||||
import { CreatePosMaster, PosMaster } from "../entities/PosMaster";
|
import { CreatePosMaster, PosMaster } from "../entities/PosMaster";
|
||||||
|
|
@ -98,9 +98,9 @@ export class PositionController extends Controller {
|
||||||
if (!checkPosLevelId) {
|
if (!checkPosLevelId) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosLevelId");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosLevelId");
|
||||||
}
|
}
|
||||||
|
const _null:any = null;
|
||||||
if (posDict.posExecutiveId == "") {
|
if (posDict.posExecutiveId == "") {
|
||||||
posDict.posExecutiveId = null;
|
posDict.posExecutiveId = _null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (posDict.posExecutiveId != null) {
|
if (posDict.posExecutiveId != null) {
|
||||||
|
|
@ -139,7 +139,95 @@ export class PositionController extends Controller {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API แก้ไขตำแหน่ง
|
||||||
|
*
|
||||||
|
* @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}
|
||||||
|
});
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API ลบตำแหน่ง
|
* API ลบตำแหน่ง
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ export class PosDict extends EntityBase {
|
||||||
comment: "ตำแหน่งทางการบริหาร",
|
comment: "ตำแหน่งทางการบริหาร",
|
||||||
default: null,
|
default: null,
|
||||||
})
|
})
|
||||||
posExecutiveId: string | null;
|
posExecutiveId: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
|
|
@ -84,20 +84,20 @@ export class CreatePosDict {
|
||||||
@Column()
|
@Column()
|
||||||
posDictField: string;
|
posDictField: string;
|
||||||
|
|
||||||
@Column()
|
@Column("uuid")
|
||||||
posTypeId: string;
|
posTypeId: string;
|
||||||
|
|
||||||
@Column()
|
@Column("uuid")
|
||||||
posLevelId: string;
|
posLevelId: string;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
posExecutiveId: string | null;
|
posExecutiveId: string;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
posDictExecutiveField: string | null;
|
posDictExecutiveField: string;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
posDictArea: string | null;
|
posDictArea: string;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
isSpecial: boolean;
|
isSpecial: boolean;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue