Merge branch 'adiDev' into develop

This commit is contained in:
AdisakKanthawilang 2024-02-02 13:17:15 +07:00
commit ed4d07a439

View file

@ -11,13 +11,13 @@ import {
Request,
SuccessResponse,
Response,
Get,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import { PosExecutive } from "../entities/PosExecutive";
import HttpError from "../interfaces/http-error";
import { CreatePosMaster, PosMaster } from "../entities/PosMaster";
import { CreatePosExecutive, PosExecutive } from "../entities/PosExecutive";
import { Position } from "../entities/Position";
@Route("api/v1/org/pos")
@Tags("PosExecutive")
@ -40,7 +40,7 @@ export class PosExecutiveController extends Controller {
@Post("executive")
async createPosExecutive(
@Body()
requestBody: CreatePosMaster,
requestBody: CreatePosExecutive,
@Request() request: { user: Record<string, any> },
) {
const posExecutive = Object.assign(new PosExecutive(), requestBody);
@ -70,16 +70,17 @@ export class PosExecutiveController extends Controller {
async updatePosExecutive(
@Path() id: string,
@Body()
requestBody: CreatePosMaster,
requestBody: CreatePosExecutive,
@Request() request: { user: Record<string, any> },
) {
const posExecutive = Object.assign(new PosExecutive(), requestBody);
const posExecutive = await this.posExecutiveRepository.findOne({where: {id: id}});
if (!posExecutive) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
try {
posExecutive.lastUpdateUserId = request.user.sub;
posExecutive.lastUpdateFullName = request.user.name;
this.posExecutiveRepository.merge(posExecutive, requestBody);
await this.posExecutiveRepository.save(posExecutive);
return new HttpSuccess();
} catch (error) {
@ -92,7 +93,7 @@ export class PosExecutiveController extends Controller {
*
* @summary ORG_043 - (ADMIN) #46
*
* @param {string} id Id
* @param {string} id Id
*/
@Delete("executive/{id}")
async deletePosExecutive(@Path() id: string) {
@ -110,4 +111,32 @@ export class PosExecutiveController extends Controller {
return error;
}
}
/**
* API
*
* @summary ORG_044 - (ADMIN) #47
*
* @param {string} id Id
*/
@Get("executive/{id}")
async detailPosExecutive(@Path() id: string) {
const posExecutive = await this.posExecutiveRepository.findOne({
where: { id },
select:[
"id",
"posExecutiveName",
"posExecutivePriority"
]
});
if (!posExecutive) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
try {
return new HttpSuccess(posExecutive);
} catch (error) {
return error;
}
}
}