ad470d2166
- Implemented CreateStockKeepingUnitDto for creating stock keeping units. - Added StockKeepingUnitsService for handling business logic related to stock keeping units. - Created StockKeepingUnitsController to manage HTTP requests for stock keeping units. - Developed UpdateStockKeepingUnitDto for updating existing stock keeping units. - Introduced StockKeepingUnitsServiceFindAllResponseDto for response structure. - Established stock keeping units module for encapsulation of related components. feat: enhance sales invoice fiscal management with new endpoints - Created SalesInvoicesFilterDto for filtering sales invoices. - Implemented PosSalesInvoiceFiscalController for managing fiscal operations on sales invoices. - Developed PosSalesInvoiceFiscalService to handle fiscal logic and interactions. - Added methods for sending, retrying, and checking the status of fiscal invoices. - Integrated error handling and response mapping for fiscal operations.
145 lines
3.1 KiB
TypeScript
145 lines
3.1 KiB
TypeScript
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,
|
|
local_sku: true,
|
|
pricing_model: true,
|
|
image_url: true,
|
|
sku: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
},
|
|
},
|
|
measure_unit: {
|
|
select: {
|
|
id: true,
|
|
name: 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, sku_id, measure_unit_id, ...rest } = data
|
|
|
|
const good = await this.prisma.good.create({
|
|
data: {
|
|
...rest,
|
|
business_activity: {
|
|
connect: {
|
|
id: business_activity_id,
|
|
},
|
|
},
|
|
category: {
|
|
connect: {
|
|
id: category_id,
|
|
},
|
|
},
|
|
sku: {
|
|
connect: {
|
|
id: sku_id,
|
|
},
|
|
},
|
|
measure_unit: {
|
|
connect: {
|
|
id: measure_unit_id,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
return ResponseMapper.create(good)
|
|
}
|
|
|
|
async update(
|
|
consumer_id: string,
|
|
business_activity_id: string,
|
|
id: string,
|
|
data: UpdateGoodDto,
|
|
) {
|
|
const { category_id, sku_id, measure_unit_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,
|
|
},
|
|
},
|
|
sku: {
|
|
connect: {
|
|
id: sku_id,
|
|
},
|
|
},
|
|
measure_unit: {
|
|
connect: {
|
|
id: measure_unit_id,
|
|
},
|
|
},
|
|
...rest,
|
|
},
|
|
})
|
|
return ResponseMapper.update(good)
|
|
}
|
|
|
|
// async delete(id: string) {
|
|
// await this.prisma.complex.delete({ where: { id } })
|
|
// return ResponseMapper.delete()
|
|
// }
|
|
}
|