no message

This commit is contained in:
Kittapath 2024-03-18 11:11:14 +07:00
parent 222a2a5b6b
commit 8acd2a97c7
4 changed files with 140 additions and 22 deletions

View file

@ -80,7 +80,7 @@ export class PosExecutiveController extends Controller {
posExecutive.lastUpdateUserId = request.user.sub;
posExecutive.lastUpdateFullName = request.user.name;
await this.posExecutiveRepository.save(posExecutive);
return new HttpSuccess();
return new HttpSuccess(posExecutive.id);
}
/**

View file

@ -62,10 +62,7 @@ export class PosTypeController extends Controller {
},
});
if (chkPosTypeName) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ชื่อประเภทตำแหน่งนี้มีอยู่ในระบบแล้ว",
);
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทตำแหน่งนี้มีอยู่ในระบบแล้ว");
}
posType.createdUserId = request.user.sub;
posType.createdFullName = request.user.name;
@ -103,10 +100,7 @@ export class PosTypeController extends Controller {
},
});
if (chkPosTypeName) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ชื่อประเภทตำแหน่งนี้มีอยู่ในระบบแล้ว",
);
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทตำแหน่งนี้มีอยู่ในระบบแล้ว");
}
posType.lastUpdateUserId = request.user.sub;
posType.lastUpdateFullName = request.user.name;
@ -179,12 +173,14 @@ export class PosTypeController extends Controller {
id: getPosType.id,
posTypeName: getPosType.posTypeName,
posTypeRank: getPosType.posTypeRank,
posLevels: getPosType.posLevels.map((posLevel) => ({
id: posLevel.id,
posLevelName: posLevel.posLevelName,
posLevelRank: posLevel.posLevelRank,
posLevelAuthority: posLevel.posLevelAuthority,
})),
posLevels: getPosType.posLevels
.sort((a, b) => a.posLevelRank - b.posLevelRank)
.map((posLevel) => ({
id: posLevel.id,
posLevelName: posLevel.posLevelName,
posLevelRank: posLevel.posLevelRank,
posLevelAuthority: posLevel.posLevelAuthority,
})),
};
return new HttpSuccess(mapGetPosType);
@ -216,6 +212,7 @@ export class PosTypeController extends Controller {
const posType = await this.posTypeRepository.find({
select: ["id", "posTypeName", "posTypeRank"],
relations: ["posLevels"],
order: { posTypeRank: "ASC" },
});
// if (!posType) {
// return new HttpSuccess([]);
@ -224,12 +221,14 @@ export class PosTypeController extends Controller {
id: item.id,
posTypeName: item.posTypeName,
posTypeRank: item.posTypeRank,
posLevels: item.posLevels.map((posLevel) => ({
id: posLevel.id,
posLevelName: posLevel.posLevelName,
posLevelRank: posLevel.posLevelRank,
posLevelAuthority: posLevel.posLevelAuthority,
})),
posLevels: item.posLevels
.sort((a, b) => a.posLevelRank - b.posLevelRank)
.map((posLevel) => ({
id: posLevel.id,
posLevelName: posLevel.posLevelName,
posLevelRank: posLevel.posLevelRank,
posLevelAuthority: posLevel.posLevelAuthority,
})),
}));
return new HttpSuccess(mapPosType);
}

View file

@ -22,7 +22,7 @@ import HttpStatusCode from "../interfaces/http-status";
import { PosExecutive } from "../entities/PosExecutive";
import { PosType } from "../entities/PosType";
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 { Equal, ILike, In, IsNull, Like, Not, Brackets } from "typeorm";
import { CreatePosMaster, PosMaster } from "../entities/PosMaster";
@ -136,6 +136,99 @@ export class PositionController extends Controller {
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
*

View file

@ -103,6 +103,32 @@ export class CreatePosDict {
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 {
@Column()
posDictName: string;