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

@ -173,6 +173,8 @@ export class UserController extends Controller {
district: true,
subDistrict: true,
branch: { include: { branch: includeBranch } },
createdBy: true,
updatedBy: true,
},
where,
take: pageSize,
@ -207,6 +209,8 @@ export class UserController extends Controller {
province: true,
district: true,
subDistrict: true,
createdBy: true,
updatedBy: true,
},
where: { id: userId },
});
@ -287,7 +291,13 @@ export class UserController extends Controller {
}
const record = await prisma.user.create({
include: { province: true, district: true, subDistrict: true },
include: {
province: true,
district: true,
subDistrict: true,
createdBy: true,
updatedBy: true,
},
data: {
id: userId,
...rest,
@ -417,7 +427,13 @@ export class UserController extends Controller {
}));
const record = await prisma.user.update({
include: { province: true, district: true, subDistrict: true },
include: {
province: true,
district: true,
subDistrict: true,
createdBy: true,
updatedBy: true,
},
data: {
...rest,
statusOrder: +(rest.status === "INACTIVE"),
@ -465,6 +481,8 @@ export class UserController extends Controller {
province: true,
district: true,
subDistrict: true,
createdBy: true,
updatedBy: true,
},
where: { id: userId },
});
@ -502,6 +520,8 @@ export class UserController extends Controller {
province: true,
district: true,
subDistrict: true,
createdBy: true,
updatedBy: true,
},
where: { id: userId },
});
@ -519,11 +539,6 @@ export class UserAttachmentController extends Controller {
@Get()
async listAttachment(@Path() userId: string) {
const record = await prisma.user.findFirst({
include: {
province: true,
district: true,
subDistrict: true,
},
where: { id: userId },
});
@ -552,11 +567,6 @@ export class UserAttachmentController extends Controller {
@Post()
async addAttachment(@Path() userId: string, @Body() payload: { file: string[] }) {
const record = await prisma.user.findFirst({
include: {
province: true,
district: true,
subDistrict: true,
},
where: { id: userId },
});