fix: line user not registered for all customer branch

This commit is contained in:
Methapon2001 2025-02-26 11:49:35 +07:00
parent ccbf21f71d
commit 6f1969c829
2 changed files with 89 additions and 14 deletions

View file

@ -73,7 +73,14 @@ export class LineController extends Controller {
status: activeOnly ? { not: Status.INACTIVE } : undefined, status: activeOnly ? { not: Status.INACTIVE } : undefined,
id: customerBranchId, id: customerBranchId,
customerId, customerId,
userId: line.user.sub, OR: [
{ userId: line.user.sub },
{
customer: {
branch: { some: { userId: line.user.sub } },
},
},
],
}, },
subDistrict: zipCode ? { zipCode } : undefined, subDistrict: zipCode ? { zipCode } : undefined,
gender, gender,
@ -135,7 +142,14 @@ export class LineController extends Controller {
where: { where: {
id: employeeId, id: employeeId,
customerBranch: { customerBranch: {
userId: line.user.sub, OR: [
{ userId: line.user.sub },
{
customer: {
branch: { some: { userId: line.user.sub } },
},
},
],
}, },
}, },
}); });
@ -220,7 +234,16 @@ export class LineController extends Controller {
// registeredBranch: { OR: permissionCond(req.user) }, // registeredBranch: { OR: permissionCond(req.user) },
}, },
employee: { employee: {
customerBranch: { userId: line.user.sub }, customerBranch: {
OR: [
{ userId: line.user.sub },
{
customer: {
branch: { some: { userId: line.user.sub } },
},
},
],
},
}, },
} satisfies Prisma.RequestDataWhereInput; } satisfies Prisma.RequestDataWhereInput;
@ -282,7 +305,16 @@ export class LineController extends Controller {
where: { where: {
id: requestDataId, id: requestDataId,
employee: { employee: {
customerBranch: { userId: line.user.sub }, customerBranch: {
OR: [
{ userId: line.user.sub },
{
customer: {
branch: { some: { userId: line.user.sub } },
},
},
],
},
}, },
}, },
include: { include: {
@ -399,7 +431,16 @@ export class LineController extends Controller {
: undefined, : undefined,
quotationId, quotationId,
employee: { employee: {
customerBranch: { userId: line.user.sub }, customerBranch: {
OR: [
{ userId: line.user.sub },
{
customer: {
branch: { some: { userId: line.user.sub } },
},
},
],
},
}, },
}, },
} satisfies Prisma.RequestWorkWhereInput; } satisfies Prisma.RequestWorkWhereInput;
@ -519,7 +560,16 @@ export class LineController extends Controller {
id: requestWorkId, id: requestWorkId,
request: { request: {
employee: { employee: {
customerBranch: { userId: line.user.sub }, customerBranch: {
OR: [
{ userId: line.user.sub },
{
customer: {
branch: { some: { userId: line.user.sub } },
},
},
],
},
}, },
}, },
}, },
@ -588,7 +638,14 @@ export class LineController extends Controller {
payCondition, payCondition,
quotationStatus: historyOnly ? { in: ["ProcessComplete", "Canceled"] } : status, quotationStatus: historyOnly ? { in: ["ProcessComplete", "Canceled"] } : status,
customerBranch: { customerBranch: {
userId: line.user.sub, OR: [
{ userId: line.user.sub },
{
customer: {
branch: { some: { userId: line.user.sub } },
},
},
],
}, },
requestData: inProgressOnly requestData: inProgressOnly
? { ? {
@ -698,7 +755,16 @@ export class LineController extends Controller {
where: { where: {
id: quotationId, id: quotationId,
isDebitNote: false, isDebitNote: false,
customerBranch: { userId: line.user.sub }, customerBranch: {
OR: [
{ userId: line.user.sub },
{
customer: {
branch: { some: { userId: line.user.sub } },
},
},
],
},
}, },
}); });

View file

@ -25,7 +25,18 @@ export class verificationController extends Controller {
@Get() @Get()
@Security("line") @Security("line")
async isRegistered(@Request() req: RequestWithLineUser) { async isRegistered(@Request() req: RequestWithLineUser) {
return !!(await prisma.customerBranch.findFirst({ where: { userId: req.user.sub } })); return !!(await prisma.customerBranch.findFirst({
where: {
OR: [
{ userId: req.user.sub },
{
customer: {
branch: { some: { userId: req.user.sub } },
},
},
],
},
}));
} }
@Post("/send-otp") @Post("/send-otp")
@ -133,13 +144,11 @@ export class verificationController extends Controller {
customerBranch.otpExpires && customerBranch.otpExpires &&
customerBranch.otpExpires >= new Date() customerBranch.otpExpires >= new Date()
) { ) {
const dataCustomer = await prisma.customerBranch.update({ const dataCustomer = await prisma.customerBranch.updateMany({
where: { where: {
id: customerBranch.id, customerId: customerBranch.customerId,
},
data: {
userId: req.user.sub,
}, },
data: { userId: req.user.sub },
}); });
return dataCustomer; return dataCustomer;