feat: add user relation on query

This commit is contained in:
Methapon2001 2024-07-01 14:38:07 +07:00
parent 2bd30b735d
commit 9f3b8cd290
14 changed files with 259 additions and 41 deletions

View file

@ -158,6 +158,8 @@ export class CustomerBranchController extends Controller {
province: true,
district: true,
subDistrict: true,
createdBy: true,
updatedBy: true,
_count: true,
},
where,
@ -177,6 +179,8 @@ export class CustomerBranchController extends Controller {
province: true,
district: true,
subDistrict: true,
createdBy: true,
updatedBy: true,
},
where: { id: branchId },
});
@ -213,6 +217,8 @@ export class CustomerBranchController extends Controller {
province: true,
district: true,
subDistrict: true,
createdBy: true,
updatedBy: true,
},
where,
take: pageSize,
@ -284,6 +290,8 @@ export class CustomerBranchController extends Controller {
province: true,
district: true,
subDistrict: true,
createdBy: true,
updatedBy: true,
},
data: {
...rest,
@ -363,6 +371,8 @@ export class CustomerBranchController extends Controller {
province: true,
district: true,
subDistrict: true,
createdBy: true,
updatedBy: true,
},
data: {
...rest,
@ -411,27 +421,32 @@ export class CustomerBranchController extends Controller {
);
}
return await prisma.customerBranch.delete({ where: { id: branchId } }).then((v) => {
new Promise<string[]>((resolve, reject) => {
const item: string[] = [];
return await prisma.customerBranch
.delete({
include: { createdBy: true, updatedBy: true },
where: { id: branchId },
})
.then((v) => {
new Promise<string[]>((resolve, reject) => {
const item: string[] = [];
const stream = minio.listObjectsV2(
MINIO_BUCKET,
`${attachmentLocation(record.customerId, branchId)}/`,
);
const stream = minio.listObjectsV2(
MINIO_BUCKET,
`${attachmentLocation(record.customerId, branchId)}/`,
);
stream.on("data", (v) => v && v.name && item.push(v.name));
stream.on("end", () => resolve(item));
stream.on("error", () => reject(new Error("MinIO error.")));
}).then((list) => {
list.map(async (v) => {
await minio.removeObject(MINIO_BUCKET, v, {
forceDelete: true,
stream.on("data", (v) => v && v.name && item.push(v.name));
stream.on("end", () => resolve(item));
stream.on("error", () => reject(new Error("MinIO error.")));
}).then((list) => {
list.map(async (v) => {
await minio.removeObject(MINIO_BUCKET, v, {
forceDelete: true,
});
});
});
return v;
});
return v;
});
}
}