แก้ชื่อ tag

This commit is contained in:
Kittapath 2024-01-26 17:09:28 +07:00
parent 4b4f2423fa
commit f509e10f8c
9 changed files with 151 additions and 107 deletions

View file

@ -159,6 +159,14 @@ export class OrgChild1Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RootId");
}
const validOrgChild1Ranks = ["OFFICE", "DIVISION", "SECTION"];
if (
requestBody.orgChild1Rank == null ||
!validOrgChild1Ranks.includes(requestBody.orgChild1Rank.toUpperCase())
) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild2Rank");
}
const child1 = await this.child1Repository.findOne({ where: { id } });
if (!child1) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");

View file

@ -13,21 +13,28 @@ import {
Body,
Request,
Example,
SuccessResponse,
Response,
} 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";
import { CreateOrgChild2, OrgChild2, UpdateOrgChild2 } from "../entities/OrgChild2";
import { OrgChild1 } from "../entities/OrgChild1";
import { OrgChild3 } from "../entities/OrgChild3";
@Route("organization")
@Tags("OrgChild2")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class OrgChild2Controller extends Controller {
private orgChild1Repository = AppDataSource.getRepository(OrgChild1);
private orgChild2Repository = AppDataSource.getRepository(OrgChild2);
private orgChild3Repository = AppDataSource.getRepository(OrgChild3);
private child1Repository = AppDataSource.getRepository(OrgChild1);
private child2Repository = AppDataSource.getRepository(OrgChild2);
private child3Repository = AppDataSource.getRepository(OrgChild3);
/**
* 2 Child2
@ -35,7 +42,7 @@ export class OrgChild2Controller extends Controller {
* @summary ORG_007 - 2 (ADMIN) #7
*
*/
@Post("child2")
@Post()
@Example([
{
orgChild2Name: "string", //ชื่อหน่วยงาน
@ -45,7 +52,7 @@ export class OrgChild2Controller extends Controller {
orgChild2PhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
orgChild2PhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
orgChild2Fax: "string", //หมายเลขโทรสาร
orgChild2IsNormal: "boolean", //สถานะของหน่วยงาน
// orgChild2IsNormal: "boolean", //สถานะของหน่วยงาน
orgChild1Id: "Guid", //id Child1
},
])
@ -55,24 +62,28 @@ export class OrgChild2Controller extends Controller {
@Request() request: { user: Record<string, any> },
) {
try {
const orgChild1 = await this.orgChild1Repository.findOne({
//BE ใช้ orgChild1Id หา orgChild1Id, orgRootId
const child1 = await this.child1Repository.findOne({
where: { id: requestBody.orgChild1Id },
});
const orgChild2 = Object.assign(new OrgChild2(), requestBody);
if (!orgChild2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
if (!child1) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
if (orgChild1) {
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");
const validOrgChild2Ranks = ["OFFICE", "DIVISION", "SECTION"];
if (!validOrgChild2Ranks.includes(requestBody.orgChild2Rank.toUpperCase())) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild2Rank");
}
const child2 = Object.assign(new OrgChild2(), requestBody) as OrgChild2;
child2.orgChild2Name = requestBody.orgChild2Name;
child2.createdUserId = request.user.sub;
child2.createdFullName = request.user.name;
child2.lastUpdateUserId = request.user.sub;
child2.lastUpdateFullName = request.user.name;
child2.orgRootId = String(child1?.orgRootId);
child2.orgChild1Id = String(child1?.id);
await this.child2Repository.save(child2);
return new HttpSuccess();
} catch (error) {
return error;
@ -96,33 +107,44 @@ export class OrgChild2Controller extends Controller {
orgChild2PhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
orgChild2PhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
orgChild2Fax: "string", //หมายเลขโทรสาร
orgChild2IsNormal: "boolean", //สถานะของหน่วยงาน
// orgChild2IsNormal: "boolean", //สถานะของหน่วยงาน
orgChild1Id: "Guid", //id Child1
},
])
async update(
@Path() id: string,
@Body()
requestBody: CreateOrgChild2,
requestBody: UpdateOrgChild2,
@Request() request: { user: Record<string, any> },
) {
try {
const orgChild1 = await this.orgChild1Repository.findOne({
const child1IdExits = await this.child1Repository.findOne({
where: { id: requestBody.orgChild1Id },
});
const orgChild2 = await this.orgChild2Repository.findOne({ where: { id } });
if (!orgChild2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
if (!child1IdExits) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child1Id");
}
if (orgChild1) {
orgChild2.lastUpdateUserId = request.user.sub;
orgChild2.lastUpdateFullName = request.user.name;
orgChild2.lastUpdatedAt = new Date();
await this.orgChild2Repository.save(orgChild2);
} else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีโครงสร้างระดับ1");
const validOrgChild2Ranks = ["OFFICE", "DIVISION", "SECTION"];
if (
requestBody.orgChild2Rank == null ||
!validOrgChild2Ranks.includes(requestBody.orgChild2Rank.toUpperCase())
) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild2Rank");
}
const child2 = await this.child2Repository.findOne({ where: { id } });
if (!child2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
child2.lastUpdateUserId = request.user.sub;
child2.lastUpdateFullName = request.user.name;
child2.lastUpdatedAt = new Date();
child2.orgRootId = String(child1IdExits?.orgRootId);
child2.orgChild1Id = String(child1IdExits?.id);
this.child2Repository.merge(child2, requestBody);
await this.child2Repository.save(child2);
return new HttpSuccess();
} catch (error) {
return error;
@ -139,22 +161,18 @@ export class OrgChild2Controller extends Controller {
@Delete("Child2/{id}")
async delete(@Path() id: string) {
try {
const orgChild2 = await this.orgChild2Repository.findOne({ where: { id } });
const orgChild3 = await this.orgChild3Repository.findOne({ where: { orgChild2Id: id } });
if (!orgChild2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
const child2 = await this.child2Repository.findOne({ where: { id } });
if (!child2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
if (!orgChild3) {
await this.orgChild2Repository.remove(orgChild2);
} else {
const exitsChild3 = await this.child3Repository.findOne({ where: { orgChild2Id: id } });
if (exitsChild3) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่สามารถลบข้อมูลได้เมื่อมีข้อมูลโครงสร้างระดับ3",
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4",
);
}
await this.child2Repository.remove(child2);
return new HttpSuccess();
} catch (error) {
return error;

View file

@ -95,6 +95,14 @@ export class OrgChild3Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child2Id");
}
const validOrgChild3Ranks = ["OFFICE", "DIVISION", "SECTION"];
if (
requestBody.orgChild3Rank == null ||
!validOrgChild3Ranks.includes(requestBody.orgChild3Rank.toUpperCase())
) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild2Rank");
}
const child3 = await this.child3Repository.findOne({ where: { id } });
if (!child3) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");

View file

@ -51,7 +51,7 @@ export class OrgChild4Controller extends Controller {
orgChild4PhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
orgChild4PhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
orgChild4Fax: "string", //หมายเลขโทรสาร
orgChild4IsNormal: "boolean", //สถานะของหน่วยงาน
// orgChild4IsNormal: "boolean", //สถานะของหน่วยงาน
orgChild3Id: "Guid", //id Child1
},
])
@ -109,7 +109,7 @@ export class OrgChild4Controller extends Controller {
orgChild4PhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
orgChild4PhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
orgChild4Fax: "string", //หมายเลขโทรสาร
orgChild4IsNormal: "boolean", //สถานะของหน่วยงาน
// orgChild4IsNormal: "boolean", //สถานะของหน่วยงาน
orgChild3Id: "Guid", //id Child1
},
])
@ -127,6 +127,14 @@ export class OrgChild4Controller extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child3Id");
}
const validOrgChild4Ranks = ["OFFICE", "DIVISION", "SECTION"];
if (
requestBody.orgChild4Rank == null ||
!validOrgChild4Ranks.includes(requestBody.orgChild4Rank.toUpperCase())
) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild2Rank");
}
const child4 = await this.child4Repository.findOne({ where: { id } });
if (!child4) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");

View file

@ -12,7 +12,6 @@ enum OrgChild1Rank {
@Entity("orgChild1")
export class OrgChild1 extends EntityBase {
@Column({
nullable: true,
comment: "ชื่อส่วนราชการ",
@ -75,7 +74,7 @@ export class OrgChild1 extends EntityBase {
@Column({
nullable: true,
comment: "สถานะของหน่วยงาน",
default: true
default: true,
})
orgChild1IsNormal: boolean;
@ -91,17 +90,15 @@ export class OrgChild1 extends EntityBase {
})
isAncestorDNA: string;
@ManyToOne(() => OrgRoot, orgRoot => orgRoot.orgChild1s)
@ManyToOne(() => OrgRoot, (orgRoot) => orgRoot.orgChild1s)
@JoinColumn({ name: "orgRootId" })
orgRoot: OrgRoot;
@OneToMany(() => OrgChild2, orgChild2 => orgChild2.orgChild1)
@OneToMany(() => OrgChild2, (orgChild2) => orgChild2.orgChild1)
orgChild2s: OrgChild2[];
}
export class CreateOrgChild1 {
@Column()
orgChild1Name: string;
@ -110,22 +107,21 @@ export class CreateOrgChild1 {
@Column()
orgChild1Code?: string;
@Column()
orgChild1Rank: string;
@Column()
orgChild1PhoneEx: string;
orgChild1PhoneEx?: string;
@Column()
orgChild1PhoneIn: string;
orgChild1PhoneIn?: string;
@Column()
orgChild1Fax: string;
orgChild1Fax?: string;
@Column('uuid')
@Column("uuid")
orgRootId: string;
}
export type UpdateOrgChild1 = Partial<CreateOrgChild1> & { orgChild1Rank?: OrgChild1Rank };

View file

@ -14,12 +14,12 @@ enum OrgChild2Rank {
}
@Entity("orgChild2")
export class OrgChild2 extends EntityBase {
// @Column({
// comment: "",
// length: 40,
// default: "00000000-0000-0000-0000-000000000000",
// })
// orgChild2Id: string;
// @Column({
// comment: "",
// length: 40,
// default: "00000000-0000-0000-0000-000000000000",
// })
// orgChild2Id: string;
@Column({
nullable: true,
@ -84,7 +84,7 @@ export class OrgChild2 extends EntityBase {
@Column({
nullable: true,
comment: "สถานะของหน่วยงาน", //ปกติ = 1 , ยุกเลิก = 0
default: true
default: true,
})
orgChild2IsNormal: boolean;
@ -106,17 +106,15 @@ export class OrgChild2 extends EntityBase {
})
isAncestorDNA: string;
@ManyToOne(() => OrgChild1, orgChild1 => orgChild1.orgChild2s)
@ManyToOne(() => OrgChild1, (orgChild1) => orgChild1.orgChild2s)
@JoinColumn({ name: "orgChild1Id" })
orgChild1: OrgChild1;
@OneToMany(() => OrgChild3, orgChild3 => orgChild3.orgChild2)
@OneToMany(() => OrgChild3, (orgChild3) => orgChild3.orgChild2)
orgChild3s: OrgChild3[];
}
export class CreateOrgChild2 {
@Column()
orgChild2Name: string;
@ -125,21 +123,20 @@ export class CreateOrgChild2 {
@Column()
orgChild2Code: string;
@Column()
orgChild2Rank: string;
@Column()
orgChild2PhoneEx: string;
orgChild2PhoneEx?: string;
@Column()
orgChild2PhoneIn: string;
orgChild2PhoneIn?: string;
@Column()
orgChild2Fax: string;
orgChild2Fax?: string;
@Column('uuid')
@Column("uuid")
orgChild1Id: string;
}
export type UpdateOrgChild2 = Partial<CreateOrgChild2>;
export type UpdateOrgChild2 = Partial<CreateOrgChild2> & { orgChild2Rank?: OrgChild2Rank };

View file

@ -12,7 +12,6 @@ enum OrgChild3Rank {
@Entity("orgChild3")
export class OrgChild3 extends EntityBase {
@Column({
nullable: true,
comment: "ชื่อส่วนราชการ",
@ -75,7 +74,7 @@ export class OrgChild3 extends EntityBase {
@Column({
nullable: true,
comment: "สถานะของหน่วยงาน",
default: true
default: true,
})
orgChild3IsNormal: boolean;
@ -103,17 +102,15 @@ export class OrgChild3 extends EntityBase {
})
isAncestorDNA: string;
@ManyToOne(() => OrgChild2, orgChild2 => orgChild2.orgChild3s)
@ManyToOne(() => OrgChild2, (orgChild2) => orgChild2.orgChild3s)
@JoinColumn({ name: "orgChild2Id" })
orgChild2: OrgChild2;
@OneToMany(() => OrgChild4, orgChild4 => orgChild4.orgChild3)
@OneToMany(() => OrgChild4, (orgChild4) => orgChild4.orgChild3)
orgChild4s: OrgChild4[];
}
export class CreateOrgChild3 {
@Column()
orgChild3Name: string;
@ -122,22 +119,21 @@ export class CreateOrgChild3 {
@Column()
orgChild3Code: string;
@Column()
orgChild3Rank: string;
@Column()
orgChild3PhoneEx: string;
orgChild3PhoneEx?: string;
@Column()
orgChild3PhoneIn: string;
orgChild3PhoneIn?: string;
@Column()
orgChild3Fax: string;
orgChild3Fax?: string;
@Column('uuid')
@Column("uuid")
orgChild2Id: string;
}
export type UpdateOrgChild3 = Partial<CreateOrgChild3> & { orgChild3Rank?: OrgChild3Rank };

View file

@ -13,12 +13,12 @@ enum OrgChild4Rank {
}
@Entity("orgChild4")
export class OrgChild4 extends EntityBase {
// @Column({
// comment: "",
// length: 40,
// default: "00000000-0000-0000-0000-000000000000",
// })
// orgChild4Id: string;
// @Column({
// comment: "",
// length: 40,
// default: "00000000-0000-0000-0000-000000000000",
// })
// orgChild4Id: string;
@Column({
nullable: true,
@ -83,7 +83,7 @@ export class OrgChild4 extends EntityBase {
@Column({
nullable: true,
comment: "สถานะของหน่วยงาน", //ปกติ = 1 , ยุกเลิก = 0
default: true
default: true,
})
orgChild4IsNormal: boolean;
@ -116,14 +116,13 @@ export class OrgChild4 extends EntityBase {
default: "00000000-0000-0000-0000-000000000000",
})
isAncestorDNA: string;
@ManyToOne(() => OrgChild3, orgChild3 => orgChild3.orgChild4s)
@ManyToOne(() => OrgChild3, (orgChild3) => orgChild3.orgChild4s)
@JoinColumn({ name: "orgChild3Id" })
orgChild3: OrgChild3;
}
export class CreateOrgChild4 {
@Column()
orgChild4Name: string;
@ -132,21 +131,20 @@ export class CreateOrgChild4 {
@Column()
orgChild4Code: string;
@Column()
orgChild4Rank: string;
@Column()
orgChild4PhoneEx: string;
orgChild4PhoneEx?: string;
@Column()
orgChild4PhoneIn: string;
orgChild4PhoneIn?: string;
@Column()
orgChild4Fax: string;
@Column('uuid')
orgChild4Fax?: string;
@Column("uuid")
orgChild3Id: string;
}
export type UpdateOrgChild4 = Partial<OrgChild4>;

View file

@ -26,9 +26,24 @@
}
},
"tags": [
{
"name": "Test", "description": "ทดสอบ"
}
{
"name": "Organization", "description": "โครงสร้างส่วนอื่น ๆ"
},
{
"name": "OrgRoot", "description": "โครงสร้างระดับ root"
},
{
"name": "OrgChild1", "description": "โครงสร้างระดับ 1"
},
{
"name": "OrgChild2", "description": "โครงสร้างระดับ 2"
},
{
"name": "OrgChild3", "description": "โครงสร้างระดับ 3"
},
{
"name": "OrgChild4", "description": "โครงสร้างระดับ 4"
}
]
},
"routes": {