2026-05-10 14:14:01 +03:30
|
|
|
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) {
|
2026-06-11 16:13:17 +03:30
|
|
|
throw new BadRequestException('شما دسترسی لازم برای ارسال صورتحساب را ندارید.')
|
2026-05-10 14:14:01 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return consumer.consumer_id
|
|
|
|
|
}
|
|
|
|
|
}
|