ผูก log โครงสร้างขรก
This commit is contained in:
parent
79989664d5
commit
b3ecbf5496
7 changed files with 76 additions and 43 deletions
|
|
@ -31,6 +31,7 @@ import { EmployeePosition } from "../entities/EmployeePosition";
|
|||
import { Like } from "typeorm/browser";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/child1")
|
||||
@Tags("OrgChild1")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -181,6 +182,7 @@ export class OrgChild1Controller {
|
|||
},
|
||||
order: { orgChild1Order: "DESC" },
|
||||
});
|
||||
const before = null;
|
||||
const child1 = Object.assign(new OrgChild1(), requestBody) as OrgChild1;
|
||||
child1.orgChild1Name = requestBody.orgChild1Name;
|
||||
child1.createdUserId = request.user.sub;
|
||||
|
|
@ -193,7 +195,8 @@ export class OrgChild1Controller {
|
|||
child1.orgRootId = String(rootIdExits?.id);
|
||||
child1.orgChild1Order =
|
||||
order == null || order.orgChild1Order == null ? 1 : order.orgChild1Order + 1;
|
||||
await this.child1Repository.save(child1);
|
||||
await this.child1Repository.save(child1, { data: request });
|
||||
setLogDataDiff( request, { before , after: child1});
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -296,7 +299,7 @@ export class OrgChild1Controller {
|
|||
// if(requestBody.orgChild1ShortName == rootIdExits.orgRootShortName){
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้ซ้ำกับอักษรย่อหน่วยงาน");
|
||||
// }
|
||||
|
||||
const before = structuredClone(child1);
|
||||
child1.lastUpdateUserId = request.user.sub;
|
||||
child1.lastUpdateFullName = request.user.name;
|
||||
child1.lastUpdatedAt = new Date();
|
||||
|
|
@ -304,7 +307,8 @@ export class OrgChild1Controller {
|
|||
child1.orgRootId = String(rootIdExits?.id);
|
||||
child1.responsibility = child1.responsibility || "";
|
||||
this.child1Repository.merge(child1, requestBody);
|
||||
await this.child1Repository.save(child1);
|
||||
await this.child1Repository.save(child1, { data: request });
|
||||
setLogDataDiff( request, { before, after: child1 });
|
||||
|
||||
const up_Child2 = await this.child2Repository.find({
|
||||
where: {
|
||||
|
|
@ -403,10 +407,10 @@ export class OrgChild1Controller {
|
|||
where: [{ posMasterId: In(empPosMasters.map((x) => x.id)) }],
|
||||
});
|
||||
|
||||
await this.empPositionRepository.remove(empPositions);
|
||||
await this.empPosMasterRepository.remove(empPosMasters);
|
||||
await this.positionRepository.remove(positions);
|
||||
await this.posMasterRepository.remove(posMasters);
|
||||
await this.empPositionRepository.remove(empPositions, { data: request });
|
||||
await this.empPosMasterRepository.remove(empPosMasters, { data: request });
|
||||
await this.positionRepository.remove(positions, { data: request });
|
||||
await this.posMasterRepository.remove(posMasters, { data: request });
|
||||
await this.child4Repository.delete({ orgChild1Id: id });
|
||||
await this.child3Repository.delete({ orgChild1Id: id });
|
||||
await this.child2Repository.delete({ orgChild1Id: id });
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
|||
import { EmployeePosition } from "../entities/EmployeePosition";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/child2")
|
||||
@Tags("OrgChild2")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -146,6 +147,7 @@ export class OrgChild2Controller extends Controller {
|
|||
},
|
||||
order: { orgChild2Order: "DESC" },
|
||||
});
|
||||
const before = null;
|
||||
const child2 = Object.assign(new OrgChild2(), requestBody) as OrgChild2;
|
||||
child2.orgChild2Name = requestBody.orgChild2Name;
|
||||
child2.createdUserId = request.user.sub;
|
||||
|
|
@ -159,7 +161,8 @@ export class OrgChild2Controller extends Controller {
|
|||
child2.orgChild1Id = String(child1?.id);
|
||||
child2.orgChild2Order =
|
||||
order == null || order.orgChild2Order == null ? 1 : order.orgChild2Order + 1;
|
||||
await this.child2Repository.save(child2);
|
||||
await this.child2Repository.save(child2, { data: request });
|
||||
setLogDataDiff( request, { before, after: child2 } );
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -226,6 +229,7 @@ export class OrgChild2Controller extends Controller {
|
|||
if (!child2) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
const before = structuredClone(child2);
|
||||
child2.lastUpdateUserId = request.user.sub;
|
||||
child2.lastUpdateFullName = request.user.name;
|
||||
child2.lastUpdatedAt = new Date();
|
||||
|
|
@ -233,7 +237,8 @@ export class OrgChild2Controller extends Controller {
|
|||
child2.orgRevisionId = String(child1IdExits?.orgRevisionId);
|
||||
child2.orgChild1Id = String(child1IdExits?.id);
|
||||
this.child2Repository.merge(child2, requestBody);
|
||||
await this.child2Repository.save(child2);
|
||||
await this.child2Repository.save(child2, { data: request });
|
||||
setLogDataDiff( request, { before, after: child2 } );
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -288,10 +293,10 @@ export class OrgChild2Controller extends Controller {
|
|||
where: [{ posMasterId: In(empPosMasters.map((x) => x.id)) }],
|
||||
});
|
||||
|
||||
await this.empPositionRepository.remove(empPositions);
|
||||
await this.empPosMasterRepository.remove(empPosMasters);
|
||||
await this.positionRepository.remove(positions);
|
||||
await this.posMasterRepository.remove(posMasters);
|
||||
await this.empPositionRepository.remove(empPositions, { data: request });
|
||||
await this.empPosMasterRepository.remove(empPosMasters, { data: request });
|
||||
await this.positionRepository.remove(positions, { data: request });
|
||||
await this.posMasterRepository.remove(posMasters, { data: request });
|
||||
await this.child4Repository.delete({ orgChild2Id: id });
|
||||
await this.child3Repository.delete({ orgChild2Id: id });
|
||||
await this.child2Repository.delete({ id });
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
|||
import { EmployeePosition } from "../entities/EmployeePosition";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/child3")
|
||||
@Tags("OrgChild3")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -125,6 +126,7 @@ export class OrgChild3Controller {
|
|||
},
|
||||
order: { orgChild3Order: "DESC" },
|
||||
});
|
||||
const before = null;
|
||||
const child3 = Object.assign(new OrgChild3(), requestBody) as OrgChild3;
|
||||
child3.orgChild3Name = requestBody.orgChild3Name;
|
||||
child3.createdUserId = request.user.sub;
|
||||
|
|
@ -139,7 +141,8 @@ export class OrgChild3Controller {
|
|||
child3.orgChild2Id = String(child2?.id);
|
||||
child3.orgChild3Order =
|
||||
order == null || order.orgChild3Order == null ? 1 : order.orgChild3Order + 1;
|
||||
await this.child3Repository.save(child3);
|
||||
await this.child3Repository.save(child3, { data: request });
|
||||
setLogDataDiff(request, { before, after: child3 });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -192,6 +195,7 @@ export class OrgChild3Controller {
|
|||
if (!child3) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
const before = structuredClone(child3);
|
||||
child3.lastUpdateUserId = request.user.sub;
|
||||
child3.lastUpdateFullName = request.user.name;
|
||||
child3.lastUpdatedAt = new Date();
|
||||
|
|
@ -200,7 +204,8 @@ export class OrgChild3Controller {
|
|||
child3.orgRevisionId = String(child2IdExits?.orgRevisionId);
|
||||
child3.orgChild2Id = String(child2IdExits?.id);
|
||||
this.child3Repository.merge(child3, requestBody);
|
||||
await this.child3Repository.save(child3);
|
||||
await this.child3Repository.save(child3, { data: request });
|
||||
setLogDataDiff(request, { before, after: child3 });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -255,10 +260,10 @@ export class OrgChild3Controller {
|
|||
where: [{ posMasterId: In(empPosMasters.map((x) => x.id)) }],
|
||||
});
|
||||
|
||||
await this.empPositionRepository.remove(empPositions);
|
||||
await this.empPosMasterRepository.remove(empPosMasters);
|
||||
await this.positionRepository.remove(positions);
|
||||
await this.posMasterRepository.remove(posMasters);
|
||||
await this.empPositionRepository.remove(empPositions, { data: request});
|
||||
await this.empPosMasterRepository.remove(empPosMasters, { data: request });
|
||||
await this.positionRepository.remove(positions, { data: request });
|
||||
await this.posMasterRepository.remove(posMasters, { data: request });
|
||||
await this.child4Repository.delete({ orgChild3Id: id });
|
||||
await this.child3Repository.delete(id);
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
|||
import { EmployeePosition } from "../entities/EmployeePosition";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/org/child4")
|
||||
@Tags("OrgChild4")
|
||||
|
|
@ -144,6 +145,7 @@ export class OrgChild4Controller extends Controller {
|
|||
},
|
||||
order: { orgChild4Order: "DESC" },
|
||||
});
|
||||
const before = null;
|
||||
const child4 = Object.assign(new OrgChild4(), requestBody) as OrgChild4;
|
||||
child4.orgChild4Name = requestBody.orgChild4Name;
|
||||
child4.createdUserId = request.user.sub;
|
||||
|
|
@ -159,7 +161,8 @@ export class OrgChild4Controller extends Controller {
|
|||
child4.orgChild3Id = String(child3?.id);
|
||||
child4.orgChild4Order =
|
||||
order == null || order.orgChild4Order == null ? 1 : order.orgChild4Order + 1;
|
||||
await this.child4Repository.save(child4);
|
||||
await this.child4Repository.save(child4, { data: request });
|
||||
setLogDataDiff(request, { before, after: child4 });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -227,6 +230,7 @@ export class OrgChild4Controller extends Controller {
|
|||
if (!child4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
const before = structuredClone(child4);
|
||||
child4.lastUpdateUserId = request.user.sub;
|
||||
child4.lastUpdateFullName = request.user.name;
|
||||
child4.lastUpdatedAt = new Date();
|
||||
|
|
@ -236,7 +240,8 @@ export class OrgChild4Controller extends Controller {
|
|||
child4.orgRevisionId = String(child3IdExits?.orgRevisionId);
|
||||
child4.orgChild3Id = String(child3IdExits?.id);
|
||||
this.child4Repository.merge(child4, requestBody);
|
||||
await this.child4Repository.save(child4);
|
||||
await this.child4Repository.save(child4, { data: request });
|
||||
setLogDataDiff(request, { before, after: child4 });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -283,10 +288,10 @@ export class OrgChild4Controller extends Controller {
|
|||
where: [{ posMasterId: In(empPosMasters.map((x) => x.id)) }],
|
||||
});
|
||||
|
||||
await this.empPositionRepository.remove(empPositions);
|
||||
await this.empPosMasterRepository.remove(empPosMasters);
|
||||
await this.positionRepository.remove(positions);
|
||||
await this.posMasterRepository.remove(posMasters);
|
||||
await this.empPositionRepository.remove(empPositions, { data: request });
|
||||
await this.empPosMasterRepository.remove(empPosMasters, { data: request });
|
||||
await this.positionRepository.remove(positions, { data: request });
|
||||
await this.posMasterRepository.remove(posMasters, { data: request });
|
||||
await this.child4Repository.delete(id);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
|||
import { EmployeePosition } from "../entities/EmployeePosition";
|
||||
import permission from "../interfaces/permission";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/org/root")
|
||||
@Tags("OrgRoot")
|
||||
|
|
@ -148,6 +149,7 @@ export class OrgRootController extends Controller {
|
|||
},
|
||||
order: { orgRootOrder: "DESC" },
|
||||
});
|
||||
const before = null;
|
||||
orgRoot.createdUserId = request.user.sub;
|
||||
orgRoot.createdFullName = request.user.name;
|
||||
orgRoot.lastUpdateUserId = request.user.sub;
|
||||
|
|
@ -155,7 +157,8 @@ export class OrgRootController extends Controller {
|
|||
orgRoot.createdAt = new Date();
|
||||
orgRoot.lastUpdatedAt = new Date();
|
||||
orgRoot.orgRootOrder = order == null || order.orgRootOrder == null ? 1 : order.orgRootOrder + 1;
|
||||
await this.orgRootRepository.save(orgRoot);
|
||||
await this.orgRootRepository.save(orgRoot, { data: request });
|
||||
setLogDataDiff(request, { before, after: orgRoot });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -254,12 +257,13 @@ export class OrgRootController extends Controller {
|
|||
// if(chkShortChild1 != null){
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้ซ้ำกับอักษรย่อส่วนราชการ");
|
||||
// }
|
||||
|
||||
const before = structuredClone(orgRoot);
|
||||
orgRoot.lastUpdateUserId = request.user.sub;
|
||||
orgRoot.lastUpdateFullName = request.user.name;
|
||||
orgRoot.lastUpdatedAt = new Date();
|
||||
this.orgRootRepository.merge(orgRoot, requestBody);
|
||||
await this.orgRootRepository.save(orgRoot);
|
||||
await this.orgRootRepository.save(orgRoot, { data: request });
|
||||
setLogDataDiff(request, {before, after: orgRoot});
|
||||
|
||||
if (orgRoot.orgRootRankSub == "DISTRICT" || orgRoot.orgRootRankSub == "OFFICE") {
|
||||
const up_Child1 = await this.child1Repository.find({
|
||||
|
|
@ -370,11 +374,11 @@ export class OrgRootController extends Controller {
|
|||
const empPositions = await this.empPositionRepository.find({
|
||||
where: [{ posMasterId: In(empPosMasters.map((x) => x.id)) }],
|
||||
});
|
||||
|
||||
await this.empPositionRepository.remove(empPositions);
|
||||
await this.empPosMasterRepository.remove(empPosMasters);
|
||||
await this.positionRepository.remove(positions);
|
||||
await this.posMasterRepository.remove(posMasters);
|
||||
|
||||
await this.empPositionRepository.remove(empPositions, { data: request });
|
||||
await this.empPosMasterRepository.remove(empPosMasters, { data: request });
|
||||
await this.positionRepository.remove(positions, { data: request });
|
||||
await this.posMasterRepository.remove(posMasters, { data: request });
|
||||
await this.child4Repository.delete({ orgRootId: id });
|
||||
await this.child3Repository.delete({ orgRootId: id });
|
||||
await this.child2Repository.delete({ orgRootId: id });
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import permission from "../interfaces/permission";
|
||||
import { PermissionOrg } from "../entities/PermissionOrg";
|
||||
import FunctionMain from "../interfaces/functionMain";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/org")
|
||||
@Tags("Organization")
|
||||
|
|
@ -124,6 +125,7 @@ export class OrganizationController extends Controller {
|
|||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
//new main revision
|
||||
const before = null;
|
||||
const revision = Object.assign(new OrgRevision(), requestBody) as OrgRevision;
|
||||
revision.orgRevisionIsDraft = true;
|
||||
revision.orgRevisionIsCurrent = false;
|
||||
|
|
@ -133,8 +135,8 @@ export class OrganizationController extends Controller {
|
|||
revision.lastUpdateFullName = request.user.name;
|
||||
revision.createdAt = new Date();
|
||||
revision.lastUpdatedAt = new Date();
|
||||
await this.orgRevisionRepository.save(revision);
|
||||
|
||||
await this.orgRevisionRepository.save(revision, { data: request });
|
||||
setLogDataDiff(request, { before, after: revision });
|
||||
//cone tree
|
||||
if (
|
||||
requestBody.typeDraft.toUpperCase() == "ORG" ||
|
||||
|
|
@ -2241,12 +2243,14 @@ export class OrganizationController extends Controller {
|
|||
if (!orgRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
const before = structuredClone(orgRevision);
|
||||
orgRevision.lastUpdateUserId = request.user.sub;
|
||||
orgRevision.lastUpdateFullName = request.user.name;
|
||||
orgRevision.lastUpdatedAt = new Date();
|
||||
orgRevision.orgPublishDate = requestBody.orgPublishDate;
|
||||
this.orgRevisionRepository.merge(orgRevision, requestBody);
|
||||
await this.orgRevisionRepository.save(orgRevision);
|
||||
await this.orgRevisionRepository.save(orgRevision, { data: request });
|
||||
setLogDataDiff(request, { before, after: orgRevision });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -2400,6 +2404,7 @@ export class OrganizationController extends Controller {
|
|||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionUpdate(request, "SYS_ORG");
|
||||
const before = null;
|
||||
switch (requestBody.type) {
|
||||
case 0: {
|
||||
const revisionId = await this.orgRevisionRepository.findOne({
|
||||
|
|
@ -2419,7 +2424,8 @@ export class OrganizationController extends Controller {
|
|||
id: data.id,
|
||||
orgRootOrder: requestBody.sortId.indexOf(data.id) + 1,
|
||||
}));
|
||||
await this.orgRootRepository.save(sortData);
|
||||
await this.orgRootRepository.save(sortData, { data: request });
|
||||
setLogDataDiff(request, { before, after: sortData });
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -2439,7 +2445,8 @@ export class OrganizationController extends Controller {
|
|||
id: data.id,
|
||||
orgChild1Order: requestBody.sortId.indexOf(data.id) + 1,
|
||||
}));
|
||||
await this.child1Repository.save(sortData);
|
||||
await this.child1Repository.save(sortData, { data: request });
|
||||
setLogDataDiff(request, { before, after: sortData });
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -2459,7 +2466,8 @@ export class OrganizationController extends Controller {
|
|||
id: data.id,
|
||||
orgChild2Order: requestBody.sortId.indexOf(data.id) + 1,
|
||||
}));
|
||||
await this.child2Repository.save(sortData);
|
||||
await this.child2Repository.save(sortData, { data: request });
|
||||
setLogDataDiff(request, { before, after: sortData });
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -2479,7 +2487,8 @@ export class OrganizationController extends Controller {
|
|||
id: data.id,
|
||||
orgChild3Order: requestBody.sortId.indexOf(data.id) + 1,
|
||||
}));
|
||||
await this.child3Repository.save(sortData);
|
||||
await this.child3Repository.save(sortData, { data: request });
|
||||
setLogDataDiff(request, { before, after: sortData });
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -2499,7 +2508,8 @@ export class OrganizationController extends Controller {
|
|||
id: data.id,
|
||||
orgChild4Order: requestBody.sortId.indexOf(data.id) + 1,
|
||||
}));
|
||||
await this.child4Repository.save(sortData);
|
||||
await this.child4Repository.save(sortData, { data: request });
|
||||
setLogDataDiff(request, { before, after: sortData });
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,10 +38,10 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
|||
|
||||
res.on("finish", () => {
|
||||
if (!req.url.startsWith("/api/")) return;
|
||||
let system = "org";
|
||||
let system = "organization";
|
||||
if (req.url.startsWith("/api/v1/org/metadata/")) system="metadata";
|
||||
if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin";
|
||||
if (req.url.startsWith("/api/v1/org/profile/")) system = "profile";
|
||||
if (req.url.startsWith("/api/v1/org/profile/")) system = "registry";
|
||||
// if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin";
|
||||
// if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue