update models and create consumer domain accounts permissions
This commit is contained in:
@@ -8,4 +8,7 @@ export default {
|
||||
GOLD: 'طلا',
|
||||
ACTIVE: 'فعال',
|
||||
SUSPENDED: 'غیرفعال',
|
||||
OWNER: 'مدیر اصلی',
|
||||
MANAGER: 'مدیریت',
|
||||
OPERATOR: 'اپراتور',
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@ export const TokenAccount = createParamDecorator(
|
||||
// ✅ if called with no param — return full account object
|
||||
return account
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
|
||||
throw new BadRequestException('مشکلی در ساختار درخواست شما وجود دارد.')
|
||||
}
|
||||
},
|
||||
|
||||
@@ -12,18 +12,24 @@ export class ConsumerGuard {
|
||||
tokenPayload: ITokenPayload,
|
||||
context: ExecutionContext,
|
||||
): Promise<boolean> {
|
||||
if (!tokenPayload || tokenPayload.type !== 'CONSUMER')
|
||||
if (!tokenPayload || tokenPayload.type !== 'CONSUMER') {
|
||||
throw new ForbiddenException('شما دسترسی لازم را ندارید.')
|
||||
}
|
||||
|
||||
const consumer = await this.prisma.consumer.findFirst({
|
||||
where: {
|
||||
accounts: {
|
||||
consumer_accounts: {
|
||||
some: {
|
||||
id: tokenPayload.account_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
consumer_accounts: {
|
||||
select: {
|
||||
role: true,
|
||||
},
|
||||
},
|
||||
license: {
|
||||
select: {
|
||||
expires_at: true,
|
||||
@@ -31,6 +37,7 @@ export class ConsumerGuard {
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if (!consumer) {
|
||||
throw new ForbiddenException('شما دسترسی لازم را ندارید.')
|
||||
}
|
||||
|
||||
@@ -14,8 +14,9 @@ export class PosGuard {
|
||||
): Promise<boolean> {
|
||||
const req = context.switchToHttp().getRequest<ExpressRequest>()
|
||||
|
||||
if (!tokenPayload || tokenPayload.type !== 'CONSUMER')
|
||||
if (!tokenPayload || tokenPayload.type !== 'CONSUMER') {
|
||||
throw new ForbiddenException('شما دسترسی لازم را ندارید.')
|
||||
}
|
||||
|
||||
const cookie = req.cookies
|
||||
const { posId } = cookie
|
||||
@@ -29,8 +30,8 @@ export class PosGuard {
|
||||
id: posId,
|
||||
complex: {
|
||||
business_activity: {
|
||||
user: {
|
||||
accounts: {
|
||||
consumer: {
|
||||
consumer_accounts: {
|
||||
some: {
|
||||
id: tokenPayload.account_id,
|
||||
},
|
||||
@@ -68,31 +69,33 @@ export class PosGuard {
|
||||
|
||||
const accountPermissions = await this.prisma.permissionConsumer.findUnique({
|
||||
where: {
|
||||
account_id: tokenPayload.account_id,
|
||||
consumer_account_id: tokenPayload.account_id,
|
||||
},
|
||||
select: {
|
||||
posPermissions: true,
|
||||
businessPermissions: true,
|
||||
complexPermissions: true,
|
||||
pos_permissions: true,
|
||||
business_permissions: true,
|
||||
complex_permissions: true,
|
||||
},
|
||||
})
|
||||
|
||||
if (accountPermissions?.posPermissions.some(p => p.pos_id === posId)) {
|
||||
if (accountPermissions?.pos_permissions.some(p => p.pos_id === posId)) {
|
||||
return true
|
||||
}
|
||||
if (
|
||||
accountPermissions?.complexPermissions.some(p => p.complex_id === pos.complex.id)
|
||||
accountPermissions?.complex_permissions.some(p => p.complex_id === pos.complex.id)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
if (
|
||||
accountPermissions?.businessPermissions.some(
|
||||
accountPermissions?.business_permissions.some(
|
||||
p => p.business_id === pos.complex.business_activity_id,
|
||||
)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
throw new ForbiddenException('شما دسترسی لازم را ندارید.')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface IConsumerPayload {
|
||||
user_id: string
|
||||
id: string
|
||||
account_id: string
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ export interface AccessTokenPayload {
|
||||
type: AccountType
|
||||
username: string
|
||||
user?: AccessTokenUser
|
||||
role?: string
|
||||
// license_id?: string
|
||||
// license_expired_at?: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user