Files
psp_api/src/common/services/saleInvoices/sale-invoice-access.service.ts
T

30 lines
840 B
TypeScript
Raw Normal View History

import { PrismaService } from '@/prisma/prisma.service'
import { BadRequestException, Injectable } from '@nestjs/common'
import { ConsumerRole } from 'generated/prisma/enums'
@Injectable()
export class SharedSaleInvoiceAccessService {
constructor(private readonly prisma: PrismaService) {}
async getConsumerIdWithPosAccess(
consumerAccountId: string,
posId: string,
): Promise<string> {
const consumer = await this.prisma.consumerAccount.findUnique({
where: {
id: consumerAccountId,
OR: [{ pos: { id: posId } }, { role: ConsumerRole.OWNER }],
},
select: {
consumer_id: true,
},
})
if (!consumer) {
throw new BadRequestException('شما دسترسی لازم برای ارسال فاکتور را ندارید.')
}
return consumer.consumer_id
}
}