no message
This commit is contained in:
parent
222a2a5b6b
commit
8acd2a97c7
4 changed files with 140 additions and 22 deletions
|
|
@ -80,7 +80,7 @@ export class PosExecutiveController extends Controller {
|
||||||
posExecutive.lastUpdateUserId = request.user.sub;
|
posExecutive.lastUpdateUserId = request.user.sub;
|
||||||
posExecutive.lastUpdateFullName = request.user.name;
|
posExecutive.lastUpdateFullName = request.user.name;
|
||||||
await this.posExecutiveRepository.save(posExecutive);
|
await this.posExecutiveRepository.save(posExecutive);
|
||||||
return new HttpSuccess();
|
return new HttpSuccess(posExecutive.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -62,10 +62,7 @@ export class PosTypeController extends Controller {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (chkPosTypeName) {
|
if (chkPosTypeName) {
|
||||||
throw new HttpError(
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทตำแหน่งนี้มีอยู่ในระบบแล้ว");
|
||||||
HttpStatusCode.NOT_FOUND,
|
|
||||||
"ชื่อประเภทตำแหน่งนี้มีอยู่ในระบบแล้ว",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
posType.createdUserId = request.user.sub;
|
posType.createdUserId = request.user.sub;
|
||||||
posType.createdFullName = request.user.name;
|
posType.createdFullName = request.user.name;
|
||||||
|
|
@ -103,10 +100,7 @@ export class PosTypeController extends Controller {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (chkPosTypeName) {
|
if (chkPosTypeName) {
|
||||||
throw new HttpError(
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทตำแหน่งนี้มีอยู่ในระบบแล้ว");
|
||||||
HttpStatusCode.NOT_FOUND,
|
|
||||||
"ชื่อประเภทตำแหน่งนี้มีอยู่ในระบบแล้ว",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
posType.lastUpdateUserId = request.user.sub;
|
posType.lastUpdateUserId = request.user.sub;
|
||||||
posType.lastUpdateFullName = request.user.name;
|
posType.lastUpdateFullName = request.user.name;
|
||||||
|
|
@ -179,12 +173,14 @@ export class PosTypeController extends Controller {
|
||||||
id: getPosType.id,
|
id: getPosType.id,
|
||||||
posTypeName: getPosType.posTypeName,
|
posTypeName: getPosType.posTypeName,
|
||||||
posTypeRank: getPosType.posTypeRank,
|
posTypeRank: getPosType.posTypeRank,
|
||||||
posLevels: getPosType.posLevels.map((posLevel) => ({
|
posLevels: getPosType.posLevels
|
||||||
id: posLevel.id,
|
.sort((a, b) => a.posLevelRank - b.posLevelRank)
|
||||||
posLevelName: posLevel.posLevelName,
|
.map((posLevel) => ({
|
||||||
posLevelRank: posLevel.posLevelRank,
|
id: posLevel.id,
|
||||||
posLevelAuthority: posLevel.posLevelAuthority,
|
posLevelName: posLevel.posLevelName,
|
||||||
})),
|
posLevelRank: posLevel.posLevelRank,
|
||||||
|
posLevelAuthority: posLevel.posLevelAuthority,
|
||||||
|
})),
|
||||||
};
|
};
|
||||||
|
|
||||||
return new HttpSuccess(mapGetPosType);
|
return new HttpSuccess(mapGetPosType);
|
||||||
|
|
@ -216,6 +212,7 @@ export class PosTypeController extends Controller {
|
||||||
const posType = await this.posTypeRepository.find({
|
const posType = await this.posTypeRepository.find({
|
||||||
select: ["id", "posTypeName", "posTypeRank"],
|
select: ["id", "posTypeName", "posTypeRank"],
|
||||||
relations: ["posLevels"],
|
relations: ["posLevels"],
|
||||||
|
order: { posTypeRank: "ASC" },
|
||||||
});
|
});
|
||||||
// if (!posType) {
|
// if (!posType) {
|
||||||
// return new HttpSuccess([]);
|
// return new HttpSuccess([]);
|
||||||
|
|
@ -224,12 +221,14 @@ export class PosTypeController extends Controller {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
posTypeName: item.posTypeName,
|
posTypeName: item.posTypeName,
|
||||||
posTypeRank: item.posTypeRank,
|
posTypeRank: item.posTypeRank,
|
||||||
posLevels: item.posLevels.map((posLevel) => ({
|
posLevels: item.posLevels
|
||||||
id: posLevel.id,
|
.sort((a, b) => a.posLevelRank - b.posLevelRank)
|
||||||
posLevelName: posLevel.posLevelName,
|
.map((posLevel) => ({
|
||||||
posLevelRank: posLevel.posLevelRank,
|
id: posLevel.id,
|
||||||
posLevelAuthority: posLevel.posLevelAuthority,
|
posLevelName: posLevel.posLevelName,
|
||||||
})),
|
posLevelRank: posLevel.posLevelRank,
|
||||||
|
posLevelAuthority: posLevel.posLevelAuthority,
|
||||||
|
})),
|
||||||
}));
|
}));
|
||||||
return new HttpSuccess(mapPosType);
|
return new HttpSuccess(mapPosType);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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, UpdatePosDict } from "../entities/PosDict";
|
import { CreatePosDict, CreatePosDictExe, 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";
|
||||||
|
|
@ -136,6 +136,99 @@ export class PositionController extends Controller {
|
||||||
return new HttpSuccess(posDict.id);
|
return new HttpSuccess(posDict.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API เพิ่มตำแหน่ง
|
||||||
|
*
|
||||||
|
* @summary ORG_030 - เพิ่มตำแหน่ง (ADMIN) #33
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Post("position/executive")
|
||||||
|
@Example([
|
||||||
|
{
|
||||||
|
positionName: "นักบริหาร",
|
||||||
|
positionField: "บริหาร",
|
||||||
|
posTypeId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
||||||
|
posLevelId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
||||||
|
posExecutiveId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
||||||
|
positionExecutiveField: "นักบริหาร",
|
||||||
|
positionArea: "บริหาร",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
async createPositionNameExe(
|
||||||
|
@Body()
|
||||||
|
requestBody: CreatePosDictExe,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
const posDict = Object.assign(new PosDict(), requestBody);
|
||||||
|
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, "ไม่พบข้อมูลประเภทตำแหน่ง");
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkPosLevelId = await this.posLevelRepository.findOne({
|
||||||
|
where: { id: posDict.posLevelId },
|
||||||
|
});
|
||||||
|
if (!checkPosLevelId) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosLevelId");
|
||||||
|
}
|
||||||
|
|
||||||
|
let posExecutive: any = null;
|
||||||
|
if (requestBody.posExecutive != null && requestBody.posExecutive != "") {
|
||||||
|
const checkName = await this.posExecutiveRepository.findOne({
|
||||||
|
where: { posExecutiveName: requestBody.posExecutive },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (checkName) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
posExecutive.posExecutiveName = requestBody.posExecutive;
|
||||||
|
|
||||||
|
const checkPriority = await this.posExecutiveRepository.findOne({
|
||||||
|
order: { posExecutivePriority: "DESC" },
|
||||||
|
});
|
||||||
|
if (checkPriority == null) {
|
||||||
|
posExecutive.posExecutivePriority = 1;
|
||||||
|
} else {
|
||||||
|
posExecutive.posExecutivePriority = checkPriority.posExecutivePriority + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
posExecutive.createdUserId = request.user.sub;
|
||||||
|
posExecutive.createdFullName = request.user.name;
|
||||||
|
posExecutive.lastUpdateUserId = request.user.sub;
|
||||||
|
posExecutive.lastUpdateFullName = request.user.name;
|
||||||
|
await this.posExecutiveRepository.save(posExecutive);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rowRepeated = await this.posDictRepository.findOne({
|
||||||
|
where: {
|
||||||
|
posDictName: posDict.posDictName,
|
||||||
|
posDictField: posDict.posDictField,
|
||||||
|
posTypeId: posDict.posTypeId,
|
||||||
|
posLevelId: posDict.posLevelId,
|
||||||
|
posExecutiveId: posExecutive == null ? null : posExecutive.id,
|
||||||
|
posDictExecutiveField: posDict.posDictExecutiveField,
|
||||||
|
posDictArea: posDict.posDictArea,
|
||||||
|
isSpecial: posDict.isSpecial,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (rowRepeated) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ข้อมูล Row นี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
|
posDict.createdUserId = request.user.sub;
|
||||||
|
posDict.createdFullName = request.user.name;
|
||||||
|
posDict.lastUpdateUserId = request.user.sub;
|
||||||
|
posDict.lastUpdateFullName = request.user.name;
|
||||||
|
await this.posDictRepository.save(posDict);
|
||||||
|
return new HttpSuccess(posDict.id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API แก้ไขตำแหน่ง
|
* API แก้ไขตำแหน่ง
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,32 @@ export class CreatePosDict {
|
||||||
isSpecial: boolean;
|
isSpecial: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class CreatePosDictExe {
|
||||||
|
@Column()
|
||||||
|
posDictName: string | null;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
posDictField: string | null;
|
||||||
|
|
||||||
|
@Column("uuid")
|
||||||
|
posTypeId: string | null;
|
||||||
|
|
||||||
|
@Column("uuid")
|
||||||
|
posLevelId: string | null;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
posExecutive?: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
posDictExecutiveField: string | null;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
posDictArea: string | null;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
isSpecial: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export class UpdatePosDict {
|
export class UpdatePosDict {
|
||||||
@Column()
|
@Column()
|
||||||
posDictName: string;
|
posDictName: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue