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:
@@ -10,3 +10,9 @@ export enum AccountType {
|
||||
PROVIDER,
|
||||
POS,
|
||||
}
|
||||
|
||||
export enum GoldKarat {
|
||||
KARAT_18 = 18,
|
||||
KARAT_21 = 21,
|
||||
KARAT_24 = 24,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import {
|
||||
ArgumentsHost,
|
||||
BadRequestException,
|
||||
Catch,
|
||||
ExceptionFilter,
|
||||
} from '@nestjs/common'
|
||||
import { Response } from 'express'
|
||||
|
||||
@Catch(BadRequestException)
|
||||
export class ValidationExceptionFilter implements ExceptionFilter {
|
||||
constructor() {
|
||||
console.log('ValidationExceptionFilter initialized')
|
||||
}
|
||||
catch(exception: BadRequestException, host: ArgumentsHost) {
|
||||
const ctx = host.switchToHttp()
|
||||
const response = ctx.getResponse<Response>()
|
||||
const status = exception.getStatus()
|
||||
const exceptionResponse = exception.getResponse()
|
||||
console.log(exception)
|
||||
|
||||
response.status(status).json({
|
||||
statusCode: status,
|
||||
message: 'Validation failed',
|
||||
errors: (exceptionResponse as any).message || exceptionResponse,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,8 @@ import { map } from 'rxjs/operators'
|
||||
@Injectable()
|
||||
export class ResponseMappingInterceptor implements NestInterceptor {
|
||||
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
|
||||
console.log('first')
|
||||
|
||||
const http = context.switchToHttp()
|
||||
const response = http.getResponse()
|
||||
const request = http.getRequest()
|
||||
@@ -30,6 +32,7 @@ export class ResponseMappingInterceptor implements NestInterceptor {
|
||||
return next.handle().pipe(
|
||||
map(data => {
|
||||
const statusCode: number = (response as Response)?.statusCode ?? 200
|
||||
console.log(data)
|
||||
|
||||
if (data && typeof data === 'object') {
|
||||
if (Array.isArray((data as any).errors) && statusCode >= 400) {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { GoldKarat } from '../enums/enums'
|
||||
|
||||
export interface SaleInvoicePayload {
|
||||
weight: number
|
||||
karat: keyof typeof GoldKarat
|
||||
wages: number
|
||||
profit: number
|
||||
}
|
||||
@@ -20,6 +20,8 @@ export const ResponseMapper = {
|
||||
},
|
||||
|
||||
single<T>(item: T): MapperWrapper<T> {
|
||||
console.log('asdasdsaasdsa')
|
||||
|
||||
return { __mapped: 'single', data: item }
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user