Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop
This commit is contained in:
commit
9e8ab0ae26
3 changed files with 133 additions and 2 deletions
109
src/controllers/PosMasterController.ts
Normal file
109
src/controllers/PosMasterController.ts
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
|
Delete,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
Body,
|
||||||
|
Path,
|
||||||
|
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 HttpError from "../interfaces/http-error";
|
||||||
|
import { PosMaster, CreatePosMaster, UpdatePosMaster } from "../entities/PosMaster";
|
||||||
|
import { Not } from "typeorm";
|
||||||
|
import { Position } from "../entities/Position";
|
||||||
|
|
||||||
|
@Route("api/v1/org/pos/profile")
|
||||||
|
@Tags("PosMaster")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
@Response(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||||
|
)
|
||||||
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||||
|
export class PosMasterController extends Controller {
|
||||||
|
private posMasterRepository = AppDataSource.getRepository(PosMaster);
|
||||||
|
private positionRepository = AppDataSource.getRepository(Position);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API สร้างทะเบียนประวัติ
|
||||||
|
*
|
||||||
|
* @summary ORG_065 - สร้างทะเบียนประวัติ (ADMIN) #70
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Post()
|
||||||
|
async createHolder(
|
||||||
|
@Body() requestBody: { posMaster: string; position: string; profileId: string; isSit: boolean },
|
||||||
|
) {
|
||||||
|
const dataMaster = await this.posMasterRepository.findOne({
|
||||||
|
where: { id: requestBody.posMaster },
|
||||||
|
relations: ["positions"],
|
||||||
|
});
|
||||||
|
if (!dataMaster) {
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.NOT_FOUND,
|
||||||
|
"ไม่พบข้อมูลไอดีนี้ : " + requestBody.posMaster,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
dataMaster.positions.forEach(async (position) => {
|
||||||
|
if (position.id === requestBody.position) {
|
||||||
|
position.positionIsSelected = true;
|
||||||
|
} else {
|
||||||
|
position.positionIsSelected = false;
|
||||||
|
}
|
||||||
|
await this.positionRepository.save(position);
|
||||||
|
});
|
||||||
|
|
||||||
|
dataMaster.isSit = requestBody.isSit;
|
||||||
|
dataMaster.next_holderId = requestBody.profileId;
|
||||||
|
await this.posMasterRepository.save(dataMaster);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API สร้างทะเบียนประวัติ
|
||||||
|
*
|
||||||
|
* @summary ORG_066 - ลบคนครองตำแหน่ง (ADMIN) #71
|
||||||
|
*
|
||||||
|
* @param {string} id *Id posMaster
|
||||||
|
*/
|
||||||
|
@Post("delete/{id}")
|
||||||
|
async deleteHolder(@Path() id: string) {
|
||||||
|
const dataMaster = await this.posMasterRepository.findOne({
|
||||||
|
where: { id: id },
|
||||||
|
relations: ["positions"],
|
||||||
|
});
|
||||||
|
if (!dataMaster) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await this.posMasterRepository.update(id, {
|
||||||
|
isSit: false,
|
||||||
|
next_holderId: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
dataMaster.positions.forEach(async (position) => {
|
||||||
|
await this.positionRepository.update(position.id, {
|
||||||
|
positionIsSelected: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -742,6 +742,28 @@ export class PositionController extends Controller {
|
||||||
relations: ["posLevel", "posType", "posExecutive"],
|
relations: ["posLevel", "posType", "posExecutive"],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(body.isAll === true) {
|
||||||
|
if(posMaster.orgRootId !== null && posMaster.orgChild1Id == null && posMaster.orgChild2Id == null
|
||||||
|
&& posMaster.orgChild2Id == null && posMaster.orgChild3Id == null) {
|
||||||
|
body.type = 0;
|
||||||
|
}
|
||||||
|
else if(posMaster.orgRootId !== null && posMaster.orgChild1Id !== null && posMaster.orgChild2Id == null
|
||||||
|
&& posMaster.orgChild2Id == null && posMaster.orgChild3Id == null) {
|
||||||
|
body.type = 1;
|
||||||
|
}
|
||||||
|
else if(posMaster.orgRootId !== null && posMaster.orgChild1Id !== null && posMaster.orgChild2Id !== null
|
||||||
|
&& posMaster.orgChild2Id == null && posMaster.orgChild3Id == null) {
|
||||||
|
body.type = 2;
|
||||||
|
}
|
||||||
|
else if(posMaster.orgRootId !== null && posMaster.orgChild1Id !== null && posMaster.orgChild2Id !== null
|
||||||
|
&& posMaster.orgChild2Id !== null && posMaster.orgChild3Id == null) {
|
||||||
|
body.type = 3;
|
||||||
|
}
|
||||||
|
else if(posMaster.orgRootId !== null && posMaster.orgChild1Id !== null && posMaster.orgChild2Id !== null
|
||||||
|
&& posMaster.orgChild2Id !== null && posMaster.orgChild3Id !== null) {
|
||||||
|
body.type = 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
id: posMaster.id,
|
id: posMaster.id,
|
||||||
orgRootId: posMaster.orgRootId,
|
orgRootId: posMaster.orgRootId,
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ export class PosMaster extends EntityBase {
|
||||||
"คนครองปัจจุบัน เมื่อทำสำเนาโครงสร้างและตำแหน่งพร้อมกับคนครองมา คนครองจะอยู่ในฟิลด์นี้",
|
"คนครองปัจจุบัน เมื่อทำสำเนาโครงสร้างและตำแหน่งพร้อมกับคนครองมา คนครองจะอยู่ในฟิลด์นี้",
|
||||||
default: null,
|
default: null,
|
||||||
})
|
})
|
||||||
current_holderId: string;
|
current_holderId?: string | null;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
|
|
@ -142,7 +142,7 @@ export class PosMaster extends EntityBase {
|
||||||
"คนที่กำลังจะมาครอง ตอนปรับโครงสร้าง ถ้าเลือกให้ใครมาครอง ProfileId ของคนนั้นจะมาอยู่ในช่องนี้ รวมทั้งตอนเลือกตำแหน่งเพื่อบรรจุ แต่งตั้ง เลื่อน ย้าย ในระบบบรรจุแต่งตั้งด้วย",
|
"คนที่กำลังจะมาครอง ตอนปรับโครงสร้าง ถ้าเลือกให้ใครมาครอง ProfileId ของคนนั้นจะมาอยู่ในช่องนี้ รวมทั้งตอนเลือกตำแหน่งเพื่อบรรจุ แต่งตั้ง เลื่อน ย้าย ในระบบบรรจุแต่งตั้งด้วย",
|
||||||
default: null,
|
default: null,
|
||||||
})
|
})
|
||||||
next_holderId: string;
|
next_holderId?: string | null;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
length: 40,
|
length: 40,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue