Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop
This commit is contained in:
commit
042422938c
2 changed files with 43 additions and 9 deletions
|
|
@ -21,7 +21,7 @@ import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import { OrgRevision } from "../entities/OrgRevision";
|
import { OrgRevision } from "../entities/OrgRevision";
|
||||||
|
|
||||||
@Route("organization")
|
@Route("api/v1/org")
|
||||||
@Tags("OrgRoot")
|
@Tags("OrgRoot")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
export class OrgRootController extends Controller {
|
export class OrgRootController extends Controller {
|
||||||
|
|
@ -54,9 +54,10 @@ export class OrgRootController extends Controller {
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const orgRevision = await this.orgRevisionRepository.findOne({
|
const validOrgRootRanks = ["DEPARTMENT", "OFFICE", "DIVISION", "SECTION"];
|
||||||
where: { id: requestBody.orgRevisionId },
|
if (!validOrgRootRanks.includes(requestBody.orgRootRank.toUpperCase())) {
|
||||||
});
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRootRank");
|
||||||
|
}
|
||||||
|
|
||||||
const orgRoot = Object.assign(new OrgRoot(), requestBody);
|
const orgRoot = Object.assign(new OrgRoot(), requestBody);
|
||||||
if (!orgRoot) {
|
if (!orgRoot) {
|
||||||
|
|
@ -69,6 +70,11 @@ export class OrgRootController extends Controller {
|
||||||
if (chkCode != null) {
|
if (chkCode != null) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const orgRevision = await this.orgRevisionRepository.findOne({
|
||||||
|
where: { id: requestBody.orgRevisionId },
|
||||||
|
});
|
||||||
|
|
||||||
if (orgRevision) {
|
if (orgRevision) {
|
||||||
orgRoot.createdUserId = request.user.sub;
|
orgRoot.createdUserId = request.user.sub;
|
||||||
orgRoot.createdFullName = request.user.name;
|
orgRoot.createdFullName = request.user.name;
|
||||||
|
|
@ -111,9 +117,15 @@ export class OrgRootController extends Controller {
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const orgRoot = await this.orgRootRepository.findOne({ where: { id } });
|
|
||||||
if (!orgRoot) {
|
const validOrgRootRanks = ["DEPARTMENT", "OFFICE", "DIVISION", "SECTION"];
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
if (!validOrgRootRanks.includes(requestBody.orgRootRank.toUpperCase())) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRootRank");
|
||||||
|
}
|
||||||
|
|
||||||
|
const revisionIdExits = await this.orgRevisionRepository.findOne({ where: {id:requestBody.orgRevisionId} });
|
||||||
|
if(!revisionIdExits){
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||||
}
|
}
|
||||||
|
|
||||||
const chkCode = await this.orgRootRepository.findOne({
|
const chkCode = await this.orgRootRepository.findOne({
|
||||||
|
|
@ -123,6 +135,12 @@ export class OrgRootController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const orgRoot = await this.orgRootRepository.findOne({ where: { id } });
|
||||||
|
if (!orgRoot) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
|
||||||
|
orgRoot.orgRevisionId = orgRoot.orgRevisionId
|
||||||
orgRoot.lastUpdateUserId = request.user.sub;
|
orgRoot.lastUpdateUserId = request.user.sub;
|
||||||
orgRoot.lastUpdateFullName = request.user.name;
|
orgRoot.lastUpdateFullName = request.user.name;
|
||||||
orgRoot.lastUpdatedAt = new Date();
|
orgRoot.lastUpdatedAt = new Date();
|
||||||
|
|
@ -156,7 +174,7 @@ export class OrgRootController extends Controller {
|
||||||
await this.orgRootRepository.remove(orgRoot);
|
await this.orgRootRepository.remove(orgRoot);
|
||||||
} else {
|
} else {
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
HttpStatusCode.NOT_FOUND,
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
"ไม่สามารถลบข้อมูลได้เมื่อมีข้อมูลโครงสร้างระดับ1",
|
"ไม่สามารถลบข้อมูลได้เมื่อมีข้อมูลโครงสร้างระดับ1",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -113,4 +113,20 @@ export class OrganizationController extends Controller {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รายละเอียดโครงสร้าง
|
||||||
|
*
|
||||||
|
* @summary ORG_023 - รายละเอียดโครงสร้าง (ADMIN) #25
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
// @Get()
|
||||||
|
// async detail(@Path() id: string) {
|
||||||
|
// try {
|
||||||
|
|
||||||
|
// return new HttpSuccess();
|
||||||
|
// } catch (error) {
|
||||||
|
// return error;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue