feat: add response DTOs for various services across modules
- Created response DTOs for ConfigService, AppService, AuthService, CatalogsService, AccountsService, BusinessActivityComplexesService, ComplexPosesService, SalesInvoicesService, BusinessActivitiesService, ConsumerBusinessActivityGoodsService, and others. - Implemented Create, FindAll, FindOne, and Update response types for services in consumer, partners, and POS modules. - Added request DTOs for creating and updating goods in the consumer business activities module. - Introduced filtering DTO for partner licenses. - Enhanced response mapping for partner license activations.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { PartnerActivatedLicensesService } from './activatedLicenses.service'
|
||||
import type { PartnerActivatedLicensesServiceFindAllResponseDto } from './dto/activatedLicenses-response.dto'
|
||||
|
||||
@ApiTags('AdminPartnerActivatedLicenses')
|
||||
@Controller('admin/partners/:partnerId/activated-licenses')
|
||||
@@ -8,7 +9,7 @@ export class PartnerLicensesController {
|
||||
constructor(private readonly service: PartnerActivatedLicensesService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(@Param('partnerId') partnerId: string) {
|
||||
async findAll(@Param('partnerId') partnerId: string): Promise<PartnerActivatedLicensesServiceFindAllResponseDto> {
|
||||
return this.service.findAll(partnerId)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
||||
import consumer_mappersUtil from '@/common/utils/mappers/consumer_mappers.util'
|
||||
import { LicenseActivationWhereInput } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
@@ -15,7 +17,7 @@ export class PartnerActivatedLicensesService {
|
||||
},
|
||||
},
|
||||
}
|
||||
const [licenses, total] = await this.prisma.$transaction(async tx => [
|
||||
const [activatedLicense, total] = await this.prisma.$transaction(async tx => [
|
||||
await tx.licenseActivation.findMany({
|
||||
where: defaultWhere,
|
||||
skip: (page - 1) * perPage,
|
||||
@@ -38,8 +40,7 @@ export class PartnerActivatedLicensesService {
|
||||
consumer: {
|
||||
select: {
|
||||
id: true,
|
||||
first_name: true,
|
||||
last_name: true,
|
||||
...QUERY_CONSTANTS.CONSUMER.infoSelect,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -51,8 +52,11 @@ export class PartnerActivatedLicensesService {
|
||||
}),
|
||||
])
|
||||
|
||||
const mappedLicenses = licenses.map(license => {
|
||||
const mappedLicenses = activatedLicense.map(license => {
|
||||
const { account_allocations, business_activity, ...rest } = license
|
||||
const { consumer, ...businessActivityRest } = business_activity
|
||||
|
||||
const mappedConsumer = consumer_mappersUtil(consumer)
|
||||
|
||||
return {
|
||||
...rest,
|
||||
@@ -64,7 +68,7 @@ export class PartnerActivatedLicensesService {
|
||||
},
|
||||
business_activity: {
|
||||
...business_activity,
|
||||
consumer_name: `${business_activity.consumer.first_name} ${business_activity.consumer.last_name}`,
|
||||
consumer_name: mappedConsumer.name,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { PartnerActivatedLicensesService } from '../activatedLicenses.service'
|
||||
|
||||
export type PartnerActivatedLicensesServiceDeleteResponseDto = Awaited<ReturnType<PartnerActivatedLicensesService['delete']>>
|
||||
export type PartnerActivatedLicensesServiceFindAllResponseDto = Awaited<ReturnType<PartnerActivatedLicensesService['findAll']>>
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { PartnerAllocatedAccountsService } from './allocatedAccounts.service'
|
||||
import type { PartnerAllocatedAccountsServiceFindAllResponseDto } from './dto/allocatedAccounts-response.dto'
|
||||
|
||||
@ApiTags('AdminPartnerAllocatedAccounts')
|
||||
@Controller('admin/partners/:partnerId/allocated-accounts')
|
||||
@@ -8,7 +9,7 @@ export class PartnerAllocatedAccountsController {
|
||||
constructor(private readonly service: PartnerAllocatedAccountsService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(@Param('partnerId') partnerId: string) {
|
||||
async findAll(@Param('partnerId') partnerId: string): Promise<PartnerAllocatedAccountsServiceFindAllResponseDto> {
|
||||
return this.service.findAll(partnerId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
import type { PartnerAllocatedAccountsService } from '../allocatedAccounts.service'
|
||||
|
||||
export type PartnerAllocatedAccountsServiceFindAllResponseDto = Awaited<ReturnType<PartnerAllocatedAccountsService['findAll']>>
|
||||
+4
-3
@@ -2,6 +2,7 @@ import { Body, Controller, Get, Param, Post } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { PartnerAccountChargeTransactionService } from './chargeAccountQuotaTransactions.service'
|
||||
import { ChargeAccountQuotaDto } from './dto/chargeAccountQuotaTransactions.dto'
|
||||
import type { PartnerAccountChargeTransactionServiceCreateResponseDto, PartnerAccountChargeTransactionServiceFindAllResponseDto, PartnerAccountChargeTransactionServiceFindOneResponseDto } from './dto/chargeAccountQuotaTransactions-response.dto'
|
||||
|
||||
@ApiTags('Admin Partner Account Charge')
|
||||
@Controller('admin/partners/:partnerId/charge-account-transactions')
|
||||
@@ -9,12 +10,12 @@ export class PartnerAccountChargeTransactionController {
|
||||
constructor(private readonly service: PartnerAccountChargeTransactionService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(@Param('partnerId') partnerId: string) {
|
||||
async findAll(@Param('partnerId') partnerId: string): Promise<PartnerAccountChargeTransactionServiceFindAllResponseDto> {
|
||||
return this.service.findAll(partnerId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(@Param('partnerId') partnerId: string, @Param('id') id: string) {
|
||||
async findOne(@Param('partnerId') partnerId: string, @Param('id') id: string): Promise<PartnerAccountChargeTransactionServiceFindOneResponseDto> {
|
||||
return this.service.findOne(partnerId, id)
|
||||
}
|
||||
|
||||
@@ -22,7 +23,7 @@ export class PartnerAccountChargeTransactionController {
|
||||
async create(
|
||||
@Param('partnerId') partnerId: string,
|
||||
@Body() data: ChargeAccountQuotaDto,
|
||||
) {
|
||||
): Promise<PartnerAccountChargeTransactionServiceCreateResponseDto> {
|
||||
return this.service.create(partnerId, data)
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type { PartnerAccountChargeTransactionService } from '../chargeAccountQuotaTransactions.service'
|
||||
|
||||
export type PartnerAccountChargeTransactionServiceCreateResponseDto = Awaited<ReturnType<PartnerAccountChargeTransactionService['create']>>
|
||||
export type PartnerAccountChargeTransactionServiceFindAllResponseDto = Awaited<ReturnType<PartnerAccountChargeTransactionService['findAll']>>
|
||||
export type PartnerAccountChargeTransactionServiceFindOneResponseDto = Awaited<ReturnType<PartnerAccountChargeTransactionService['findOne']>>
|
||||
+4
-3
@@ -2,6 +2,7 @@ import { Body, Controller, Get, Param, Post } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { PartnerLicenseChargeTransactionService } from './chargedLicenseTransactions.service'
|
||||
import { ChargeLicenseDto } from './dto/chargedLicenseTransactions.dto'
|
||||
import type { PartnerLicenseChargeTransactionServiceCreateResponseDto, PartnerLicenseChargeTransactionServiceFindAllResponseDto, PartnerLicenseChargeTransactionServiceFindOneResponseDto } from './dto/chargedLicenseTransactions-response.dto'
|
||||
|
||||
@ApiTags('AdminPartnerLicenseChargeTransaction')
|
||||
@Controller('admin/partners/:partnerId/charge-license-transactions')
|
||||
@@ -9,17 +10,17 @@ export class PartnerLicenseChargeTransactionController {
|
||||
constructor(private readonly service: PartnerLicenseChargeTransactionService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(@Param('partnerId') partnerId: string) {
|
||||
async findAll(@Param('partnerId') partnerId: string): Promise<PartnerLicenseChargeTransactionServiceFindAllResponseDto> {
|
||||
return this.service.findAll(partnerId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(@Param('partnerId') partnerId: string, @Param('id') id: string) {
|
||||
async findOne(@Param('partnerId') partnerId: string, @Param('id') id: string): Promise<PartnerLicenseChargeTransactionServiceFindOneResponseDto> {
|
||||
return this.service.findOne(partnerId, id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(@Param('partnerId') partnerId: string, @Body() data: ChargeLicenseDto) {
|
||||
async create(@Param('partnerId') partnerId: string, @Body() data: ChargeLicenseDto): Promise<PartnerLicenseChargeTransactionServiceCreateResponseDto> {
|
||||
return this.service.create(partnerId, data)
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type { PartnerLicenseChargeTransactionService } from '../chargedLicenseTransactions.service'
|
||||
|
||||
export type PartnerLicenseChargeTransactionServiceCreateResponseDto = Awaited<ReturnType<PartnerLicenseChargeTransactionService['create']>>
|
||||
export type PartnerLicenseChargeTransactionServiceFindAllResponseDto = Awaited<ReturnType<PartnerLicenseChargeTransactionService['findAll']>>
|
||||
export type PartnerLicenseChargeTransactionServiceFindOneResponseDto = Awaited<ReturnType<PartnerLicenseChargeTransactionService['findOne']>>
|
||||
@@ -23,6 +23,10 @@ export class CreatePartnerDto {
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
password: string
|
||||
|
||||
@IsOptional()
|
||||
@ApiProperty({ required: false, type: 'string', format: 'binary' })
|
||||
logo?: any
|
||||
}
|
||||
|
||||
export class UpdatePartnerDto extends PartialType(CreatePartnerDto) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { PartnersService } from '../partners.service'
|
||||
|
||||
export type PartnersServiceCreateResponseDto = Awaited<ReturnType<PartnersService['create']>>
|
||||
export type PartnersServiceDeleteResponseDto = Awaited<ReturnType<PartnersService['delete']>>
|
||||
export type PartnersServiceFindAllResponseDto = Awaited<ReturnType<PartnersService['findAll']>>
|
||||
export type PartnersServiceFindOneResponseDto = Awaited<ReturnType<PartnersService['findOne']>>
|
||||
export type PartnersServiceUpdateResponseDto = Awaited<ReturnType<PartnersService['update']>>
|
||||
@@ -1,18 +1,19 @@
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { AccountsService } from './accounts.service'
|
||||
import { CreatePartnerAccountDto, UpdateAccountDto } from './dto/account.dto'
|
||||
import type { AccountsServiceCreateResponseDto, AccountsServiceDeleteResponseDto, AccountsServiceFindAllResponseDto, AccountsServiceFindOneResponseDto, AccountsServiceUpdateResponseDto } from './dto/accounts-response.dto'
|
||||
|
||||
@Controller('admin/partners/:partnerId/accounts')
|
||||
export class AccountsController {
|
||||
constructor(private readonly accountsService: AccountsService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(@Param('partnerId') partnerId: string) {
|
||||
async findAll(@Param('partnerId') partnerId: string): Promise<AccountsServiceFindAllResponseDto> {
|
||||
return this.accountsService.findAll(partnerId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(@Param('id') id: string) {
|
||||
async findOne(@Param('id') id: string): Promise<AccountsServiceFindOneResponseDto> {
|
||||
return this.accountsService.findOne(id)
|
||||
}
|
||||
|
||||
@@ -20,17 +21,17 @@ export class AccountsController {
|
||||
async create(
|
||||
@Param('partnerId') partnerId: string,
|
||||
@Body() data: CreatePartnerAccountDto,
|
||||
) {
|
||||
): Promise<AccountsServiceCreateResponseDto> {
|
||||
return this.accountsService.create(partnerId, data)
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
async update(@Param('id') id: string, @Body() data: UpdateAccountDto) {
|
||||
async update(@Param('id') id: string, @Body() data: UpdateAccountDto): Promise<AccountsServiceUpdateResponseDto> {
|
||||
return this.accountsService.update(id, data)
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async delete(@Param('id') id: string) {
|
||||
async delete(@Param('id') id: string): Promise<AccountsServiceDeleteResponseDto> {
|
||||
return this.accountsService.delete(id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { AccountsService } from '../accounts.service'
|
||||
|
||||
export type AccountsServiceCreateResponseDto = Awaited<ReturnType<AccountsService['create']>>
|
||||
export type AccountsServiceDeleteResponseDto = Awaited<ReturnType<AccountsService['delete']>>
|
||||
export type AccountsServiceFindAllResponseDto = Awaited<ReturnType<AccountsService['findAll']>>
|
||||
export type AccountsServiceFindOneResponseDto = Awaited<ReturnType<AccountsService['findOne']>>
|
||||
export type AccountsServiceUpdateResponseDto = Awaited<ReturnType<AccountsService['update']>>
|
||||
@@ -1,4 +1,16 @@
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { multerImageOptions } from '@/multer.config'
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
UploadedFile,
|
||||
UseInterceptors,
|
||||
} from '@nestjs/common'
|
||||
import { FileInterceptor } from '@nestjs/platform-express'
|
||||
import { ApiBody, ApiConsumes } from '@nestjs/swagger'
|
||||
import { CreatePartnerDto, UpdatePartnerDto } from './dto/partner.dto'
|
||||
import { PartnersService } from './partners.service'
|
||||
|
||||
@@ -7,23 +19,47 @@ export class PartnersController {
|
||||
constructor(private readonly partnersService: PartnersService) {}
|
||||
|
||||
@Get()
|
||||
async findAll() {
|
||||
async findAll(): Promise<PartnersServiceFindAllResponseDto> {
|
||||
return this.partnersService.findAll()
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(@Param('id') id: string) {
|
||||
async findOne(@Param('id') id: string): Promise<PartnersServiceFindOneResponseDto> {
|
||||
return this.partnersService.findOne(id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(@Body() data: CreatePartnerDto) {
|
||||
return this.partnersService.create(data)
|
||||
@UseInterceptors(FileInterceptor('logo', multerImageOptions))
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@ApiBody({
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
logo: { type: 'string', format: 'binary' },
|
||||
},
|
||||
},
|
||||
})
|
||||
async create(@Body() data: CreatePartnerDto, @UploadedFile() logo: any): Promise<PartnersServiceCreateResponseDto> {
|
||||
return this.partnersService.create(data, logo)
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
async update(@Param('id') id: string, @Body() data: UpdatePartnerDto) {
|
||||
return this.partnersService.update(id, data)
|
||||
@UseInterceptors(FileInterceptor('logo', multerImageOptions))
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@ApiBody({
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
logo: { type: 'string', format: 'binary' },
|
||||
},
|
||||
},
|
||||
})
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@Body() data: UpdatePartnerDto,
|
||||
@UploadedFile() logo: Express.Multer.File,
|
||||
): Promise<PartnersServiceUpdateResponseDto> {
|
||||
return this.partnersService.update(id, data, logo)
|
||||
}
|
||||
|
||||
// @Delete(':id')
|
||||
@@ -31,3 +67,5 @@ export class PartnersController {
|
||||
// return this.partnersService.delete(id)
|
||||
// }
|
||||
}
|
||||
|
||||
import type { PartnersServiceCreateResponseDto, PartnersServiceFindAllResponseDto, PartnersServiceFindOneResponseDto, PartnersServiceUpdateResponseDto } from './dto/partners-response.dto'
|
||||
@@ -1,3 +1,4 @@
|
||||
import { UploaderModule } from '@/modules/uploader/uploader.module'
|
||||
import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
|
||||
@@ -11,6 +12,7 @@ import { PartnersService } from './partners.service'
|
||||
@Module({
|
||||
imports: [
|
||||
PrismaModule,
|
||||
UploaderModule,
|
||||
AdminPartnerLicenseChargeTransactionModule,
|
||||
AdminPartnerActivatedLicensesModule,
|
||||
// AdminPartnerAllocatedAccountsModule,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { UploadedFileTypes } from '@/common/enums/enums'
|
||||
import { PasswordUtil } from '@/common/utils/password.util'
|
||||
import {
|
||||
AccountStatus,
|
||||
@@ -6,6 +7,7 @@ import {
|
||||
PartnerStatus,
|
||||
} from '@/generated/prisma/enums'
|
||||
import { PartnerSelect } from '@/generated/prisma/models'
|
||||
import { UploaderService } from '@/modules/uploader/uploader.service'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
@@ -14,13 +16,17 @@ import { CreatePartnerDto, UpdatePartnerDto } from './dto/partner.dto'
|
||||
@Injectable()
|
||||
export class PartnersService {
|
||||
private now = new Date().getTime()
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly uploaderService: UploaderService,
|
||||
) {}
|
||||
|
||||
private readonly defaultSelect: PartnerSelect = {
|
||||
id: true,
|
||||
name: true,
|
||||
code: true,
|
||||
status: true,
|
||||
logo_url: true,
|
||||
created_at: true,
|
||||
license_charge_transactions: {
|
||||
select: {
|
||||
@@ -145,19 +151,26 @@ export class PartnersService {
|
||||
return ResponseMapper.single(this.mapPartner(partner))
|
||||
}
|
||||
|
||||
async create(data: CreatePartnerDto) {
|
||||
const { username, password, ...rest } = data
|
||||
async create(data: CreatePartnerDto, logo?: any) {
|
||||
const { username, password, ...rest } = data as any
|
||||
delete rest.logo
|
||||
|
||||
const logo_url = logo
|
||||
? await this.uploaderService.uploadFile(logo, UploadedFileTypes.PARTNER_LOGO)
|
||||
: undefined
|
||||
|
||||
const partner = await this.prisma.partner.create({
|
||||
data: {
|
||||
...rest,
|
||||
status: PartnerStatus.ACTIVE,
|
||||
partner_accounts: {
|
||||
...(logo_url ? { logo_url } : {}),
|
||||
accounts: {
|
||||
create: {
|
||||
role: PartnerRole.OWNER,
|
||||
account: {
|
||||
create: {
|
||||
username,
|
||||
password: await PasswordUtil.hash(data.password),
|
||||
password: await PasswordUtil.hash(password),
|
||||
status: AccountStatus.ACTIVE,
|
||||
type: AccountType.PARTNER,
|
||||
},
|
||||
@@ -170,12 +183,39 @@ export class PartnersService {
|
||||
return ResponseMapper.create(partner)
|
||||
}
|
||||
|
||||
async update(id: string, data: UpdatePartnerDto) {
|
||||
const partner = await this.prisma.partner.update({
|
||||
where: { id },
|
||||
data,
|
||||
select: this.defaultSelect,
|
||||
async update(id: string, data: UpdatePartnerDto, logo?: any) {
|
||||
const rest = { ...(data as any) }
|
||||
delete rest.logo
|
||||
|
||||
const partner = await this.prisma.$transaction(async tx => {
|
||||
let logo_url = ''
|
||||
if (logo) {
|
||||
const uploadedUrl = await this.uploaderService.uploadFile(
|
||||
logo,
|
||||
UploadedFileTypes.PARTNER_LOGO,
|
||||
)
|
||||
logo_url = uploadedUrl || ''
|
||||
}
|
||||
|
||||
const prevLogo = await tx.partner.findUnique({
|
||||
where: { id },
|
||||
select: { logo_url: true },
|
||||
})
|
||||
|
||||
if (logo_url && prevLogo?.logo_url) {
|
||||
this.uploaderService.deleteFile(prevLogo.logo_url, UploadedFileTypes.PARTNER_LOGO)
|
||||
}
|
||||
|
||||
return tx.partner.update({
|
||||
where: { id },
|
||||
data: {
|
||||
...rest,
|
||||
...(logo_url ? { logo_url } : {}),
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
})
|
||||
|
||||
return ResponseMapper.update(partner)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user