update
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { ConsumerRole } from '@/generated/prisma/enums'
|
||||
import { AccountInclude, AccountWhereUniqueInput } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable, NotFoundException } from '@nestjs/common'
|
||||
@@ -26,31 +27,32 @@ export class AuthService {
|
||||
|
||||
let accountInclude: AccountInclude = {}
|
||||
|
||||
// console.error('isPos', isPos)
|
||||
console.error('isPos', isPos)
|
||||
|
||||
// if (isPos) {
|
||||
// if (!device_info?.id) {
|
||||
// throw new NotFoundException('اطلاعات ورودی شما اشتباه است')
|
||||
// }
|
||||
// accountWhere = {
|
||||
// ...accountWhere,
|
||||
// consumer_account: {
|
||||
// pos: {
|
||||
// isNot: null,
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
if (isPos) {
|
||||
if (!device_info?.id) {
|
||||
throw new NotFoundException('اطلاعات ورودی شما اشتباه است')
|
||||
}
|
||||
accountWhere = {
|
||||
...accountWhere,
|
||||
consumer_account: {
|
||||
pos: {
|
||||
isNot: null,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// accountInclude = {
|
||||
// ...accountInclude,
|
||||
// consumer_account: {
|
||||
// select: {
|
||||
// id: true,
|
||||
// account_device: true,
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
accountInclude = {
|
||||
...accountInclude,
|
||||
consumer_account: {
|
||||
select: {
|
||||
id: true,
|
||||
account_device: true,
|
||||
role: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const account = await this.prisma.account.findUnique({
|
||||
where: accountWhere,
|
||||
@@ -62,42 +64,45 @@ export class AuthService {
|
||||
}
|
||||
await this.authUtils.checkAuthPassword(password, account.password)
|
||||
|
||||
// if (isPos) {
|
||||
// if (!account.consumer_account) {
|
||||
// throw new NotFoundException('اطلاعات ورودی شما اشتباه است')
|
||||
// }
|
||||
// const { account_device, id } = account.consumer_account as any
|
||||
if (isPos) {
|
||||
if (
|
||||
!account.consumer_account ||
|
||||
account.consumer_account.role !== ConsumerRole.OPERATOR
|
||||
) {
|
||||
throw new NotFoundException('اطلاعات ورودی شما اشتباه است')
|
||||
}
|
||||
// const { account_device, id } = account.consumer_account as any
|
||||
|
||||
// if (account_device?.device_id !== device_info!.id) {
|
||||
// throw new ForbiddenException(
|
||||
// 'کاربر شما با دستگاه دیگری اجازه ورود دارد. لطفا با پشتیبانی تماس بگیرید',
|
||||
// )
|
||||
// }
|
||||
// if (account_device?.device_id !== device_info!.id) {
|
||||
// throw new ForbiddenException(
|
||||
// 'کاربر شما با دستگاه دیگری اجازه ورود دارد. لطفا با پشتیبانی تماس بگیرید',
|
||||
// )
|
||||
// }
|
||||
|
||||
// const device = await this.prisma.consumerAccountDevice.findUnique({
|
||||
// where: {
|
||||
// device_id: device_info!.id!,
|
||||
// },
|
||||
// })
|
||||
// const device = await this.prisma.consumerAccountDevice.findUnique({
|
||||
// where: {
|
||||
// device_id: device_info!.id!,
|
||||
// },
|
||||
// })
|
||||
|
||||
// if (device) {
|
||||
// throw new ForbiddenException(
|
||||
// 'این دستگاه برای کاربر دیگری رجیستر شده است. لطفا با پشتیبانی تماس بگیرید.',
|
||||
// )
|
||||
// }
|
||||
// if (device) {
|
||||
// throw new ForbiddenException(
|
||||
// 'این دستگاه برای کاربر دیگری رجیستر شده است. لطفا با پشتیبانی تماس بگیرید.',
|
||||
// )
|
||||
// }
|
||||
|
||||
// await this.prisma.consumerAccountDevice.create({
|
||||
// data: {
|
||||
// device_id: device_info!.id!,
|
||||
// device_name: device_info!.name,
|
||||
// consumer_account: {
|
||||
// connect: {
|
||||
// id,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
// }
|
||||
// await this.prisma.consumerAccountDevice.create({
|
||||
// data: {
|
||||
// device_id: device_info!.id!,
|
||||
// device_name: device_info!.name,
|
||||
// consumer_account: {
|
||||
// connect: {
|
||||
// id,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
}
|
||||
|
||||
const preparedData = await this.authUtils.generateLoginResponse(account)
|
||||
return ResponseMapper.create(preparedData)
|
||||
|
||||
Reference in New Issue
Block a user