checkpoint
This commit is contained in:
parent
42bd8cd77b
commit
5fbb2c5eea
4 changed files with 261 additions and 39 deletions
|
|
@ -1 +1,210 @@
|
|||
import { Controller, Get, Post, Put, Delete, Patch, Route, Security, Tags } from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Patch,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Path,
|
||||
Body,
|
||||
Request,
|
||||
Example,
|
||||
} from "tsoa";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { CreateOrgChild2, OrgChild2 } from "../entities/OrgChild2";
|
||||
|
||||
@Route("organization")
|
||||
@Tags("OrgChild2")
|
||||
@Security("bearerAuth")
|
||||
export class OrgChild2Controller extends Controller {
|
||||
private orgChild2Repository = AppDataSource.getRepository(OrgChild2);
|
||||
|
||||
/**
|
||||
* สร้างโครงสร้างระดับ2 Child2
|
||||
*
|
||||
* @summary ORG_007 - สร้างโครงสร้างระดับ2 (ADMIN) #7
|
||||
*
|
||||
* @param {string} id id ข้อมูลการประเมิน
|
||||
*/
|
||||
@Post("Child2")
|
||||
@Example([
|
||||
{
|
||||
orgChild2Name: "string", //ชื่อหน่วยงาน
|
||||
orgChild2ShortName: "string", //อักษรย่อ
|
||||
orgChild2Code: "string", //รหัสหน่วยงาน
|
||||
orgChild2Order: "number", //ลำดับที่ของหน่วยงาน
|
||||
orgChild2PhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
|
||||
orgChild2PhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
|
||||
orgChild2Fax: "string", //หมายเลขโทรสาร
|
||||
orgChild2IsNormal: "boolean", //สถานะของหน่วยงาน
|
||||
orgChild1Id: "Guid", //id Child1
|
||||
},
|
||||
])
|
||||
async create(
|
||||
@Body()
|
||||
requestBody: CreateOrgChild2,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
try {
|
||||
const orgChild1 = await this.orgChild2Repository.findOne({
|
||||
where: { id: requestBody.orgChild1Id },
|
||||
});
|
||||
const orgChild2 = Object.assign(new OrgChild2(), requestBody);
|
||||
if (!orgChild2) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
const chkOrder = await this.orgChild2Repository.findOne({
|
||||
where: { orgChild1Id:requestBody.orgChild1Id, orgChild2Order: requestBody.orgChild2Order },
|
||||
});
|
||||
if (chkOrder != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
const chkCode = await this.orgChild2Repository.findOne({
|
||||
where: { orgChild1Id:requestBody.orgChild1Id, orgChild2Code: requestBody.orgChild2Code },
|
||||
});
|
||||
if (chkCode != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
if(orgChild1){
|
||||
orgChild2.orgChild2Name = requestBody.orgChild2Name;
|
||||
orgChild2.orgChild2ShortName = requestBody.orgChild2ShortName;
|
||||
orgChild2.orgChild2Code = requestBody.orgChild2Code;
|
||||
orgChild2.orgChild2Order = requestBody.orgChild2Order;
|
||||
orgChild2.orgChild2PhoneEx = requestBody.orgChild2PhoneEx;
|
||||
orgChild2.orgChild2PhoneIn = requestBody.orgChild2PhoneIn;
|
||||
orgChild2.orgChild2Fax = requestBody.orgChild2Fax;
|
||||
orgChild2.orgChild2IsNormal = requestBody.orgChild2IsNormal;
|
||||
orgChild2.createdUserId = request.user.sub;
|
||||
orgChild2.createdFullName = request.user.name;
|
||||
orgChild2.lastUpdateUserId = request.user.sub;
|
||||
orgChild2.lastUpdateFullName = request.user.name;
|
||||
await this.orgChild2Repository.save(orgChild2);
|
||||
}else{
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีโครงสร้างระดับ1");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* แก้ไขโครงสร้างระดับ Child2
|
||||
*
|
||||
* @summary ORG_002 - แก้ไขโครงสร้างระดับ Child2 (ADMIN) #2
|
||||
*
|
||||
* @param {string} id Guid, *Id Child2
|
||||
*/
|
||||
// @Put("Child2/{id}")
|
||||
// @Example([
|
||||
// {
|
||||
// orgChild2Name: "string", //ชื่อหน่วยงาน
|
||||
// orgChild2ShortName: "string", //อักษรย่อ
|
||||
// orgChild2Code: "string", //รหัสหน่วยงาน
|
||||
// orgChild2Order: "number", //ลำดับที่ของหน่วยงาน
|
||||
// orgChild2PhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
|
||||
// orgChild2PhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
|
||||
// orgChild2Fax: "string", //หมายเลขโทรสาร
|
||||
// orgChild2IsNormal: "boolean", //สถานะของหน่วยงาน
|
||||
// },
|
||||
// ])
|
||||
// async update(
|
||||
// @Path() id: string,
|
||||
// @Body()
|
||||
// requestBody: CreateOrgChild2,
|
||||
// @Request() request: { user: Record<string, any> },
|
||||
// ) {
|
||||
// try {
|
||||
// const orgChild2 = await this.orgChild2Repository.findOne({ where: { id } });
|
||||
// if (!orgChild2) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
// const chkOrder = await this.orgChild2Repository.findOne({
|
||||
// where: { orgChild2Order: requestBody.orgChild2Order },
|
||||
// });
|
||||
// if (chkOrder != null) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
// }
|
||||
// const chkCode = await this.orgChild2Repository.findOne({
|
||||
// where: { orgChild2Code: requestBody.orgChild2Code },
|
||||
// });
|
||||
// if (chkCode != null) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
// }
|
||||
|
||||
// orgChild2.orgChild2Name = requestBody.orgChild2Name;
|
||||
// orgChild2.orgChild2ShortName = requestBody.orgChild2ShortName;
|
||||
// orgChild2.orgChild2Code = requestBody.orgChild2Code;
|
||||
// orgChild2.orgChild2Order = requestBody.orgChild2Order;
|
||||
// orgChild2.orgChild2PhoneEx = requestBody.orgChild2PhoneEx;
|
||||
// orgChild2.orgChild2PhoneIn = requestBody.orgChild2PhoneIn;
|
||||
// orgChild2.orgChild2Fax = requestBody.orgChild2Fax;
|
||||
// orgChild2.orgChild2IsNormal = requestBody.orgChild2IsNormal;
|
||||
// orgChild2.lastUpdateUserId = request.user.sub;
|
||||
// orgChild2.lastUpdateFullName = request.user.name;
|
||||
// await this.orgChild2Repository.save(orgChild2);
|
||||
|
||||
// return new HttpSuccess();
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* ลบโครงสร้างระดับ Child2
|
||||
*
|
||||
* @summary ORG_003 - ลบโครงสร้างระดับ Child2 (ADMIN) #3
|
||||
*
|
||||
* @param {string} id Guid, *Id Child2
|
||||
*/
|
||||
// @Delete("Child2/{id}")
|
||||
// async delete(@Path() id: string) {
|
||||
// try {
|
||||
// const orgChild2 = await this.orgChild2Repository.findOne({ where: { id } });
|
||||
// const orgChild1 = await await this.orgChild2Repository.findOne({ where: { id: id } });
|
||||
|
||||
// if (!orgChild2) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
|
||||
// if (!orgChild1) {
|
||||
// await this.orgChild2Repository.remove(orgChild2);
|
||||
// } else {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลได้");
|
||||
// }
|
||||
|
||||
// return new HttpSuccess();
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* รายละเอียดโครงสร้างระดับ Child2
|
||||
*
|
||||
* @summary ORG_016 - รายละเอียดโครงสร้างระดับ Child2 (ADMIN) #16
|
||||
*
|
||||
* @param {string} id Guid, *Id Child2
|
||||
*/
|
||||
// @Get("Child2/{id}")
|
||||
// async detail(@Path() id: string) {
|
||||
// try {
|
||||
// const orgChild2 = await this.orgChild2Repository.findOne({ where: { id } });
|
||||
|
||||
// if (!orgChild2) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
|
||||
// return new HttpSuccess(orgChild2);
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
|
||||
@Route("organization")
|
||||
@Tags("OrgRoot")
|
||||
// @Security("bearerAuth")
|
||||
@Security("bearerAuth")
|
||||
export class OrgRootController extends Controller {
|
||||
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
|
||||
|
||||
|
|
@ -77,6 +77,10 @@ export class OrgRootController extends Controller {
|
|||
orgRoot.orgRootPhoneIn = requestBody.orgRootPhoneIn;
|
||||
orgRoot.orgRootFax = requestBody.orgRootFax;
|
||||
orgRoot.orgRootIsNormal = requestBody.orgRootIsNormal;
|
||||
orgRoot.createdUserId = request.user.sub
|
||||
orgRoot.createdFullName = request.user.name
|
||||
orgRoot.lastUpdateUserId = request.user.sub;
|
||||
orgRoot.lastUpdateFullName = request.user.name;
|
||||
await this.orgRootRepository.save(orgRoot);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
@ -109,6 +113,7 @@ export class OrgRootController extends Controller {
|
|||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: CreateOrgRoot,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
try {
|
||||
const orgRoot = await this.orgRootRepository.findOne({ where: { id } });
|
||||
|
|
@ -136,6 +141,8 @@ export class OrgRootController extends Controller {
|
|||
orgRoot.orgRootPhoneIn = requestBody.orgRootPhoneIn;
|
||||
orgRoot.orgRootFax = requestBody.orgRootFax;
|
||||
orgRoot.orgRootIsNormal = requestBody.orgRootIsNormal;
|
||||
orgRoot.lastUpdateUserId = request.user.sub;
|
||||
orgRoot.lastUpdateFullName = request.user.name;
|
||||
await this.orgRootRepository.save(orgRoot);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -100,20 +100,49 @@ export class OrgChild2 extends EntityBase {
|
|||
})
|
||||
orgChild1Id: string;
|
||||
|
||||
// @ManyToOne(() => OrgRoot, orgRoot => orgRoot.orgChild2s)
|
||||
// @JoinColumn({ name: "orgRootId" })
|
||||
// orgRoot: OrgRoot;
|
||||
|
||||
@ManyToOne(() => OrgChild1, orgChild1 => orgChild1.orgChild2s)
|
||||
@JoinColumn({ name: "orgChild1Id" })
|
||||
orgChild1: OrgChild1;
|
||||
|
||||
//child table 3,4
|
||||
@OneToMany(() => OrgChild3, orgChild3 => orgChild3.orgChild2)
|
||||
orgChild3s: OrgChild3[];
|
||||
|
||||
// @OneToMany(() => OrgChild4, orgChild4 => orgChild4.orgChild2)
|
||||
// orgChild4s: OrgChild4[];
|
||||
}
|
||||
|
||||
export class CreateOrgChild2 {
|
||||
|
||||
@Column()
|
||||
orgChild2Name: string;
|
||||
|
||||
@Column()
|
||||
orgChild2ShortName: string;
|
||||
|
||||
@Column()
|
||||
orgChild2Code: string;
|
||||
|
||||
@Column()
|
||||
orgChild2Rank: string;
|
||||
|
||||
@Column()
|
||||
orgChild2Order: number;
|
||||
|
||||
@Column()
|
||||
orgChild2PhoneEx: string;
|
||||
|
||||
@Column()
|
||||
orgChild2PhoneIn: string;
|
||||
|
||||
@Column()
|
||||
orgChild2Fax: string;
|
||||
|
||||
@Column()
|
||||
orgChild2IsNormal: boolean;
|
||||
|
||||
@Column('uuid')
|
||||
orgRootId: string;
|
||||
|
||||
@Column('uuid')
|
||||
orgChild1Id: string;
|
||||
|
||||
}
|
||||
export type UpdateOrgChild2 = Partial<OrgChild2>;
|
||||
|
|
|
|||
|
|
@ -1,27 +1,17 @@
|
|||
import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { OrgChild1 } from "./OrgChild1";
|
||||
import { OrgChild2 } from "./OrgChild2";
|
||||
import { OrgChild3 } from "./OrgChild3";
|
||||
import { OrgChild4 } from "./OrgChild4";
|
||||
|
||||
// ENUM orgRootRank
|
||||
enum OrgRootRank {
|
||||
DEPARTMENT = "department",
|
||||
OFFICE = "office",
|
||||
DIVISION = "division",
|
||||
SECTION = "section",
|
||||
DEPARTMENT = "department",
|
||||
OFFICE = "office",
|
||||
DIVISION = "division",
|
||||
SECTION = "section",
|
||||
}
|
||||
|
||||
@Entity("orgRoot")
|
||||
export class OrgRoot extends EntityBase {
|
||||
// @Column({
|
||||
// comment: "",
|
||||
// length: 40,
|
||||
// default: "00000000-0000-0000-0000-000000000000",
|
||||
// })
|
||||
// orgRootId: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ชื่อหน่วยงาน",
|
||||
|
|
@ -85,35 +75,23 @@ export class OrgRoot extends EntityBase {
|
|||
@Column({
|
||||
nullable: true,
|
||||
comment: "สถานะของหน่วยงาน", //ปกติ = 1 , ยุกเลิก = 0
|
||||
default: true
|
||||
default: true,
|
||||
})
|
||||
orgRootIsNormal: boolean;
|
||||
|
||||
|
||||
@Column({
|
||||
length: 40,
|
||||
default: "00000000-0000-0000-0000-000000000000",
|
||||
})
|
||||
orgRevisionId: string;
|
||||
|
||||
//child table 1,2,3,4
|
||||
@OneToMany(() => OrgChild1, orgChild1 => orgChild1.orgRoot)
|
||||
@OneToMany(() => OrgChild1, (orgChild1) => orgChild1.orgRoot)
|
||||
orgChild1s: OrgChild1[];
|
||||
|
||||
// @OneToMany(() => OrgChild2, orgChild2 => orgChild2.orgRoot)
|
||||
// orgChild2s: OrgChild2[];
|
||||
|
||||
// @OneToMany(() => OrgChild3, orgChild3 => orgChild3.orgRoot)
|
||||
// orgChild3s: OrgChild3[];
|
||||
|
||||
// @OneToMany(() => OrgChild4, orgChild4 => orgChild4.orgRoot)
|
||||
// orgChild4s: OrgChild4[];
|
||||
|
||||
}
|
||||
|
||||
export type UpdateOrgRoot = Partial<OrgRoot>;
|
||||
|
||||
export class CreateOrgRoot {
|
||||
|
||||
@Column()
|
||||
orgRootName: string;
|
||||
|
||||
|
|
@ -140,5 +118,4 @@ export class CreateOrgRoot {
|
|||
|
||||
@Column()
|
||||
orgRootIsNormal: boolean;
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue