Platform Marketing Content: - Add PaginationParams, PaginationMeta, PaginatedResponse interfaces - Fix JwtAuthGuard import paths (common/guards instead of modules/auth) - Add missing fields to CRM interfaces (address, keywords, features, benefits) - Install @nestjs/throttler dependency ERP Suite - Construccion: - Create tsconfig.node.json for web frontend - Add vite-env.d.ts for Vite types - Fix implicit return errors in Express controllers - Prefix unused parameters with underscore ERP Suite - ERP Core: - Export PoolClient type from database config - Fix invoice type comparison (customer/supplier vs out_invoice) - Refactor base.service.ts query handling for proper type inference - Rename Role type to RoleType to avoid conflict with entity - Fix ProtectedRoute to use role?.name instead of roles array ERP Suite - POS Micro: - Add vite-env.d.ts for Vite types - Fix Sale property names (discountAmount, changeAmount) - Export TodaySummary interface from sales service All projects now pass npm install and npm run build successfully. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
/**
|
|
* Custom Validation Pipe
|
|
*
|
|
* Enhanced validation pipe with custom error messages.
|
|
*/
|
|
|
|
import { PipeTransform, Injectable, BadRequestException } from '@nestjs/common';
|
|
import { validate, ValidationError } from 'class-validator';
|
|
import { plainToInstance } from 'class-transformer';
|
|
|
|
@Injectable()
|
|
export class CustomValidationPipe implements PipeTransform<any> {
|
|
async transform(value: any, { metatype }: any) {
|
|
if (!metatype || !this.toValidate(metatype)) {
|
|
return value;
|
|
}
|
|
|
|
const object = plainToInstance(metatype, value);
|
|
const errors = await validate(object);
|
|
|
|
if (errors.length > 0) {
|
|
throw new BadRequestException({
|
|
message: 'Validation failed',
|
|
errors: this.formatErrors(errors),
|
|
});
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
private toValidate(metatype: Function): boolean {
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
const types: Function[] = [String, Boolean, Number, Array, Object];
|
|
return !types.includes(metatype);
|
|
}
|
|
|
|
private formatErrors(errors: ValidationError[]) {
|
|
return errors.map((error) => ({
|
|
field: error.property,
|
|
constraints: error.constraints,
|
|
}));
|
|
}
|
|
}
|