Refactor Partner and POS models to replace 'serial' with 'serial_number' and update related services and DTOs

- Updated PartnerAccountQuotaAllocation model to change license relation.
- Refactored Pos model to replace 'serial' with 'serial_number' across all references.
- Modified BusinessActivitiesService to include license activation details in responses.
- Adjusted ComplexPosesService to reflect changes in the Pos model.
- Updated PartnerService to include a new method for updating partner profiles.
- Created UpdatePartnerProfileDto for partner profile updates.
- Added migration to drop 'serial' column and add unique 'serial_number' column in poses table.
This commit is contained in:
2026-04-24 02:20:15 +03:30
parent a350ec7990
commit 11488093a7
26 changed files with 285 additions and 173 deletions
@@ -20,6 +20,37 @@ export class BusinessActivitiesService {
name: true,
},
},
license_activation: {
select: {
id: true,
starts_at: true,
expires_at: true,
license: {
select: {
accounts_limit: true,
_count: {
select: {
account_allocations: true,
},
},
},
},
},
},
}
private readonly prepareBusinessActivityResponse = (businessActivity: any) => {
const { license_activation, ...rest } = businessActivity
const { license, ...license_activation_rest } = license_activation
const { accounts_limit, _count } = license
return {
...rest,
license_info: {
...license_activation_rest,
accounts_limit: accounts_limit + _count.account_allocations,
},
}
}
async findAll(partner_id: string, consumer_id: string) {
@@ -32,7 +63,9 @@ export class BusinessActivitiesService {
},
select: this.defaultSelect,
})
return ResponseMapper.list(businessActivities)
return ResponseMapper.list(
businessActivities.map(this.prepareBusinessActivityResponse),
)
}
async findOne(partner_id: string, consumer_id: string, id: string) {
@@ -46,7 +79,7 @@ export class BusinessActivitiesService {
},
select: this.defaultSelect,
})
return ResponseMapper.single(businessActivity)
return ResponseMapper.single(this.prepareBusinessActivityResponse(businessActivity))
}
async create(consumer_id: string, data: CreateBusinessActivitiesDto) {
@@ -7,10 +7,6 @@ export class CreatePosDto {
@ApiProperty({})
name: string
@IsString()
@ApiProperty({})
serial: string
// @IsString()
// @IsOptional()
// @ApiProperty({ required: false })
@@ -25,6 +21,11 @@ export class CreatePosDto {
@ApiProperty({})
device_id: string
@IsString()
@IsOptional()
@ApiProperty({})
serial: string
@IsString()
@IsOptional()
@ApiProperty()
@@ -5,7 +5,7 @@ import { CreatePosDto, UpdatePosDto } from './dto/pos.dto'
import { ComplexPosesService } from './poses.service'
@ApiTags('AdminComplexPoses')
@Controller('admin/business_activities/:businessActivityId/complexes/:complexId/poses')
@Controller('partner/business_activities/:businessActivityId/complexes/:complexId/poses')
export class ComplexPosesController {
constructor(private readonly service: ComplexPosesService) {}
@@ -13,7 +13,7 @@ export class ComplexPosesService {
id: true,
name: true,
model: true,
serial: true,
serial_number: true,
status: true,
created_at: true,
pos_type: true,
+12
View File
@@ -0,0 +1,12 @@
import { ApiProperty } from '@nestjs/swagger'
import { IsString } from 'class-validator'
export class UpdatePartnerProfileDto {
@IsString()
@ApiProperty({ required: true })
name: string
@IsString()
@ApiProperty({ required: true })
code: string
}
+10 -4
View File
@@ -1,6 +1,7 @@
import { ConsumerInfo } from '@/common/decorators/consumerInfo.decorator'
import { Controller, Get } from '@nestjs/common'
import { PartnerInfo } from '@/common/decorators/partnerInfo.decorator'
import { Controller, Get, Patch } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { UpdatePartnerProfileDto } from './dto/partner.dto'
import { PartnerService } from './partners.service'
@ApiTags('Partner')
@@ -9,7 +10,12 @@ export class PartnerController {
constructor(private service: PartnerService) {}
@Get('')
async findOne(@ConsumerInfo('id') consumerId: string) {
return this.service.getInfo(consumerId)
async findOne(@PartnerInfo('id') partnerId: string) {
return this.service.getInfo(partnerId)
}
@Patch('profile')
async update(@PartnerInfo('id') partnerId: string, data: UpdatePartnerProfileDto) {
return this.service.updateInfo(partnerId, data)
}
}
+34 -18
View File
@@ -1,36 +1,52 @@
import { ResponseMapper } from '@/common/response/response-mapper'
import { PartnerSelect } from '@/generated/prisma/models'
import { PrismaService } from '@/prisma/prisma.service'
import { Injectable } from '@nestjs/common'
import { UpdatePartnerProfileDto } from './dto/partner.dto'
@Injectable()
export class PartnerService {
constructor(private readonly prisma: PrismaService) {}
private readonly defaultSelect: PartnerSelect = {
id: true,
name: true,
status: true,
account_quota_charge_transactions: {
select: {
_count: {
select: {
allocations: {
where: {
license_id: undefined,
},
},
},
},
},
},
}
async getInfo(partner_id: string) {
const partner = await this.prisma.partner.findUniqueOrThrow({
where: {
id: partner_id,
},
select: {
id: true,
name: true,
status: true,
account_quota_charge_transactions: {
select: {
_count: {
select: {
allocations: {
where: {
license_id: undefined,
},
},
},
},
},
},
},
select: this.defaultSelect,
})
return ResponseMapper.single(partner)
}
async updateInfo(partner_id: string, data: UpdatePartnerProfileDto) {
const updatedPartner = await this.prisma.partner.update({
where: {
id: partner_id,
},
data,
select: this.defaultSelect,
})
return ResponseMapper.single(updatedPartner)
}
}