feat: implement purchase receipt items management with create, update, find, and delete functionalities
feat: add purchase receipts management with create, update, find, and delete functionalities feat: implement sales invoice items management with create, update, find, and delete functionalities feat: add sales invoices management with create, update, find, and delete functionalities feat: implement stock adjustments management with create, update, find, and delete functionalities feat: add stock balance retrieval functionality feat: implement stock movements management with create, update, find, and delete functionalities
This commit is contained in:
@@ -9,7 +9,6 @@ export class ProductsController {
|
||||
|
||||
@Post()
|
||||
create(@Body() dto: CreateProductDto) {
|
||||
console.log('[ProductController] create called', dto)
|
||||
return this.productsService.create(dto)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ShortEntity } from '../common/interfaces/response-models'
|
||||
import { ResponseMapper } from '../common/response/response-mapper'
|
||||
import { PrismaService } from '../prisma/prisma.service'
|
||||
import { CreateProductDto } from './dto/create-product.dto'
|
||||
@@ -8,12 +9,7 @@ export class ProductsService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async create(data: CreateProductDto) {
|
||||
console.log(data)
|
||||
|
||||
// Transform incoming DTO so relation ids are passed as `connect` objects
|
||||
const payload: any = { ...data }
|
||||
// If the client supplied brandId/categoryId (even null), remove the scalar
|
||||
// Prisma expects nested relation objects, so only add `connect` when an id is present.
|
||||
if (Object.prototype.hasOwnProperty.call(payload, 'brandId')) {
|
||||
if (payload.brandId !== undefined && payload.brandId !== null) {
|
||||
payload.brand = { connect: { id: Number(payload.brandId) } }
|
||||
@@ -38,7 +34,13 @@ export class ProductsService {
|
||||
})
|
||||
const mapped = items.map(p => {
|
||||
const { brandId, categoryId, ...rest } = p as any
|
||||
return { ...rest, brand: p.brand, category: p.category }
|
||||
const brand: ShortEntity | null = p.brand
|
||||
? { id: p.brand.id, name: p.brand.name }
|
||||
: null
|
||||
const category: ShortEntity | null = p.category
|
||||
? { id: p.category.id, name: p.category.name }
|
||||
: null
|
||||
return { ...rest, brand, category }
|
||||
})
|
||||
return ResponseMapper.list(mapped)
|
||||
}
|
||||
@@ -46,14 +48,23 @@ export class ProductsService {
|
||||
async findOne(id: number) {
|
||||
const p = await this.prisma.product.findUnique({
|
||||
where: { id },
|
||||
include: { brand: true, category: true },
|
||||
include: { brand: true, category: true, productCharges: true },
|
||||
})
|
||||
if (!p) return null
|
||||
|
||||
console.log('first')
|
||||
|
||||
const { brandId, categoryId, ...rest } = p as any
|
||||
return ResponseMapper.single({ ...rest, brand: p.brand, category: p.category })
|
||||
const brand: ShortEntity | null = p.brand
|
||||
? { id: p.brand.id, name: p.brand.name }
|
||||
: null
|
||||
const category: ShortEntity | null = p.category
|
||||
? { id: p.category.id, name: p.category.name }
|
||||
: null
|
||||
return ResponseMapper.single({
|
||||
...rest,
|
||||
brand,
|
||||
category,
|
||||
count: p.productCharges.reduce((acc, charge) => acc + Number(charge.count), 0.0),
|
||||
})
|
||||
}
|
||||
|
||||
async update(id: number, data: any) {
|
||||
|
||||
Reference in New Issue
Block a user