สร้างโครงสร้าง
This commit is contained in:
parent
042422938c
commit
8184152ac0
16 changed files with 295 additions and 84 deletions
|
|
@ -130,6 +130,7 @@ export class OrgChild1Controller {
|
|||
child1.createdFullName = request.user.name;
|
||||
child1.lastUpdateUserId = request.user.sub;
|
||||
child1.lastUpdateFullName = request.user.name;
|
||||
child1.orgRevisionId = String(rootIdExits?.orgRevisionId);
|
||||
child1.orgRootId = String(rootIdExits?.id);
|
||||
await this.child1Repository.save(child1);
|
||||
return new HttpSuccess();
|
||||
|
|
@ -184,6 +185,7 @@ export class OrgChild1Controller {
|
|||
child1.lastUpdateUserId = request.user.sub;
|
||||
child1.lastUpdateFullName = request.user.name;
|
||||
child1.lastUpdatedAt = new Date();
|
||||
child1.orgRevisionId = String(rootIdExits?.orgRevisionId);
|
||||
child1.orgRootId = String(rootIdExits?.id);
|
||||
this.child1Repository.merge(child1, requestBody);
|
||||
await this.child1Repository.save(child1);
|
||||
|
|
|
|||
|
|
@ -22,8 +22,7 @@ import HttpError from "../interfaces/http-error";
|
|||
import { CreateOrgChild2, OrgChild2, UpdateOrgChild2 } from "../entities/OrgChild2";
|
||||
import { OrgChild1 } from "../entities/OrgChild1";
|
||||
import { OrgChild3 } from "../entities/OrgChild3";
|
||||
|
||||
@Route("organization")
|
||||
@Route("api/v1/org/child2")
|
||||
@Tags("OrgChild2")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
|
|
@ -82,6 +81,7 @@ export class OrgChild2Controller extends Controller {
|
|||
child2.lastUpdateUserId = request.user.sub;
|
||||
child2.lastUpdateFullName = request.user.name;
|
||||
child2.orgRootId = String(child1?.orgRootId);
|
||||
child2.orgRevisionId = String(child1?.orgRevisionId);
|
||||
child2.orgChild1Id = String(child1?.id);
|
||||
await this.child2Repository.save(child2);
|
||||
return new HttpSuccess();
|
||||
|
|
@ -142,6 +142,7 @@ export class OrgChild2Controller extends Controller {
|
|||
child2.lastUpdateFullName = request.user.name;
|
||||
child2.lastUpdatedAt = new Date();
|
||||
child2.orgRootId = String(child1IdExits?.orgRootId);
|
||||
child2.orgRevisionId = String(child1IdExits?.orgRevisionId);
|
||||
child2.orgChild1Id = String(child1IdExits?.id);
|
||||
this.child2Repository.merge(child2, requestBody);
|
||||
await this.child2Repository.save(child2);
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ export class OrgChild3Controller {
|
|||
child3.lastUpdateFullName = request.user.name;
|
||||
child3.orgRootId = String(child2?.orgRootId);
|
||||
child3.orgChild1Id = String(child2?.orgChild1Id);
|
||||
child3.orgRevisionId = String(child2?.orgRevisionId);
|
||||
child3.orgChild2Id = String(child2?.id);
|
||||
await this.child3Repository.save(child3);
|
||||
return new HttpSuccess();
|
||||
|
|
@ -113,6 +114,7 @@ export class OrgChild3Controller {
|
|||
child3.lastUpdatedAt = new Date();
|
||||
child3.orgRootId = String(child2IdExits?.orgRootId);
|
||||
child3.orgChild1Id = String(child2IdExits?.orgChild1Id);
|
||||
child3.orgRevisionId = String(child2IdExits?.orgRevisionId);
|
||||
child3.orgChild2Id = String(child2IdExits?.id);
|
||||
this.child3Repository.merge(child3, requestBody);
|
||||
await this.child3Repository.save(child3);
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ export class OrgChild4Controller extends Controller {
|
|||
* @summary ORG_013 - สร้างโครงสร้างระดับ4 (ADMIN) #13
|
||||
*
|
||||
*/
|
||||
@Post("child4")
|
||||
@Post()
|
||||
@Example([
|
||||
{
|
||||
orgChild4Name: "string", //ชื่อหน่วยงาน
|
||||
|
|
@ -83,6 +83,7 @@ export class OrgChild4Controller extends Controller {
|
|||
child4.orgRootId = String(child3?.orgRootId);
|
||||
child4.orgChild1Id = String(child3?.orgChild1Id);
|
||||
child4.orgChild2Id = String(child3?.orgChild2Id);
|
||||
child4.orgRevisionId = String(child3?.orgRevisionId);
|
||||
child4.orgChild3Id = String(child3?.id);
|
||||
await this.child4Repository.save(child4);
|
||||
|
||||
|
|
@ -99,7 +100,7 @@ export class OrgChild4Controller extends Controller {
|
|||
*
|
||||
* @param {string} id Guid, *Id Child4
|
||||
*/
|
||||
@Put("child4/{id}")
|
||||
@Put("{id}")
|
||||
@Example([
|
||||
{
|
||||
orgChild4Name: "string", //ชื่อหน่วยงาน
|
||||
|
|
@ -145,6 +146,8 @@ export class OrgChild4Controller extends Controller {
|
|||
child4.lastUpdatedAt = new Date();
|
||||
child4.orgRootId = String(child3IdExits?.orgRootId);
|
||||
child4.orgChild1Id = String(child3IdExits?.orgChild1Id);
|
||||
child4.orgChild2Id = String(child3IdExits?.orgChild2Id);
|
||||
child4.orgRevisionId = String(child3IdExits?.orgRevisionId);
|
||||
child4.orgChild3Id = String(child3IdExits?.id);
|
||||
this.child4Repository.merge(child4, requestBody);
|
||||
await this.child4Repository.save(child4);
|
||||
|
|
@ -161,7 +164,7 @@ export class OrgChild4Controller extends Controller {
|
|||
*
|
||||
* @param {string} id Guid, *Id Child4
|
||||
*/
|
||||
@Delete("child4/{id}")
|
||||
@Delete("{id}")
|
||||
async delete(@Path() id: string) {
|
||||
try {
|
||||
const child4 = await this.child4Repository.findOne({ where: { id } });
|
||||
|
|
|
|||
|
|
@ -76,12 +76,12 @@ export class OrgRootController extends Controller {
|
|||
});
|
||||
|
||||
if (orgRevision) {
|
||||
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);
|
||||
}else{
|
||||
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);
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี Revision");
|
||||
}
|
||||
|
||||
|
|
@ -117,17 +117,18 @@ export class OrgRootController extends Controller {
|
|||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
try {
|
||||
|
||||
const validOrgRootRanks = ["DEPARTMENT", "OFFICE", "DIVISION", "SECTION"];
|
||||
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){
|
||||
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({
|
||||
where: { orgRootCode: requestBody.orgRootCode },
|
||||
});
|
||||
|
|
@ -139,8 +140,7 @@ export class OrgRootController extends Controller {
|
|||
if (!orgRoot) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
orgRoot.orgRevisionId = orgRoot.orgRevisionId
|
||||
|
||||
orgRoot.lastUpdateUserId = request.user.sub;
|
||||
orgRoot.lastUpdateFullName = request.user.name;
|
||||
orgRoot.lastUpdatedAt = new Date();
|
||||
|
|
|
|||
|
|
@ -15,12 +15,17 @@ import {
|
|||
SuccessResponse,
|
||||
Response,
|
||||
} from "tsoa";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
import { CreateOrgRevision, OrgRevision } from "../entities/OrgRevision";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import { CreateOrgChild1, OrgChild1 } from "../entities/OrgChild1";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { In, Not } from "typeorm";
|
||||
import { OrgRoot } from "../entities/OrgRoot";
|
||||
import { OrgChild2 } from "../entities/OrgChild2";
|
||||
import { OrgChild3 } from "../entities/OrgChild3";
|
||||
import { OrgChild4 } from "../entities/OrgChild4";
|
||||
|
||||
@Route("api/v1/org")
|
||||
@Tags("Organization")
|
||||
|
|
@ -32,6 +37,11 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class OrganizationController extends Controller {
|
||||
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
|
||||
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
|
||||
private child1Repository = AppDataSource.getRepository(OrgChild1);
|
||||
private child2Repository = AppDataSource.getRepository(OrgChild2);
|
||||
private child3Repository = AppDataSource.getRepository(OrgChild3);
|
||||
private child4Repository = AppDataSource.getRepository(OrgChild4);
|
||||
|
||||
/**
|
||||
* API รายการประวัติโครงสร้าง
|
||||
|
|
@ -104,16 +114,172 @@ export class OrganizationController extends Controller {
|
|||
*/
|
||||
@Post()
|
||||
async CreateOrgRevision(
|
||||
@Body() requestBody: CreateOrgChild1,
|
||||
@Body() requestBody: CreateOrgRevision,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
try {
|
||||
return new HttpSuccess();
|
||||
const revision = Object.assign(new OrgRevision(), requestBody) as OrgRevision;
|
||||
revision.orgRevisionIsDraft = true;
|
||||
revision.orgRevisionIsCurrent = false;
|
||||
revision.createdUserId = request.user.sub;
|
||||
revision.createdFullName = request.user.name;
|
||||
revision.lastUpdateUserId = request.user.sub;
|
||||
revision.lastUpdateFullName = request.user.name;
|
||||
await this.orgRevisionRepository.save(revision);
|
||||
|
||||
if (requestBody.typeDraft.toUpperCase() == "ORG") {
|
||||
if (requestBody.orgRevisionId == null)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
const _revision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: requestBody.orgRevisionId },
|
||||
});
|
||||
if (!_revision) throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
|
||||
//clone data
|
||||
const orgRoot = await this.orgRootRepository.find({
|
||||
where: { orgRevisionId: requestBody.orgRevisionId },
|
||||
});
|
||||
const _orgRoot = orgRoot.map((x) => ({
|
||||
...x,
|
||||
isAncestorDNA:
|
||||
x.isAncestorDNA == null || x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
? x.id
|
||||
: x.isAncestorDNA,
|
||||
}));
|
||||
await this.orgRootRepository.save(_orgRoot);
|
||||
|
||||
_orgRoot.forEach(async (x: any) => {
|
||||
delete x.id;
|
||||
const data = Object.assign(new OrgRoot(), x);
|
||||
data.orgRevisionId = revision.id;
|
||||
data.createdUserId = request.user.sub;
|
||||
data.createdFullName = request.user.name;
|
||||
data.createdAt = new Date();
|
||||
data.lastUpdateUserId = request.user.sub;
|
||||
data.lastUpdateFullName = request.user.name;
|
||||
data.lastUpdatedAt = new Date();
|
||||
await this.orgRootRepository.save(data);
|
||||
});
|
||||
//clone data
|
||||
const orgChild1 = await this.child1Repository.find({
|
||||
where: { orgRevisionId: requestBody.orgRevisionId },
|
||||
});
|
||||
const _orgChild1 = orgChild1.map((x) => ({
|
||||
...x,
|
||||
isAncestorDNA:
|
||||
x.isAncestorDNA == null || x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
? x.id
|
||||
: x.isAncestorDNA,
|
||||
}));
|
||||
await this.child1Repository.save(_orgChild1);
|
||||
|
||||
_orgChild1.forEach(async (x: any) => {
|
||||
delete x.id;
|
||||
const data = Object.assign(new OrgChild1(), x);
|
||||
data.orgRevisionId = revision.id;
|
||||
data.createdUserId = request.user.sub;
|
||||
data.createdFullName = request.user.name;
|
||||
data.createdAt = new Date();
|
||||
data.lastUpdateUserId = request.user.sub;
|
||||
data.lastUpdateFullName = request.user.name;
|
||||
data.lastUpdatedAt = new Date();
|
||||
await this.child1Repository.save(data);
|
||||
});
|
||||
//clone data
|
||||
const orgChild2 = await this.child2Repository.find({
|
||||
where: { orgRevisionId: requestBody.orgRevisionId },
|
||||
});
|
||||
const _orgChild2 = orgChild2.map((x) => ({
|
||||
...x,
|
||||
isAncestorDNA:
|
||||
x.isAncestorDNA == null || x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
? x.id
|
||||
: x.isAncestorDNA,
|
||||
}));
|
||||
await this.child2Repository.save(_orgChild2);
|
||||
|
||||
_orgChild2.forEach(async (x: any) => {
|
||||
delete x.id;
|
||||
const data = Object.assign(new OrgChild2(), x);
|
||||
data.orgRevisionId = revision.id;
|
||||
data.createdUserId = request.user.sub;
|
||||
data.createdFullName = request.user.name;
|
||||
data.createdAt = new Date();
|
||||
data.lastUpdateUserId = request.user.sub;
|
||||
data.lastUpdateFullName = request.user.name;
|
||||
data.lastUpdatedAt = new Date();
|
||||
await this.child2Repository.save(data);
|
||||
});
|
||||
//clone data
|
||||
const orgChild3 = await this.child3Repository.find({
|
||||
where: { orgRevisionId: requestBody.orgRevisionId },
|
||||
});
|
||||
const _orgChild3 = orgChild3.map((x) => ({
|
||||
...x,
|
||||
isAncestorDNA:
|
||||
x.isAncestorDNA == null || x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
? x.id
|
||||
: x.isAncestorDNA,
|
||||
}));
|
||||
await this.child3Repository.save(_orgChild3);
|
||||
|
||||
_orgChild3.forEach(async (x: any) => {
|
||||
delete x.id;
|
||||
const data = Object.assign(new OrgChild3(), x);
|
||||
data.orgRevisionId = revision.id;
|
||||
data.createdUserId = request.user.sub;
|
||||
data.createdFullName = request.user.name;
|
||||
data.createdAt = new Date();
|
||||
data.lastUpdateUserId = request.user.sub;
|
||||
data.lastUpdateFullName = request.user.name;
|
||||
data.lastUpdatedAt = new Date();
|
||||
await this.child3Repository.save(data);
|
||||
});
|
||||
//clone data
|
||||
const orgChild4 = await this.child4Repository.find({
|
||||
where: { orgRevisionId: requestBody.orgRevisionId },
|
||||
});
|
||||
const _orgChild4 = orgChild4.map((x) => ({
|
||||
...x,
|
||||
isAncestorDNA:
|
||||
x.isAncestorDNA == null || x.isAncestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
? x.id
|
||||
: x.isAncestorDNA,
|
||||
}));
|
||||
await this.child4Repository.save(_orgChild4);
|
||||
|
||||
_orgChild4.forEach(async (x: any) => {
|
||||
delete x.id;
|
||||
const data = Object.assign(new OrgChild4(), x);
|
||||
data.orgRevisionId = revision.id;
|
||||
data.createdUserId = request.user.sub;
|
||||
data.createdFullName = request.user.name;
|
||||
data.createdAt = new Date();
|
||||
data.lastUpdateUserId = request.user.sub;
|
||||
data.lastUpdateFullName = request.user.name;
|
||||
data.lastUpdatedAt = new Date();
|
||||
await this.child4Repository.save(data);
|
||||
});
|
||||
} else if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
|
||||
} else if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") {
|
||||
}
|
||||
|
||||
const orgRevisions = await this.orgRevisionRepository.find({
|
||||
where: [{ orgRevisionIsDraft: true, id: Not(revision.id) }],
|
||||
});
|
||||
await this.child4Repository.delete({ orgRevisionId: In(orgRevisions.map((x) => x.id)) });
|
||||
await this.child3Repository.delete({ orgRevisionId: In(orgRevisions.map((x) => x.id)) });
|
||||
await this.child2Repository.delete({ orgRevisionId: In(orgRevisions.map((x) => x.id)) });
|
||||
await this.child1Repository.delete({ orgRevisionId: In(orgRevisions.map((x) => x.id)) });
|
||||
await this.orgRootRepository.delete({ orgRevisionId: In(orgRevisions.map((x) => x.id)) });
|
||||
await this.orgRevisionRepository.remove(orgRevisions);
|
||||
|
||||
return new HttpSuccess(revision);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* API รายละเอียดโครงสร้าง
|
||||
*
|
||||
|
|
@ -123,10 +289,13 @@ export class OrganizationController extends Controller {
|
|||
// @Get()
|
||||
// async detail(@Path() id: string) {
|
||||
// try {
|
||||
|
||||
|
||||
// return new HttpSuccess();
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
function ANY(arg0: OrgRevision[]): string | import("typeorm").FindOperator<string> | undefined {
|
||||
throw new Error("Function not implemented.");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue