update entity OrgGroup and Org_013 - 15
This commit is contained in:
parent
6d136f8a97
commit
dde127a222
9 changed files with 273 additions and 24 deletions
|
|
@ -34,7 +34,6 @@ export class OrgChild2Controller extends Controller {
|
|||
*
|
||||
* @summary ORG_007 - สร้างโครงสร้างระดับ2 (ADMIN) #7
|
||||
*
|
||||
* @param {string} id id ข้อมูลการประเมิน
|
||||
*/
|
||||
@Post("child2")
|
||||
@Example([
|
||||
|
|
@ -85,6 +84,7 @@ export class OrgChild2Controller extends Controller {
|
|||
orgChild2.orgChild2Fax = requestBody.orgChild2Fax;
|
||||
orgChild2.orgChild2IsNormal = requestBody.orgChild2IsNormal;
|
||||
orgChild2.orgRootId = orgChild1.orgRootId;
|
||||
orgChild2.orgChild1Id = orgChild1.id;
|
||||
orgChild2.createdUserId = request.user.sub;
|
||||
orgChild2.createdFullName = request.user.name;
|
||||
orgChild2.lastUpdateUserId = request.user.sub;
|
||||
|
|
|
|||
|
|
@ -1 +1,202 @@
|
|||
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 { CreateOrgChild4, OrgChild4 } from "../entities/OrgChild4";
|
||||
import { OrgChild1 } from "../entities/OrgChild1";
|
||||
import { OrgChild3 } from "../entities/OrgChild3";
|
||||
|
||||
@Route("organization")
|
||||
@Tags("OrgChild4")
|
||||
// @Security("bearerAuth")
|
||||
export class OrgChild4Controller extends Controller {
|
||||
private orgChild3Repository = AppDataSource.getRepository(OrgChild3);
|
||||
private orgChild4Repository = AppDataSource.getRepository(OrgChild4);
|
||||
|
||||
/**
|
||||
* สร้างโครงสร้างระดับ4 Child4
|
||||
*
|
||||
* @summary ORG_013 - สร้างโครงสร้างระดับ4 (ADMIN) #13
|
||||
*
|
||||
*/
|
||||
@Post("child4")
|
||||
@Example([
|
||||
{
|
||||
orgChild4Name: "string", //ชื่อหน่วยงาน
|
||||
orgChild4ShortName: "string", //อักษรย่อ
|
||||
orgChild4Code: "string", //รหัสหน่วยงาน
|
||||
orgChild4Order: "number", //ลำดับที่ของหน่วยงาน
|
||||
orgChild4PhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
|
||||
orgChild4PhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
|
||||
orgChild4Fax: "string", //หมายเลขโทรสาร
|
||||
orgChild4IsNormal: "boolean", //สถานะของหน่วยงาน
|
||||
orgChild3Id: "Guid", //id Child1
|
||||
},
|
||||
])
|
||||
async create(
|
||||
@Body()
|
||||
requestBody: CreateOrgChild4,
|
||||
// @Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
try {
|
||||
console.log("child3Id:"+requestBody.orgChild3Id);
|
||||
|
||||
const orgChild3 = await this.orgChild3Repository.findOne({
|
||||
where: { id: requestBody.orgChild3Id },
|
||||
});
|
||||
const orgChild4 = Object.assign(new OrgChild4(), requestBody);
|
||||
if (!orgChild4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
const chkOrder = await this.orgChild4Repository.findOne({
|
||||
where: { orgChild3Id: requestBody.orgChild3Id, orgChild4Order: requestBody.orgChild4Order },
|
||||
});
|
||||
if (chkOrder != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
const chkCode = await this.orgChild4Repository.findOne({
|
||||
where: { orgChild3Id: requestBody.orgChild3Id, orgChild4Code: requestBody.orgChild4Code },
|
||||
});
|
||||
if (chkCode != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
if (orgChild3) {
|
||||
orgChild4.orgChild4Name = requestBody.orgChild4Name;
|
||||
orgChild4.orgChild4ShortName = requestBody.orgChild4ShortName;
|
||||
orgChild4.orgChild4Code = requestBody.orgChild4Code;
|
||||
orgChild4.orgChild4Order = requestBody.orgChild4Order;
|
||||
orgChild4.orgChild4PhoneEx = requestBody.orgChild4PhoneEx;
|
||||
orgChild4.orgChild4PhoneIn = requestBody.orgChild4PhoneIn;
|
||||
orgChild4.orgChild4Fax = requestBody.orgChild4Fax;
|
||||
orgChild4.orgChild4IsNormal = requestBody.orgChild4IsNormal;
|
||||
orgChild4.orgRootId = orgChild3.orgRootId;
|
||||
orgChild4.orgChild1Id = orgChild3.orgChild1Id;
|
||||
orgChild4.orgChild2Id = orgChild3.orgChild2Id;
|
||||
orgChild4.orgChild3Id = orgChild3.id;
|
||||
// orgChild4.createdUserId = request.user.sub;
|
||||
// orgChild4.createdFullName = request.user.name;
|
||||
// orgChild4.lastUpdateUserId = request.user.sub;
|
||||
// orgChild4.lastUpdateFullName = request.user.name;
|
||||
await this.orgChild4Repository.save(orgChild4);
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีโครงสร้างระดับ3");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* แก้ไขโครงสร้างระดับ4 Child4
|
||||
*
|
||||
* @summary ORG_014 - แก้ไขโครงสร้างระดับ4 (ADMIN) #14
|
||||
*
|
||||
* @param {string} id Guid, *Id Child4
|
||||
*/
|
||||
@Put("child4/{id}")
|
||||
@Example([
|
||||
{
|
||||
orgChild4Name: "string", //ชื่อหน่วยงาน
|
||||
orgChild4ShortName: "string", //อักษรย่อ
|
||||
orgChild4Code: "string", //รหัสหน่วยงาน
|
||||
orgChild4Order: "number", //ลำดับที่ของหน่วยงาน
|
||||
orgChild4PhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
|
||||
orgChild4PhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
|
||||
orgChild4Fax: "string", //หมายเลขโทรสาร
|
||||
orgChild4IsNormal: "boolean", //สถานะของหน่วยงาน
|
||||
orgChild3Id: "Guid", //id Child1
|
||||
},
|
||||
])
|
||||
async update(
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: CreateOrgChild4,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
try {
|
||||
const orgChild3 = await this.orgChild3Repository.findOne({
|
||||
where: { id: requestBody.orgChild3Id },
|
||||
});
|
||||
const orgChild4 = await this.orgChild4Repository.findOne({ where: { id } });
|
||||
if (!orgChild4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
const chkOrder = await this.orgChild4Repository.findOne({
|
||||
where: { orgChild4Order: requestBody.orgChild4Order },
|
||||
});
|
||||
if (chkOrder != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
const chkCode = await this.orgChild4Repository.findOne({
|
||||
where: { orgChild4Code: requestBody.orgChild4Code },
|
||||
});
|
||||
if (chkCode != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
if (orgChild3) {
|
||||
orgChild4.orgChild4Name = requestBody.orgChild4Name;
|
||||
orgChild4.orgChild4ShortName = requestBody.orgChild4ShortName;
|
||||
orgChild4.orgChild4Code = requestBody.orgChild4Code;
|
||||
orgChild4.orgChild4Order = requestBody.orgChild4Order;
|
||||
orgChild4.orgChild4PhoneEx = requestBody.orgChild4PhoneEx;
|
||||
orgChild4.orgChild4PhoneIn = requestBody.orgChild4PhoneIn;
|
||||
orgChild4.orgChild4Fax = requestBody.orgChild4Fax;
|
||||
orgChild4.orgChild4IsNormal = requestBody.orgChild4IsNormal;
|
||||
orgChild4.lastUpdateUserId = request.user.sub;
|
||||
orgChild4.lastUpdateFullName = request.user.name;
|
||||
await this.orgChild4Repository.save(orgChild4);
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีโครงสร้างระดับ3");
|
||||
}
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ลบโครงสร้างระดับ4 Child4
|
||||
*
|
||||
* @summary ORG_015 - ลบโครงสร้างระดับ4 (ADMIN) #15
|
||||
*
|
||||
* @param {string} id Guid, *Id Child4
|
||||
*/
|
||||
@Delete("child4/{id}")
|
||||
async delete(@Path() id: string) {
|
||||
try {
|
||||
const orgChild4 = await this.orgChild4Repository.findOne({ where: { id } });
|
||||
const orgChild3 = await this.orgChild3Repository.findOne({ where: { id: id } });
|
||||
|
||||
if (!orgChild4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
if (!orgChild3) {
|
||||
await this.orgChild4Repository.remove(orgChild4);
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลได้");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ export class OrgRootController extends Controller {
|
|||
*
|
||||
* @summary ORG_001 - สร้างโครงสร้างระดับ Root (ADMIN) #1
|
||||
*
|
||||
* @param {string} id id ข้อมูลการประเมิน
|
||||
*/
|
||||
@Post("root")
|
||||
@Example([
|
||||
|
|
|
|||
|
|
@ -85,6 +85,12 @@ export class OrgChild1 extends EntityBase {
|
|||
})
|
||||
orgRootId: string;
|
||||
|
||||
@Column({
|
||||
length: 40,
|
||||
default: "00000000-0000-0000-0000-000000000000",
|
||||
})
|
||||
isAncestorDNA: string;
|
||||
|
||||
@ManyToOne(() => OrgRoot, orgRoot => orgRoot.orgChild1s)
|
||||
@JoinColumn({ name: "orgRootId" })
|
||||
orgRoot: OrgRoot;
|
||||
|
|
|
|||
|
|
@ -100,6 +100,12 @@ export class OrgChild2 extends EntityBase {
|
|||
})
|
||||
orgChild1Id: string;
|
||||
|
||||
@Column({
|
||||
length: 40,
|
||||
default: "00000000-0000-0000-0000-000000000000",
|
||||
})
|
||||
isAncestorDNA: string;
|
||||
|
||||
@ManyToOne(() => OrgChild1, orgChild1 => orgChild1.orgChild2s)
|
||||
@JoinColumn({ name: "orgChild1Id" })
|
||||
orgChild1: OrgChild1;
|
||||
|
|
@ -138,11 +144,8 @@ export class CreateOrgChild2 {
|
|||
@Column()
|
||||
orgChild2IsNormal: boolean;
|
||||
|
||||
@Column('uuid')
|
||||
orgRootId: string;
|
||||
|
||||
@Column('uuid')
|
||||
orgChild1Id: string;
|
||||
|
||||
}
|
||||
export type UpdateOrgChild2 = Partial<OrgChild2>;
|
||||
export type UpdateOrgChild2 = Partial<CreateOrgChild2>;
|
||||
|
|
|
|||
|
|
@ -97,6 +97,12 @@ export class OrgChild3 extends EntityBase {
|
|||
})
|
||||
orgChild2Id: string;
|
||||
|
||||
@Column({
|
||||
length: 40,
|
||||
default: "00000000-0000-0000-0000-000000000000",
|
||||
})
|
||||
isAncestorDNA: string;
|
||||
|
||||
@ManyToOne(() => OrgChild2, orgChild2 => orgChild2.orgChild3s)
|
||||
@JoinColumn({ name: "orgChild2Id" })
|
||||
orgChild2: OrgChild2;
|
||||
|
|
@ -140,4 +146,4 @@ export class CreateOrgChild3 {
|
|||
|
||||
}
|
||||
|
||||
export type UpdateOrgChild3 = Partial<CreateOrgChild3> & { orgChild3Rank?: OrgChild3Rank };;
|
||||
export type UpdateOrgChild3 = Partial<CreateOrgChild3> & { orgChild3Rank?: OrgChild3Rank };
|
||||
|
|
|
|||
|
|
@ -110,21 +110,49 @@ export class OrgChild4 extends EntityBase {
|
|||
default: "00000000-0000-0000-0000-000000000000",
|
||||
})
|
||||
orgChild3Id: string;
|
||||
|
||||
@Column({
|
||||
length: 40,
|
||||
default: "00000000-0000-0000-0000-000000000000",
|
||||
})
|
||||
isAncestorDNA: string;
|
||||
|
||||
// @ManyToOne(() => OrgRoot, orgRoot => orgRoot.orgChild4s)
|
||||
// @JoinColumn({ name: "orgRootId" })
|
||||
// orgRoot: OrgRoot;
|
||||
|
||||
// @ManyToOne(() => OrgChild1, orgChild1 => orgChild1.orgChild4s)
|
||||
// @JoinColumn({ name: "orgChild1Id" })
|
||||
// orgChild1: OrgChild1;
|
||||
|
||||
// @ManyToOne(() => OrgChild2, orgChild2 => orgChild2.orgChild4s)
|
||||
// @JoinColumn({ name: "orgChild2Id" })
|
||||
// orgChild2: OrgChild2;
|
||||
|
||||
@ManyToOne(() => OrgChild3, orgChild3 => orgChild3.orgChild4s)
|
||||
@JoinColumn({ name: "orgChild3Id" })
|
||||
orgChild3: OrgChild3;
|
||||
}
|
||||
|
||||
export class CreateOrgChild4 {
|
||||
|
||||
@Column()
|
||||
orgChild4Name: string;
|
||||
|
||||
@Column()
|
||||
orgChild4ShortName: string;
|
||||
|
||||
@Column()
|
||||
orgChild4Code: string;
|
||||
|
||||
@Column()
|
||||
orgChild4Rank: string;
|
||||
|
||||
@Column()
|
||||
orgChild4Order: number;
|
||||
|
||||
@Column()
|
||||
orgChild4PhoneEx: string;
|
||||
|
||||
@Column()
|
||||
orgChild4PhoneIn: string;
|
||||
|
||||
@Column()
|
||||
orgChild4Fax: string;
|
||||
|
||||
@Column()
|
||||
orgChild4IsNormal: boolean;
|
||||
|
||||
@Column('uuid')
|
||||
orgChild3Id: string;
|
||||
|
||||
}
|
||||
export type UpdateOrgChild4 = Partial<OrgChild4>;
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@ export class OrgRevision extends EntityBase {
|
|||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "tinyint",
|
||||
comment: "",
|
||||
default: false
|
||||
})
|
||||
orgRevisionIsCurrent: number;
|
||||
orgRevisionIsCurrent: boolean;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
|
|
@ -33,10 +33,10 @@ export class OrgRevision extends EntityBase {
|
|||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "tinyint",
|
||||
comment: "",
|
||||
default: false
|
||||
})
|
||||
orgRevisionIsDraft: number;
|
||||
orgRevisionIsDraft: boolean;
|
||||
}
|
||||
|
||||
export type UpdateOrgRevision = Partial<OrgRevision>;
|
||||
|
|
|
|||
|
|
@ -85,6 +85,12 @@ export class OrgRoot extends EntityBase {
|
|||
})
|
||||
orgRevisionId: string;
|
||||
|
||||
@Column({
|
||||
length: 40,
|
||||
default: "00000000-0000-0000-0000-000000000000",
|
||||
})
|
||||
isAncestorDNA: string;
|
||||
|
||||
@OneToMany(() => OrgChild1, (orgChild1) => orgChild1.orgRoot)
|
||||
orgChild1s: OrgChild1[];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue