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