no message

This commit is contained in:
Kittapath 2024-03-14 21:53:19 +07:00
parent 966d565ac6
commit 19e23bd8b1
2 changed files with 38 additions and 24 deletions

View file

@ -995,7 +995,7 @@ export class EmployeePositionController extends Controller {
where: { where: {
posMasterId: posMaster.id, posMasterId: posMaster.id,
}, },
relations: ["posLevel", "posType", "posExecutive"], relations: ["posLevel", "posType"],
}); });
let profile: any; let profile: any;

View file

@ -21,8 +21,8 @@ import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status"; import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { Equal, ILike, In, IsNull, Like, Not, Brackets, Between } from "typeorm"; import { Equal, ILike, In, IsNull, Like, Not, Brackets, Between } from "typeorm";
import { InsigniaType, CreateInsigniaType, UpdateInsigniaType } from "../entities/InsigniaType"; import { InsigniaType, CreateInsigniaType, UpdateInsigniaType } from "../entities/InsigniaType";
import { Insignia, CreateInsignias, UpdateInsignias } from "../entities/Insignia"; import { Insignia, CreateInsignias, UpdateInsignias } from "../entities/Insignia";
@Route("api/v1/org/insignia/insignia") @Route("api/v1/org/insignia/insignia")
@Tags("Insignia") @Tags("Insignia")
@ -33,10 +33,9 @@ import { Insignia, CreateInsignias, UpdateInsignias } from "../entities/Insigni
) )
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ") @SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class InsigniaController extends Controller { export class InsigniaController extends Controller {
private insigniaTypeRepository = AppDataSource.getRepository(InsigniaType); private insigniaTypeRepository = AppDataSource.getRepository(InsigniaType);
private insigniaRepository = AppDataSource.getRepository(Insignia); private insigniaRepository = AppDataSource.getRepository(Insignia);
/** /**
* API * API
* *
@ -48,13 +47,12 @@ export class InsigniaController extends Controller {
@Body() requestBody: CreateInsignias, @Body() requestBody: CreateInsignias,
@Request() request: { user: Record<string, any> }, @Request() request: { user: Record<string, any> },
) { ) {
const insignia = Object.assign(new Insignia(), requestBody); const insignia = Object.assign(new Insignia(), requestBody);
if (!insignia) { if (!insignia) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
} }
const insigniaType = await this.insigniaTypeRepository.findOne({ const insigniaType = await this.insigniaTypeRepository.findOne({
where: { id: requestBody.insigniaTypeId}, where: { id: requestBody.insigniaTypeId },
}); });
if (!insigniaType) { if (!insigniaType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลลำดับชั้นเครื่องราชอิสริยาภรณ์นี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลลำดับชั้นเครื่องราชอิสริยาภรณ์นี้");
@ -97,7 +95,7 @@ export class InsigniaController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชอิสริยาภรณ์นี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชอิสริยาภรณ์นี้");
} }
const insigniaType = await this.insigniaTypeRepository.findOne({ const insigniaType = await this.insigniaTypeRepository.findOne({
where: { id: requestBody.insigniaTypeId}, where: { id: requestBody.insigniaTypeId },
}); });
if (!insigniaType) { if (!insigniaType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลลำดับชั้นเครื่องราชอิสริยาภรณ์นี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลลำดับชั้นเครื่องราชอิสริยาภรณ์นี้");
@ -142,13 +140,22 @@ export class InsigniaController extends Controller {
* *
* @summary ORG_037 - (ADMIN) # * @summary ORG_037 - (ADMIN) #
* *
* @param {string} id Id * @param {string} id Id
*/ */
@Get("{id}") @Get("{id}")
async GetInsigniaById(@Path() id: string) { async GetInsigniaById(@Path() id: string) {
const insignia = await this.insigniaRepository.findOne({ const insignia = await this.insigniaRepository.findOne({
relations: ["insigniaType"], relations: ["insigniaType"],
select: ["id", "name", "shortName", "createdAt", "lastUpdatedAt", "lastUpdateFullName", "isActive", "note"], select: [
"id",
"name",
"shortName",
"createdAt",
"lastUpdatedAt",
"lastUpdateFullName",
"isActive",
"note",
],
where: { id: id }, where: { id: id },
}); });
if (!insignia) { if (!insignia) {
@ -160,11 +167,11 @@ export class InsigniaController extends Controller {
shortName: insignia.shortName, shortName: insignia.shortName,
insigniaTypeName: insignia.insigniaType == null ? null : insignia.insigniaType.name, //ลำดับชั้นเครื่องราช insigniaTypeName: insignia.insigniaType == null ? null : insignia.insigniaType.name, //ลำดับชั้นเครื่องราช
createdAt: insignia.createdAt, createdAt: insignia.createdAt,
lastUpdatedAt: insignia.lastUpdatedAt, lastUpdatedAt: insignia.lastUpdatedAt,
lastUpdateFullName: insignia.lastUpdateFullName, lastUpdateFullName: insignia.lastUpdateFullName,
isActive: insignia.isActive, isActive: insignia.isActive,
note: insignia.note note: insignia.note,
} };
return new HttpSuccess(mapInsignia); return new HttpSuccess(mapInsignia);
} }
@ -174,13 +181,21 @@ export class InsigniaController extends Controller {
* @summary ORG_ - (ADMIN) # * @summary ORG_ - (ADMIN) #
* *
*/ */
@Get("") @Get()
async GetInsignia() { async GetInsignia() {
const insigniaAll = await this.insigniaRepository.find({ const insigniaAll = await this.insigniaRepository.find({
relations: ["insigniaType"], relations: ["insigniaType"],
select: ["id", "name", "shortName", "createdAt", "lastUpdatedAt", "lastUpdateFullName", "isActive", "note"], select: [
order: { "level": "ASC" } "id",
"name",
"shortName",
"createdAt",
"lastUpdatedAt",
"lastUpdateFullName",
"isActive",
"note",
],
order: { level: "ASC" },
}); });
const mapInsigniaAll = insigniaAll.map((item) => ({ const mapInsigniaAll = insigniaAll.map((item) => ({
@ -189,10 +204,10 @@ export class InsigniaController extends Controller {
shortName: item.shortName, shortName: item.shortName,
insigniaTypeName: item.insigniaType == null ? null : item.insigniaType.name, //ลำดับชั้นเครื่องราช insigniaTypeName: item.insigniaType == null ? null : item.insigniaType.name, //ลำดับชั้นเครื่องราช
createdAt: item.createdAt, createdAt: item.createdAt,
lastUpdatedAt: item.lastUpdatedAt, lastUpdatedAt: item.lastUpdatedAt,
lastUpdateFullName: item.lastUpdateFullName, lastUpdateFullName: item.lastUpdateFullName,
isActive: item.isActive, isActive: item.isActive,
note: item.note note: item.note,
})); }));
return new HttpSuccess(mapInsigniaAll); return new HttpSuccess(mapInsigniaAll);
} }
@ -205,9 +220,8 @@ export class InsigniaController extends Controller {
*/ */
@Post("sort") @Post("sort")
async Sort(@Body() requestBody: { insigniaTypeId: string; sortId: string[] }) { async Sort(@Body() requestBody: { insigniaTypeId: string; sortId: string[] }) {
const insigniaType = await this.insigniaTypeRepository.findOne({ const insigniaType = await this.insigniaTypeRepository.findOne({
where: { id: requestBody.insigniaTypeId } where: { id: requestBody.insigniaTypeId },
}); });
if (!insigniaType) { if (!insigniaType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลลำดับเครื่องราชอิสริยาภรณ์นี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลลำดับเครื่องราชอิสริยาภรณ์นี้");
@ -215,7 +229,7 @@ export class InsigniaController extends Controller {
const insignia = await this.insigniaRepository.find({ const insignia = await this.insigniaRepository.find({
select: ["id", "level"], select: ["id", "level"],
where: { insigniaTypeId: requestBody.insigniaTypeId } where: { insigniaTypeId: requestBody.insigniaTypeId },
}); });
if (!insignia) { if (!insignia) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชอิสริยาภรณ์นี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชอิสริยาภรณ์นี้");