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
View File
@@ -16,3 +16,10 @@ export enum GoldKarat {
KARAT_21 = '21',
KARAT_24 = '24',
}
export const UploadedFileTypes = {
GOOD: 'good',
SERVICE: 'service',
PROFILE_AVATAR: 'profile_avatar',
}
export type UploadedFileTypes = (typeof UploadedFileTypes)[keyof typeof UploadedFileTypes]
+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
+1 -1
View File
@@ -1,4 +1,4 @@
export * from './consumerPayload.model'
export * from './posPayload.model'
export * from './tokenPayload.model'
export * from './uploadedFileTypes.model'
export * from './uploadFile.model'
+12
View File
@@ -0,0 +1,12 @@
import { UploadedFileTypes } from '@/common/enums/enums'
import { ApiProperty } from '@nestjs/swagger'
import { IsEnum } from 'class-validator'
export class UploadImageDto {
@ApiProperty({
enum: UploadedFileTypes,
example: UploadedFileTypes.GOOD,
})
@IsEnum(UploadedFileTypes)
type: UploadedFileTypes
}
@@ -1 +0,0 @@
export type TUploadedFileTypes = 'good' | 'service' | 'profile_avatar'