สร้างสิทธิ์
This commit is contained in:
parent
fc5f28ee36
commit
b7cd88af9e
1 changed files with 27 additions and 8 deletions
|
|
@ -1186,7 +1186,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
//หา dna posmaster ถ้าไม่มีให้เอาตัวเองเป็น dna
|
//หา dna posmaster ถ้าไม่มีให้เอาตัวเองเป็น dna
|
||||||
const orgPosMaster = await posMasterRepository.find({
|
const orgPosMaster = await posMasterRepository.find({
|
||||||
where: { orgRevisionId: requestBody.orgRevisionId },
|
where: { orgRevisionId: requestBody.orgRevisionId },
|
||||||
relations: ["positions", "posMasterAssigns"],
|
relations: ["positions"],
|
||||||
});
|
});
|
||||||
|
|
||||||
let _orgPosMaster: PosMaster[] = [];
|
let _orgPosMaster: PosMaster[] = [];
|
||||||
|
|
@ -1237,6 +1237,9 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
for await (const item of orgPosMaster.filter(
|
for await (const item of orgPosMaster.filter(
|
||||||
(x: PosMaster) => x.orgRootId == dataId && x.orgChild1Id == null,
|
(x: PosMaster) => x.orgRootId == dataId && x.orgChild1Id == null,
|
||||||
) as any) {
|
) as any) {
|
||||||
|
let posMasterAssign = await posMasterAssignRepository.find({
|
||||||
|
where: { posMasterId: item.id },
|
||||||
|
});
|
||||||
delete item.id;
|
delete item.id;
|
||||||
const posMaster = Object.assign(new PosMaster(), item);
|
const posMaster = Object.assign(new PosMaster(), item);
|
||||||
posMaster.positions = [];
|
posMaster.positions = [];
|
||||||
|
|
@ -1275,7 +1278,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
|
|
||||||
// Copy assignments
|
// Copy assignments
|
||||||
await posMasterAssignRepository.save(
|
await posMasterAssignRepository.save(
|
||||||
item.posMasterAssigns.map(({ id, ...rest }: PosMasterAssign) => ({
|
posMasterAssign.map(({ id, ...rest }: PosMasterAssign) => ({
|
||||||
...rest,
|
...rest,
|
||||||
posMasterId: posMaster.id,
|
posMasterId: posMaster.id,
|
||||||
})),
|
})),
|
||||||
|
|
@ -1326,6 +1329,9 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
for await (const item of orgPosMaster.filter(
|
for await (const item of orgPosMaster.filter(
|
||||||
(x: PosMaster) => x.orgChild1Id == data1Id && x.orgChild2Id == null,
|
(x: PosMaster) => x.orgChild1Id == data1Id && x.orgChild2Id == null,
|
||||||
) as any) {
|
) as any) {
|
||||||
|
let posMasterAssign = await posMasterAssignRepository.find({
|
||||||
|
where: { posMasterId: item.id },
|
||||||
|
});
|
||||||
delete item.id;
|
delete item.id;
|
||||||
const posMaster = Object.assign(new PosMaster(), item);
|
const posMaster = Object.assign(new PosMaster(), item);
|
||||||
posMaster.positions = [];
|
posMaster.positions = [];
|
||||||
|
|
@ -1365,7 +1371,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
|
|
||||||
// Copy assignments
|
// Copy assignments
|
||||||
await posMasterAssignRepository.save(
|
await posMasterAssignRepository.save(
|
||||||
item.posMasterAssigns.map(({ id, ...rest }: PosMasterAssign) => ({
|
posMasterAssign.map(({ id, ...rest }: PosMasterAssign) => ({
|
||||||
...rest,
|
...rest,
|
||||||
posMasterId: posMaster.id,
|
posMasterId: posMaster.id,
|
||||||
})),
|
})),
|
||||||
|
|
@ -1417,6 +1423,9 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
for await (const item of orgPosMaster.filter(
|
for await (const item of orgPosMaster.filter(
|
||||||
(x: PosMaster) => x.orgChild2Id == data2Id && x.orgChild3Id == null,
|
(x: PosMaster) => x.orgChild2Id == data2Id && x.orgChild3Id == null,
|
||||||
) as any) {
|
) as any) {
|
||||||
|
let posMasterAssign = await posMasterAssignRepository.find({
|
||||||
|
where: { posMasterId: item.id },
|
||||||
|
});
|
||||||
delete item.id;
|
delete item.id;
|
||||||
const posMaster = Object.assign(new PosMaster(), item);
|
const posMaster = Object.assign(new PosMaster(), item);
|
||||||
posMaster.positions = [];
|
posMaster.positions = [];
|
||||||
|
|
@ -1457,7 +1466,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
|
|
||||||
// Copy assignments
|
// Copy assignments
|
||||||
await posMasterAssignRepository.save(
|
await posMasterAssignRepository.save(
|
||||||
item.posMasterAssigns.map(({ id, ...rest }: PosMasterAssign) => ({
|
posMasterAssign.map(({ id, ...rest }: PosMasterAssign) => ({
|
||||||
...rest,
|
...rest,
|
||||||
posMasterId: posMaster.id,
|
posMasterId: posMaster.id,
|
||||||
})),
|
})),
|
||||||
|
|
@ -1510,6 +1519,9 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
for await (const item of orgPosMaster.filter(
|
for await (const item of orgPosMaster.filter(
|
||||||
(x: PosMaster) => x.orgChild3Id == data3Id && x.orgChild4Id == null,
|
(x: PosMaster) => x.orgChild3Id == data3Id && x.orgChild4Id == null,
|
||||||
) as any) {
|
) as any) {
|
||||||
|
let posMasterAssign = await posMasterAssignRepository.find({
|
||||||
|
where: { posMasterId: item.id },
|
||||||
|
});
|
||||||
delete item.id;
|
delete item.id;
|
||||||
const posMaster = Object.assign(new PosMaster(), item);
|
const posMaster = Object.assign(new PosMaster(), item);
|
||||||
posMaster.positions = [];
|
posMaster.positions = [];
|
||||||
|
|
@ -1551,7 +1563,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
|
|
||||||
// Copy assignments
|
// Copy assignments
|
||||||
await posMasterAssignRepository.save(
|
await posMasterAssignRepository.save(
|
||||||
item.posMasterAssigns.map(({ id, ...rest }: PosMasterAssign) => ({
|
posMasterAssign.map(({ id, ...rest }: PosMasterAssign) => ({
|
||||||
...rest,
|
...rest,
|
||||||
posMasterId: posMaster.id,
|
posMasterId: posMaster.id,
|
||||||
})),
|
})),
|
||||||
|
|
@ -1606,6 +1618,9 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
for await (const item of orgPosMaster.filter(
|
for await (const item of orgPosMaster.filter(
|
||||||
(x: PosMaster) => x.orgChild4Id == data4Id,
|
(x: PosMaster) => x.orgChild4Id == data4Id,
|
||||||
) as any) {
|
) as any) {
|
||||||
|
let posMasterAssign = await posMasterAssignRepository.find({
|
||||||
|
where: { posMasterId: item.id },
|
||||||
|
});
|
||||||
delete item.id;
|
delete item.id;
|
||||||
const posMaster = Object.assign(new PosMaster(), item);
|
const posMaster = Object.assign(new PosMaster(), item);
|
||||||
posMaster.positions = [];
|
posMaster.positions = [];
|
||||||
|
|
@ -1648,7 +1663,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
|
|
||||||
// Copy assignments
|
// Copy assignments
|
||||||
await posMasterAssignRepository.save(
|
await posMasterAssignRepository.save(
|
||||||
item.posMasterAssigns.map(({ id, ...rest }: PosMasterAssign) => ({
|
posMasterAssign.map(({ id, ...rest }: PosMasterAssign) => ({
|
||||||
...rest,
|
...rest,
|
||||||
posMasterId: posMaster.id,
|
posMasterId: posMaster.id,
|
||||||
})),
|
})),
|
||||||
|
|
@ -1711,7 +1726,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
});
|
});
|
||||||
// await posMasterRepository.remove(_posMasters);
|
// await posMasterRepository.remove(_posMasters);
|
||||||
const batchSize = 1000;
|
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) {
|
for (let i = 0; i < data.length; i += batchSize) {
|
||||||
const batch = data.slice(i, i + batchSize);
|
const batch = data.slice(i, i + batchSize);
|
||||||
try {
|
try {
|
||||||
|
|
@ -1724,7 +1739,11 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
};
|
};
|
||||||
await removeInBatches(posMasterRepository, _posMasters, "PosMaster");
|
await removeInBatches(posMasterRepository, _posMasters, "PosMaster");
|
||||||
await removeInBatches(employeePosMasterRepository, _employeePosMasters, "EmployeePosMaster");
|
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 child4Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
|
||||||
await child3Repository.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)) });
|
await child2Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue