feat: Organization services
This commit is contained in:
@@ -24,7 +24,12 @@ export class HttpExceptionFilter implements ExceptionFilter<HttpException> {
|
||||
});
|
||||
}
|
||||
|
||||
if (status === 404) {
|
||||
exception.message = `${exception.message} not found`;
|
||||
}
|
||||
|
||||
response.status(status).json({
|
||||
success: false,
|
||||
message: exception.message,
|
||||
statusCode: status,
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { DataResponse, MessageResponse } from 'common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
|
||||
@Injectable()
|
||||
export class ResponseInterceptor<T> implements NestInterceptor<T, any> {
|
||||
|
||||
26
common/validators/at-least-one-field.ts
Normal file
26
common/validators/at-least-one-field.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import {
|
||||
registerDecorator,
|
||||
ValidationArguments,
|
||||
ValidationOptions,
|
||||
} from 'class-validator';
|
||||
|
||||
export function AtLeastOneField(validationOptions?: ValidationOptions) {
|
||||
return function (constructor: Function) {
|
||||
registerDecorator({
|
||||
name: 'atLeastOneField',
|
||||
target: constructor,
|
||||
propertyName: undefined as any, // important for class-level
|
||||
options: validationOptions,
|
||||
validator: {
|
||||
validate(_: any, args: ValidationArguments) {
|
||||
const object = args.object as Record<string, any>;
|
||||
|
||||
return Object.values(object).some((value) => value !== undefined);
|
||||
},
|
||||
defaultMessage() {
|
||||
return 'At least one field must be provided';
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
1
common/validators/index.ts
Normal file
1
common/validators/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './at-least-one-field';
|
||||
6
common/validators/query-uuid.dto.ts
Normal file
6
common/validators/query-uuid.dto.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { IsUUID } from 'class-validator';
|
||||
|
||||
export class UUIDQueryDTO {
|
||||
@IsUUID()
|
||||
id: string;
|
||||
}
|
||||
Reference in New Issue
Block a user