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:
@@ -0,0 +1,114 @@
|
||||
import { GoodSelect } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { CreateGoodDto, UpdateGoodDto } from './dto/good.dto'
|
||||
|
||||
@Injectable()
|
||||
export class ConsumerBusinessActivityGoodsService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
defaultSelect: GoodSelect = {
|
||||
id: true,
|
||||
name: true,
|
||||
barcode: true,
|
||||
sku: true,
|
||||
local_sku: true,
|
||||
pricing_model: true,
|
||||
unit_type: true,
|
||||
image_url: true,
|
||||
category: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
created_at: true,
|
||||
}
|
||||
|
||||
async findAll(consumer_id: string, business_activity_id: string) {
|
||||
const goods = await this.prisma.good.findMany({
|
||||
where: {
|
||||
business_activity: {
|
||||
id: business_activity_id,
|
||||
consumer_id,
|
||||
},
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
|
||||
return ResponseMapper.list(goods)
|
||||
}
|
||||
|
||||
async findOne(consumer_id: string, business_activity_id: string, id: string) {
|
||||
const good = await this.prisma.good.findUnique({
|
||||
where: {
|
||||
business_activity: {
|
||||
id: business_activity_id,
|
||||
consumer_id,
|
||||
},
|
||||
id,
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.single(good)
|
||||
}
|
||||
|
||||
async create(business_activity_id: string, data: CreateGoodDto) {
|
||||
const { category_id, ...rest } = data
|
||||
|
||||
const good = await this.prisma.good.create({
|
||||
data: {
|
||||
...rest,
|
||||
business_activity: {
|
||||
connect: {
|
||||
id: business_activity_id,
|
||||
},
|
||||
},
|
||||
category: {
|
||||
connect: {
|
||||
id: category_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
return ResponseMapper.create(good)
|
||||
}
|
||||
|
||||
async update(
|
||||
consumer_id: string,
|
||||
business_activity_id: string,
|
||||
id: string,
|
||||
data: UpdateGoodDto,
|
||||
) {
|
||||
const { category_id, ...rest } = data
|
||||
const good = await this.prisma.good.update({
|
||||
where: {
|
||||
business_activity: {
|
||||
id: business_activity_id,
|
||||
consumer_id,
|
||||
},
|
||||
id,
|
||||
},
|
||||
data: {
|
||||
business_activity: {
|
||||
connect: {
|
||||
id: business_activity_id,
|
||||
},
|
||||
},
|
||||
category: {
|
||||
connect: {
|
||||
id: category_id,
|
||||
},
|
||||
},
|
||||
...rest,
|
||||
},
|
||||
})
|
||||
return ResponseMapper.update(good)
|
||||
}
|
||||
|
||||
// async delete(id: string) {
|
||||
// await this.prisma.complex.delete({ where: { id } })
|
||||
// return ResponseMapper.delete()
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user