org_041-044 posExecutive
This commit is contained in:
parent
4adf3590f8
commit
a4786c4bb9
1 changed files with 35 additions and 6 deletions
|
|
@ -11,13 +11,13 @@ import {
|
||||||
Request,
|
Request,
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
|
Get,
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import { PosExecutive } from "../entities/PosExecutive";
|
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { CreatePosMaster, PosMaster } from "../entities/PosMaster";
|
import { CreatePosExecutive, PosExecutive } from "../entities/PosExecutive";
|
||||||
import { Position } from "../entities/Position";
|
import { Position } from "../entities/Position";
|
||||||
@Route("api/v1/org/pos")
|
@Route("api/v1/org/pos")
|
||||||
@Tags("PosExecutive")
|
@Tags("PosExecutive")
|
||||||
|
|
@ -40,7 +40,7 @@ export class PosExecutiveController extends Controller {
|
||||||
@Post("executive")
|
@Post("executive")
|
||||||
async createPosExecutive(
|
async createPosExecutive(
|
||||||
@Body()
|
@Body()
|
||||||
requestBody: CreatePosMaster,
|
requestBody: CreatePosExecutive,
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
) {
|
) {
|
||||||
const posExecutive = Object.assign(new PosExecutive(), requestBody);
|
const posExecutive = Object.assign(new PosExecutive(), requestBody);
|
||||||
|
|
@ -70,16 +70,17 @@ export class PosExecutiveController extends Controller {
|
||||||
async updatePosExecutive(
|
async updatePosExecutive(
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
@Body()
|
@Body()
|
||||||
requestBody: CreatePosMaster,
|
requestBody: CreatePosExecutive,
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
) {
|
) {
|
||||||
const posExecutive = Object.assign(new PosExecutive(), requestBody);
|
const posExecutive = await this.posExecutiveRepository.findOne({where: {id: id}});
|
||||||
if (!posExecutive) {
|
if (!posExecutive) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
posExecutive.lastUpdateUserId = request.user.sub;
|
posExecutive.lastUpdateUserId = request.user.sub;
|
||||||
posExecutive.lastUpdateFullName = request.user.name;
|
posExecutive.lastUpdateFullName = request.user.name;
|
||||||
|
this.posExecutiveRepository.merge(posExecutive, requestBody);
|
||||||
await this.posExecutiveRepository.save(posExecutive);
|
await this.posExecutiveRepository.save(posExecutive);
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -92,7 +93,7 @@ export class PosExecutiveController extends Controller {
|
||||||
*
|
*
|
||||||
* @summary ORG_043 - ลบตำแหน่งทางการบริหาร (ADMIN) #46
|
* @summary ORG_043 - ลบตำแหน่งทางการบริหาร (ADMIN) #46
|
||||||
*
|
*
|
||||||
* @param {string} id Id ตำแหน่ง
|
* @param {string} id Id ตำแหน่งทางการบริหาร
|
||||||
*/
|
*/
|
||||||
@Delete("executive/{id}")
|
@Delete("executive/{id}")
|
||||||
async deletePosExecutive(@Path() id: string) {
|
async deletePosExecutive(@Path() id: string) {
|
||||||
|
|
@ -110,4 +111,32 @@ export class PosExecutiveController extends Controller {
|
||||||
return error;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue