update license structures and setup file storage services

This commit is contained in:
2026-04-16 22:19:20 +03:30
parent d098ef10e1
commit ca494ee82a
75 changed files with 4550 additions and 1255 deletions
+7 -3
View File
@@ -39,7 +39,7 @@ export class ConsumerGuard {
role: true,
},
},
license: {
activated_licenses: {
select: {
expires_at: true,
},
@@ -54,10 +54,14 @@ export class ConsumerGuard {
const req = context.switchToHttp().getRequest<ExpressRequest>()
if (req.method !== 'GET') {
if (!consumer.license?.expires_at) {
if (!consumer.activated_licenses) {
throw new ForbiddenException('برای کاربر شما لایسنس ایجاد نشده است.')
}
if (new Date().getTime() > new Date(consumer.license?.expires_at).getTime()) {
if (
consumer.activated_licenses.every(
license => new Date().getTime() > new Date(license?.expires_at).getTime(),
)
) {
throw new ForbiddenException('لایسنس شما منقضی شده است.')
}
}
+31 -4
View File
@@ -25,6 +25,9 @@ export class PosGuard {
return false
}
const startOfToday = new Date()
startOfToday.setHours(0, 0, 0, 0)
const pos = await this.prisma.pos.findUnique({
where: {
id: posId,
@@ -44,7 +47,20 @@ export class PosGuard {
complex: {
select: {
id: true,
business_activity_id: true,
business_activity: {
select: {
id: true,
consumer: {
select: {
activated_licenses: {
select: {
expires_at: true,
},
},
},
},
},
},
},
},
},
@@ -54,6 +70,19 @@ export class PosGuard {
throw new ForbiddenException('شما دسترسی لازم را ندارید.')
}
if (req.method !== 'GET') {
if (!pos.complex.business_activity.consumer.activated_licenses.length) {
throw new ForbiddenException('برای کاربر شما لایسنس ایجاد نشده است.')
}
if (
pos.complex.business_activity.consumer.activated_licenses.every(
license => new Date().getTime() > new Date(license?.expires_at).getTime(),
)
) {
throw new ForbiddenException('لایسنس شما منقضی شده است.')
}
}
const foundedAccount = await this.prisma.consumerAccount.findUnique({
where: {
id: tokenPayload.account_id,
@@ -88,14 +117,12 @@ export class PosGuard {
}
if (
accountPermissions?.business_permissions.some(
p => p.business_id === pos.complex.business_activity_id,
p => p.business_id === pos.complex.business_activity.id,
)
) {
return true
}
return true
throw new ForbiddenException('شما دسترسی لازم را ندارید.')
}
}
+10 -8
View File
@@ -2,6 +2,7 @@ import { ITokenPayload } from '@/modules/auth/auth.utils'
import {
CanActivate,
ExecutionContext,
ForbiddenException,
Injectable,
UnauthorizedException,
} from '@nestjs/common'
@@ -63,14 +64,15 @@ export class JwtAuthGuard implements CanActivate {
// if (req.url.startsWith('/api/v1/partner')) {
// await this.partnerGuard.canActivate(tokenPayload, context)
// }
// if (req.url.startsWith('/api/v1/consumer')) {
// await this.consumerGuard.canActivate(tokenPayload, context)
// } else if (req.url.startsWith('/api/v1/pos')) {
// // await this.consumerGuard.canActivate(tokenPayload, context)
// await this.posGuard.canActivate(tokenPayload, context)
// } else if (tokenPayload.type != 'ADMIN') {
// throw new ForbiddenException('شما دسترسی لازم را ندارید')
// }
if (req.url.startsWith('/api/v1/consumer')) {
await this.consumerGuard.canActivate(tokenPayload, context)
} else if (req.url.startsWith('/api/v1/pos')) {
// await this.consumerGuard.canActivate(tokenPayload, context)
// await this.consumerGuard.canActivate(tokenPayload, context)
await this.posGuard.canActivate(tokenPayload, context)
} else if (tokenPayload.type != 'ADMIN') {
throw new ForbiddenException('شما دسترسی لازم را ندارید')
}
return true
} catch (err) {
if (err) throw err