update models and create consumer domain accounts permissions

This commit is contained in:
2026-04-11 14:47:05 +03:30
parent 89726c8904
commit 9cef733370
87 changed files with 2967 additions and 3352 deletions
@@ -11,30 +11,30 @@ export class consumerCustomersController {
constructor(private readonly service: consumerCustomersService) {}
@Get()
async findAll(@ConsumerInfo('user_id') userId: string) {
return this.service.findAll(userId)
async findAll(@ConsumerInfo('id') consumerId: string) {
return this.service.findAll(consumerId)
}
@Get(':id')
async findOne(@ConsumerInfo('user_id') userId: string, @Param('id') id: string) {
return this.service.findOne(userId, id)
async findOne(@ConsumerInfo('id') consumerId: string, @Param('id') id: string) {
return this.service.findOne(consumerId, id)
}
@Patch(':id/legal')
async updateLegal(
@ConsumerInfo('user_id') userId: string,
@ConsumerInfo('id') consumerId: string,
@Param('id') id: string,
@Body() data: UpdateCustomerLegalDto,
) {
return this.service.updateLegal(userId, id, data)
return this.service.updateLegal(consumerId, id, data)
}
@Patch(':id/individual')
async updateIndividual(
@ConsumerInfo('user_id') userId: string,
@ConsumerInfo('id') consumerId: string,
@Param('id') id: string,
@Body() data: UpdateCustomerIndividualDto,
) {
return this.service.updateIndividual(userId, id, data)
return this.service.updateIndividual(consumerId, id, data)
}
}
@@ -35,14 +35,14 @@ export class consumerCustomersService {
},
}
private defaultWhere(user_id: string): CustomerWhereInput {
private defaultWhere(consumer_id: string): CustomerWhereInput {
return {
OR: [
{
customer_individual: {
complex: {
business_activity: {
user_id,
consumer_id,
},
},
},
@@ -51,7 +51,7 @@ export class consumerCustomersService {
customer_legal: {
complex: {
business_activity: {
user_id,
consumer_id,
},
},
},
@@ -60,43 +60,45 @@ export class consumerCustomersService {
}
}
async findAll(user_id: string, page = 1, pageSize = 10) {
async findAll(consumer_id: string, page = 1, pageSize = 10) {
const [customers, count] = await this.prisma.$transaction(async tx => [
await tx.customer.findMany({
where: this.defaultWhere(user_id),
where: this.defaultWhere(consumer_id),
select: this.defaultSelect,
skip: (page - 1) * pageSize,
take: 10,
}),
await tx.customer.count({
where: this.defaultWhere(user_id),
where: this.defaultWhere(consumer_id),
}),
])
return ResponseMapper.paginate(customers, { count, page, pageSize })
}
async findOne(user_id: string, customer_id: string) {
async findOne(consumer_id: string, customer_id: string) {
const customer = await this.prisma.customer.findUniqueOrThrow({
where: {
...this.defaultWhere(user_id),
...this.defaultWhere(consumer_id),
id: customer_id,
},
select: this.defaultSelect,
})
console.log(customer)
return ResponseMapper.single(customer)
}
async updateLegal(user_id: string, customer_id: string, data: UpdateCustomerLegalDto) {
async updateLegal(
consumer_id: string,
customer_id: string,
data: UpdateCustomerLegalDto,
) {
const customer = await this.prisma.customer.update({
where: {
id: customer_id,
customer_legal: {
complex: {
business_activity: {
user_id,
consumer_id,
},
},
},
@@ -115,7 +117,7 @@ export class consumerCustomersService {
}
async updateIndividual(
user_id: string,
consumer_id: string,
customer_id: string,
data: UpdateCustomerIndividualDto,
) {
@@ -125,7 +127,7 @@ export class consumerCustomersService {
customer_individual: {
complex: {
business_activity: {
user_id,
consumer_id,
},
},
},
@@ -34,7 +34,7 @@ export class CustomerSaleInvoicesService {
account: {
select: {
role: true,
user: {
consumer: {
select: {
first_name: true,
last_name: true,
@@ -50,13 +50,13 @@ export class CustomerSaleInvoicesService {
created_at: true,
}
async findAll(user_id: string, customer_id: string, page = 1, pageSize = 10) {
async findAll(consumer_id: string, customer_id: string, page = 1, pageSize = 10) {
const salesWhere: SalesInvoiceWhereInput = {
customer_id,
pos: {
complex: {
business_activity: {
user_id,
consumer_id,
},
},
},
@@ -96,7 +96,7 @@ export class CustomerSaleInvoicesService {
})
}
async findOne(user_id: string, customer_id: string, id: string) {
async findOne(consumer_id: string, customer_id: string, id: string) {
const account = await this.prisma.salesInvoice.findUniqueOrThrow({
where: {
id,
@@ -104,7 +104,7 @@ export class CustomerSaleInvoicesService {
pos: {
complex: {
business_activity: {
user_id,
consumer_id,
},
},
},