api ลบตำแหน่ง
This commit is contained in:
parent
e601dfccab
commit
d3cfe0855a
1 changed files with 31 additions and 12 deletions
|
|
@ -21,7 +21,7 @@ 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 { CreatePosDict, PosDict } from "../entities/PosDict";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
@Route("api/v1/org/pos")
|
||||
@Tags("Position")
|
||||
|
|
@ -35,7 +35,7 @@ export class PositionController extends Controller {
|
|||
private posExecutiveRepository = AppDataSource.getRepository(PosExecutive);
|
||||
private posTypeRepository = AppDataSource.getRepository(PosType);
|
||||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||||
private positionRepository = AppDataSource.getRepository(Position);
|
||||
private posDictRepository = AppDataSource.getRepository(PosDict);
|
||||
|
||||
/**
|
||||
* API รายการตำแหน่งทางการบริหาร
|
||||
|
|
@ -193,10 +193,10 @@ export class PositionController extends Controller {
|
|||
])
|
||||
async createPosition(
|
||||
@Body()
|
||||
requestBody: CreatePosition,
|
||||
requestBody: CreatePosDict,
|
||||
@Request() request: { user: Record<string, any> },) {
|
||||
const position = Object.assign(new Position(), requestBody);
|
||||
if (!position) {
|
||||
const posDict = Object.assign(new PosDict(), requestBody);
|
||||
if (!posDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
|
|
@ -216,16 +216,35 @@ export class PositionController extends Controller {
|
|||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* API ลบตำแหน่ง
|
||||
*
|
||||
* @summary ORG_032 - ลบตำแหน่ง (ADMIN) #40
|
||||
*
|
||||
* @param {string} id Id ตำแหน่ง
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async delete(@Path() id: string) {
|
||||
const delPosDict = await this.posDictRepository.findOne({ where: { id } });
|
||||
if (!delPosDict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
||||
}
|
||||
try {
|
||||
await this.posDictRepository.remove(delPosDict);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue