สร้างสิทธิ์

This commit is contained in:
mamoss 2025-03-19 18:16:58 +07:00
parent fc5f28ee36
commit b7cd88af9e

View file

@ -1186,7 +1186,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
//หา dna posmaster ถ้าไม่มีให้เอาตัวเองเป็น dna
const orgPosMaster = await posMasterRepository.find({
where: { orgRevisionId: requestBody.orgRevisionId },
relations: ["positions", "posMasterAssigns"],
relations: ["positions"],
});
let _orgPosMaster: PosMaster[] = [];
@ -1237,6 +1237,9 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
for await (const item of orgPosMaster.filter(
(x: PosMaster) => x.orgRootId == dataId && x.orgChild1Id == null,
) as any) {
let posMasterAssign = await posMasterAssignRepository.find({
where: { posMasterId: item.id },
});
delete item.id;
const posMaster = Object.assign(new PosMaster(), item);
posMaster.positions = [];
@ -1275,7 +1278,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
// Copy assignments
await posMasterAssignRepository.save(
item.posMasterAssigns.map(({ id, ...rest }: PosMasterAssign) => ({
posMasterAssign.map(({ id, ...rest }: PosMasterAssign) => ({
...rest,
posMasterId: posMaster.id,
})),
@ -1326,6 +1329,9 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
for await (const item of orgPosMaster.filter(
(x: PosMaster) => x.orgChild1Id == data1Id && x.orgChild2Id == null,
) as any) {
let posMasterAssign = await posMasterAssignRepository.find({
where: { posMasterId: item.id },
});
delete item.id;
const posMaster = Object.assign(new PosMaster(), item);
posMaster.positions = [];
@ -1365,7 +1371,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
// Copy assignments
await posMasterAssignRepository.save(
item.posMasterAssigns.map(({ id, ...rest }: PosMasterAssign) => ({
posMasterAssign.map(({ id, ...rest }: PosMasterAssign) => ({
...rest,
posMasterId: posMaster.id,
})),
@ -1417,6 +1423,9 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
for await (const item of orgPosMaster.filter(
(x: PosMaster) => x.orgChild2Id == data2Id && x.orgChild3Id == null,
) as any) {
let posMasterAssign = await posMasterAssignRepository.find({
where: { posMasterId: item.id },
});
delete item.id;
const posMaster = Object.assign(new PosMaster(), item);
posMaster.positions = [];
@ -1457,7 +1466,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
// Copy assignments
await posMasterAssignRepository.save(
item.posMasterAssigns.map(({ id, ...rest }: PosMasterAssign) => ({
posMasterAssign.map(({ id, ...rest }: PosMasterAssign) => ({
...rest,
posMasterId: posMaster.id,
})),
@ -1510,6 +1519,9 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
for await (const item of orgPosMaster.filter(
(x: PosMaster) => x.orgChild3Id == data3Id && x.orgChild4Id == null,
) as any) {
let posMasterAssign = await posMasterAssignRepository.find({
where: { posMasterId: item.id },
});
delete item.id;
const posMaster = Object.assign(new PosMaster(), item);
posMaster.positions = [];
@ -1551,7 +1563,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
// Copy assignments
await posMasterAssignRepository.save(
item.posMasterAssigns.map(({ id, ...rest }: PosMasterAssign) => ({
posMasterAssign.map(({ id, ...rest }: PosMasterAssign) => ({
...rest,
posMasterId: posMaster.id,
})),
@ -1606,6 +1618,9 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
for await (const item of orgPosMaster.filter(
(x: PosMaster) => x.orgChild4Id == data4Id,
) as any) {
let posMasterAssign = await posMasterAssignRepository.find({
where: { posMasterId: item.id },
});
delete item.id;
const posMaster = Object.assign(new PosMaster(), item);
posMaster.positions = [];
@ -1648,7 +1663,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
// Copy assignments
await posMasterAssignRepository.save(
item.posMasterAssigns.map(({ id, ...rest }: PosMasterAssign) => ({
posMasterAssign.map(({ id, ...rest }: PosMasterAssign) => ({
...rest,
posMasterId: posMaster.id,
})),
@ -1711,7 +1726,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
});
// await posMasterRepository.remove(_posMasters);
const batchSize = 1000;
const removeInBatches = async (repository:any, data:any, label:any) => {
const removeInBatches = async (repository: any, data: any, label: any) => {
for (let i = 0; i < data.length; i += batchSize) {
const batch = data.slice(i, i + batchSize);
try {
@ -1724,7 +1739,11 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
};
await removeInBatches(posMasterRepository, _posMasters, "PosMaster");
await removeInBatches(employeePosMasterRepository, _employeePosMasters, "EmployeePosMaster");
await removeInBatches(employeeTempPosMasterRepository, _employeeTempPosMasters, "EmployeeTempPosMaster");
await removeInBatches(
employeeTempPosMasterRepository,
_employeeTempPosMasters,
"EmployeeTempPosMaster",
);
await child4Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
await child3Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
await child2Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });