feat: refactor ComplexPosesService to remove unused defaultInsert method and improve findAll logic
fix: update PartnersService to use 'isNot' instead of 'not' for allocation checks refactor: enhance BusinessActivityComplexesService to validate license activation before creating a complex fix: adjust ComplexPosesService to ensure account allocation checks are accurate and handle errors properly refactor: modify ConsumerMiddleware to set consumerData instead of partnerData for better clarity feat: expand SaleInvoicesService to include additional fields in the invoice selection chore: update business-activities module to include accounts-charge module for better organization fix: ensure ComplexPosesService correctly handles account allocation during POS creation feat: implement PartnerBusinessActivityAccountsCharge module with create functionality for account charges refactor: streamline getPartnerBusinessActivityAllocationLimits utility for better clarity and functionality chore: add migration script to update database schema with necessary constraints and foreign keys feat: create DTO for accounts charge to validate incoming data
This commit is contained in:
@@ -18,104 +18,124 @@ export class PosGuard {
|
||||
throw new ForbiddenException('شما دسترسی لازم را ندارید.')
|
||||
}
|
||||
|
||||
const now = new Date()
|
||||
const cookie = req.cookies
|
||||
const { posId } = cookie
|
||||
|
||||
if (!posId) {
|
||||
return false
|
||||
throw new ForbiddenException('شما دسترسی لازم را ندارید.')
|
||||
}
|
||||
|
||||
const pos = await this.prisma.pos.findUnique({
|
||||
const checkLicenseActivation = await this.prisma.licenseAccountAllocation.findFirst({
|
||||
where: {
|
||||
id: posId,
|
||||
complex: {
|
||||
business_activity: {
|
||||
consumer: {
|
||||
consumer_accounts: {
|
||||
some: {
|
||||
id: tokenPayload.account_id,
|
||||
},
|
||||
account_id: tokenPayload.account_id,
|
||||
license_activation: {
|
||||
OR: [
|
||||
{
|
||||
expires_at: {
|
||||
gte: now,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
complex: {
|
||||
select: {
|
||||
id: true,
|
||||
business_activity: {
|
||||
select: {
|
||||
id: true,
|
||||
license_activation: {
|
||||
select: {
|
||||
expires_at: true,
|
||||
{
|
||||
license_renews: {
|
||||
some: {
|
||||
expires_at: {
|
||||
gte: now,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if (!pos) {
|
||||
throw new ForbiddenException('شما دسترسی لازم را ندارید.')
|
||||
}
|
||||
|
||||
if (req.method !== 'GET') {
|
||||
if (!pos.complex.business_activity.license_activation) {
|
||||
throw new ForbiddenException('برای کاربر شما لایسنس ایجاد نشده است.')
|
||||
}
|
||||
if (
|
||||
pos.complex.business_activity.license_activation.expires_at &&
|
||||
new Date().getTime() >
|
||||
new Date(pos.complex.business_activity.license_activation.expires_at).getTime()
|
||||
) {
|
||||
throw new ForbiddenException('لایسنس شما منقضی شده است.')
|
||||
}
|
||||
}
|
||||
|
||||
const foundedAccount = await this.prisma.consumerAccount.findUnique({
|
||||
where: {
|
||||
id: tokenPayload.account_id,
|
||||
},
|
||||
select: {
|
||||
role: true,
|
||||
},
|
||||
})
|
||||
|
||||
if (foundedAccount?.role === 'OWNER') {
|
||||
return true
|
||||
}
|
||||
|
||||
const accountPermissions = await this.prisma.permissionConsumer.findUnique({
|
||||
where: {
|
||||
consumer_account_id: tokenPayload.account_id,
|
||||
},
|
||||
select: {
|
||||
pos_permissions: true,
|
||||
business_permissions: true,
|
||||
complex_permissions: true,
|
||||
},
|
||||
})
|
||||
|
||||
if (accountPermissions?.pos_permissions.some(p => p.pos_id === posId)) {
|
||||
return true
|
||||
}
|
||||
if (
|
||||
accountPermissions?.complex_permissions.some(p => p.complex_id === pos.complex.id)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
if (
|
||||
accountPermissions?.business_permissions.some(
|
||||
p => p.business_id === pos.complex.business_activity.id,
|
||||
if (!checkLicenseActivation) {
|
||||
throw new ForbiddenException(
|
||||
'متاسفانه لایسنس شما منقضی شده است. لطفا برای تمدید لایسنس با پشتیبانی تماس بگیرید.',
|
||||
)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
throw new ForbiddenException('شما دسترسی لازم را ندارید.')
|
||||
return true
|
||||
// const pos = await this.prisma.pos.findUnique({
|
||||
// where: {
|
||||
// id: posId,
|
||||
// account_id: tokenPayload.account_id,
|
||||
// },
|
||||
// select: {
|
||||
// complex: {
|
||||
// select: {
|
||||
// id: true,
|
||||
// business_activity: {
|
||||
// select: {
|
||||
// id: true,
|
||||
// license_activation: {
|
||||
// select: {
|
||||
// expires_at: true,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
|
||||
// if (!pos) {
|
||||
// throw new ForbiddenException('شما دسترسی لازم را ندارید.')
|
||||
// }
|
||||
|
||||
// if (req.method !== 'GET') {
|
||||
// if (!pos.complex.business_activity.license_activation) {
|
||||
// throw new ForbiddenException('برای کاربر شما لایسنس ایجاد نشده است.')
|
||||
// }
|
||||
// if (
|
||||
// pos.complex.business_activity.license_activation.expires_at &&
|
||||
// new Date().getTime() >
|
||||
// new Date(pos.complex.business_activity.license_activation.expires_at).getTime()
|
||||
// ) {
|
||||
// throw new ForbiddenException('لایسنس شما منقضی شده است.')
|
||||
// }
|
||||
// }
|
||||
|
||||
// const foundedAccount = await this.prisma.consumerAccount.findUnique({
|
||||
// where: {
|
||||
// id: tokenPayload.account_id,
|
||||
// },
|
||||
// select: {
|
||||
// role: true,
|
||||
// },
|
||||
// })
|
||||
|
||||
// if (foundedAccount?.role === 'OWNER') {
|
||||
// return true
|
||||
// }
|
||||
|
||||
// const accountPermissions = await this.prisma.permissionConsumer.findUnique({
|
||||
// where: {
|
||||
// consumer_account_id: tokenPayload.account_id,
|
||||
// },
|
||||
// select: {
|
||||
// pos_permissions: true,
|
||||
// business_permissions: true,
|
||||
// complex_permissions: true,
|
||||
// },
|
||||
// })
|
||||
|
||||
// if (accountPermissions?.pos_permissions.some(p => p.pos_id === posId)) {
|
||||
// return true
|
||||
// }
|
||||
// if (
|
||||
// accountPermissions?.complex_permissions.some(p => p.complex_id === pos.complex.id)
|
||||
// ) {
|
||||
// return true
|
||||
// }
|
||||
// if (
|
||||
// accountPermissions?.business_permissions.some(
|
||||
// p => p.business_id === pos.complex.business_activity.id,
|
||||
// )
|
||||
// ) {
|
||||
// return true
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user