feat: update validation and exception handling, refactor controller routes, and enhance sales invoice item DTO
- Removed global validation pipe and added a new ValidationExceptionFilter for better error handling. - Refactored controller routes to use underscores instead of hyphens for consistency. - Updated CreateSalesInvoiceItemDto to include new fields: quantity, unit_type, and payload. - Modified CreateSalesInvoiceDto to enforce items as an array with a minimum size. - Added Enums module to provide gold karat values through a dedicated endpoint. - Introduced new columns in the database schema for sales invoice items and goods.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import { Controller, Get } from '@nestjs/common'
|
||||
import { EnumsService } from './enums.service'
|
||||
|
||||
@Controller('enums')
|
||||
export class EnumsController {
|
||||
constructor(private readonly enumsService: EnumsService) {}
|
||||
|
||||
@Get('gold_karat')
|
||||
async getGoldKarat() {
|
||||
return this.enumsService.getEnumValues('GoldKarat')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { EnumsController } from './enums.controller'
|
||||
import { EnumsService } from './enums.service'
|
||||
|
||||
@Module({
|
||||
controllers: [EnumsController],
|
||||
providers: [EnumsService],
|
||||
exports: [EnumsService],
|
||||
})
|
||||
export class EnumsModule {}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { GoldKarat } from '../../common/enums/enums'
|
||||
import { ResponseMapper } from '../../common/response/response-mapper'
|
||||
|
||||
@Injectable()
|
||||
export class EnumsService {
|
||||
getAllEnums() {
|
||||
return {
|
||||
GoldKarat: Object.values(GoldKarat).filter(value => typeof value === 'string'),
|
||||
}
|
||||
}
|
||||
|
||||
getEnumValues(enumName: string) {
|
||||
const enums = this.getAllEnums()
|
||||
return ResponseMapper.list(enums[enumName] || [])
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { reqTokenPayload } from '../auth/current-user.decorator'
|
||||
import { CreateGoodCategoryDto } from './dto/create-good-category.dto'
|
||||
import { GoodCategoriesService } from './good-categories.service'
|
||||
|
||||
@Controller('good-categories')
|
||||
@Controller('good_categories')
|
||||
export class GoodCategoriesController {
|
||||
constructor(private readonly goodCategoriesService: GoodCategoriesService) {}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ export class GoodCategoriesService {
|
||||
account_id: '',
|
||||
},
|
||||
})
|
||||
|
||||
return ResponseMapper.create(category)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ export class GoodsService {
|
||||
},
|
||||
},
|
||||
}
|
||||
console.log(dataToCreate)
|
||||
|
||||
const good = await this.prisma.good.create({
|
||||
data: dataToCreate,
|
||||
@@ -61,6 +62,8 @@ export class GoodsService {
|
||||
deleted_at: true,
|
||||
},
|
||||
})
|
||||
console.log(good)
|
||||
|
||||
return ResponseMapper.create(good)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||
import { IsNumber, IsOptional, IsString } from 'class-validator'
|
||||
import { IsEnum, IsNumber, IsObject, IsOptional, IsString } from 'class-validator'
|
||||
import type { SaleInvoicePayload } from '../../../common/interfaces/sale-invoice-payload'
|
||||
import { UnitType } from '../../../generated/prisma/enums'
|
||||
|
||||
export class CreateSalesInvoiceItemDto {
|
||||
@IsNumber()
|
||||
@ApiProperty()
|
||||
count: number
|
||||
|
||||
@IsNumber()
|
||||
@ApiProperty()
|
||||
unit_price: number
|
||||
@@ -27,6 +25,19 @@ export class CreateSalesInvoiceItemDto {
|
||||
@IsString()
|
||||
@ApiProperty({ required: false })
|
||||
service_id?: string
|
||||
|
||||
@IsNumber()
|
||||
@ApiProperty({ required: true, default: 1 })
|
||||
quantity: number
|
||||
|
||||
@IsEnum(UnitType)
|
||||
@ApiProperty({ enum: Object.values(UnitType) })
|
||||
unit_type: UnitType
|
||||
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
@ApiProperty({ required: false, default: {} })
|
||||
payload?: SaleInvoicePayload
|
||||
}
|
||||
|
||||
export class UpdateSalesInvoiceItemDto extends PartialType(CreateSalesInvoiceItemDto) {}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common'
|
||||
import { SalesInvoiceItemsService } from './sales-invoice-items.service'
|
||||
|
||||
@Controller('sales-invoice-items')
|
||||
@Controller('sales_invoice_items')
|
||||
export class SalesInvoiceItemsController {
|
||||
constructor(private readonly salesInvoiceItemsService: SalesInvoiceItemsService) {}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||
import { IsNumber, IsOptional, IsString } from 'class-validator'
|
||||
import { ArrayMinSize, IsNumber, IsOptional, IsString } from 'class-validator'
|
||||
import { CreateSalesInvoiceItemDto } from '../../sales-invoice-items/dto/create-sales-invoice-item.dto'
|
||||
|
||||
export class CreateSalesInvoiceDto {
|
||||
@IsString()
|
||||
@@ -7,18 +8,17 @@ export class CreateSalesInvoiceDto {
|
||||
code: string
|
||||
|
||||
@IsNumber()
|
||||
@ApiProperty()
|
||||
@ApiProperty({ required: true, default: 0 })
|
||||
total_amount: number
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiProperty({ required: false })
|
||||
description?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiProperty({ required: false })
|
||||
customer_id?: string
|
||||
|
||||
@ApiProperty()
|
||||
@ArrayMinSize(1)
|
||||
items: CreateSalesInvoiceItemDto[]
|
||||
}
|
||||
|
||||
export class UpdateSalesInvoiceDto extends PartialType(CreateSalesInvoiceDto) {}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common'
|
||||
import { SalesInvoicesService } from './sales-invoices.service'
|
||||
|
||||
@Controller('sales-invoices')
|
||||
@Controller('sales_invoices')
|
||||
export class SalesInvoicesController {
|
||||
constructor(private readonly salesInvoicesService: SalesInvoicesService) {}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common'
|
||||
import { ServiceCategoriesService } from './service-categories.service'
|
||||
|
||||
@Controller('service-categories')
|
||||
@Controller('service_categories')
|
||||
export class ServiceCategoriesController {
|
||||
constructor(private readonly serviceCategoriesService: ServiceCategoriesService) {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user