org_30
This commit is contained in:
parent
c8bddda2e2
commit
0c8b82a41f
3 changed files with 182 additions and 82 deletions
|
|
@ -21,6 +21,8 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import { PosExecutive } from "../entities/PosExecutive";
|
||||
import { PosType } from "../entities/PosType";
|
||||
import { PosLevel } from "../entities/PosLevel";
|
||||
import { CreatePosition, Position } from "../entities/Position";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
@Route("api/v1/org/pos")
|
||||
@Tags("Position")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -31,8 +33,9 @@ import { PosLevel } from "../entities/PosLevel";
|
|||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class PositionController extends Controller {
|
||||
private posExecutiveRepository = AppDataSource.getRepository(PosExecutive);
|
||||
private posTypeRepository = AppDataSource.getRepository(PosType)
|
||||
private posTypeRepository = AppDataSource.getRepository(PosType);
|
||||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||||
private positionRepository = AppDataSource.getRepository(Position);
|
||||
|
||||
/**
|
||||
* API รายการตำแหน่งทางการบริหาร
|
||||
|
|
@ -162,4 +165,60 @@ export class PositionController extends Controller {
|
|||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API เพิ่มตำแหน่ง
|
||||
*
|
||||
* @summary ORG_030 - เพิ่มตำแหน่ง (ADMIN) #33
|
||||
*
|
||||
*/
|
||||
@Post("position")
|
||||
@Example([
|
||||
{
|
||||
positionName: "นักบริหาร",
|
||||
positionField: "บริหาร",
|
||||
posTypeId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
||||
posLevelId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
||||
posExecutiveId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
||||
positionExecutiveField: "นักบริหาร",
|
||||
positionArea: "บริหาร"
|
||||
},
|
||||
])
|
||||
async createPosition(
|
||||
@Body()
|
||||
requestBody: CreatePosition,
|
||||
@Request() request: { user: Record<string, any> },) {
|
||||
const position = Object.assign(new Position(), requestBody);
|
||||
if (!position) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
const checkPosTypeId = await this.posTypeRepository.findOne({where: { id: requestBody.posTypeId }});
|
||||
if (!checkPosTypeId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosTypeId");
|
||||
}
|
||||
|
||||
const checkPosLevelId = await this.posLevelRepository.findOne({where: { id: requestBody.posLevelId }});
|
||||
if (!checkPosLevelId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosLevelId");
|
||||
}
|
||||
|
||||
const checkPosExecutiveId = await this.posExecutiveRepository.findOne({where: { id: requestBody.posExecutiveId }});
|
||||
if (!checkPosExecutiveId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosExecutiveId");
|
||||
}
|
||||
|
||||
try {
|
||||
position.createdUserId = request.user.sub;
|
||||
position.createdFullName = request.user.name;
|
||||
position.lastUpdateUserId = request.user.sub;
|
||||
position.lastUpdateFullName = request.user.name;
|
||||
await this.positionRepository.save(position);
|
||||
return new HttpSuccess(position.id);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue