mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2025-12-31 10:02:42 +00:00
refactor to ddh, first commit
This commit is contained in:
140
old/modules/ad/domain/dtos/create-ad.request.ts
Normal file
140
old/modules/ad/domain/dtos/create-ad.request.ts
Normal file
@@ -0,0 +1,140 @@
|
||||
import { AutoMap } from '@automapper/classes';
|
||||
import {
|
||||
ArrayMinSize,
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
IsDate,
|
||||
IsEnum,
|
||||
IsMilitaryTime,
|
||||
IsNotEmpty,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsString,
|
||||
} from 'class-validator';
|
||||
import { Frequency } from '../types/frequency.enum';
|
||||
import { Coordinate } from '../../../geography/domain/entities/coordinate';
|
||||
import { Type } from 'class-transformer';
|
||||
import { HasTruthyWith } from './has-truthy-with.validator';
|
||||
|
||||
export class CreateAdRequest {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@AutoMap()
|
||||
uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@AutoMap()
|
||||
userUuid: string;
|
||||
|
||||
@HasTruthyWith('passenger', {
|
||||
message: 'A role (driver or passenger) must be set to true',
|
||||
})
|
||||
@IsBoolean()
|
||||
@AutoMap()
|
||||
driver: boolean;
|
||||
|
||||
@IsBoolean()
|
||||
@AutoMap()
|
||||
passenger: boolean;
|
||||
|
||||
@IsEnum(Frequency)
|
||||
@AutoMap()
|
||||
frequency: Frequency;
|
||||
|
||||
@Type(() => Date)
|
||||
@IsDate()
|
||||
@AutoMap()
|
||||
fromDate: Date;
|
||||
|
||||
@Type(() => Date)
|
||||
@IsDate()
|
||||
@AutoMap()
|
||||
toDate: Date;
|
||||
|
||||
@IsOptional()
|
||||
@IsMilitaryTime()
|
||||
@AutoMap()
|
||||
monTime?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsMilitaryTime()
|
||||
@AutoMap()
|
||||
tueTime?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsMilitaryTime()
|
||||
@AutoMap()
|
||||
wedTime?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsMilitaryTime()
|
||||
@AutoMap()
|
||||
thuTime?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsMilitaryTime()
|
||||
@AutoMap()
|
||||
friTime?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsMilitaryTime()
|
||||
@AutoMap()
|
||||
satTime?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsMilitaryTime()
|
||||
@AutoMap()
|
||||
sunTime?: string;
|
||||
|
||||
@IsNumber()
|
||||
@AutoMap()
|
||||
monMargin: number;
|
||||
|
||||
@IsNumber()
|
||||
@AutoMap()
|
||||
tueMargin: number;
|
||||
|
||||
@IsNumber()
|
||||
@AutoMap()
|
||||
wedMargin: number;
|
||||
|
||||
@IsNumber()
|
||||
@AutoMap()
|
||||
thuMargin: number;
|
||||
|
||||
@IsNumber()
|
||||
@AutoMap()
|
||||
friMargin: number;
|
||||
|
||||
@IsNumber()
|
||||
@AutoMap()
|
||||
satMargin: number;
|
||||
|
||||
@IsNumber()
|
||||
@AutoMap()
|
||||
sunMargin: number;
|
||||
|
||||
@Type(() => Coordinate)
|
||||
@IsArray()
|
||||
@ArrayMinSize(2)
|
||||
@AutoMap(() => [Coordinate])
|
||||
addresses: Coordinate[];
|
||||
|
||||
@IsNumber()
|
||||
@AutoMap()
|
||||
seatsDriver: number;
|
||||
|
||||
@IsNumber()
|
||||
@AutoMap()
|
||||
seatsPassenger: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@AutoMap()
|
||||
seatsUsed?: number;
|
||||
|
||||
@IsBoolean()
|
||||
@AutoMap()
|
||||
strict: boolean;
|
||||
}
|
||||
32
old/modules/ad/domain/dtos/has-truthy-with.validator.ts
Normal file
32
old/modules/ad/domain/dtos/has-truthy-with.validator.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import {
|
||||
registerDecorator,
|
||||
ValidationOptions,
|
||||
ValidationArguments,
|
||||
} from 'class-validator';
|
||||
|
||||
export function HasTruthyWith(
|
||||
property: string,
|
||||
validationOptions?: ValidationOptions,
|
||||
) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
return function (object: Object, propertyName: string) {
|
||||
registerDecorator({
|
||||
name: 'hasTruthyWith',
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
constraints: [property],
|
||||
options: validationOptions,
|
||||
validator: {
|
||||
validate(value: any, args: ValidationArguments) {
|
||||
const [relatedPropertyName] = args.constraints;
|
||||
const relatedValue = (args.object as any)[relatedPropertyName];
|
||||
return (
|
||||
typeof value === 'boolean' &&
|
||||
typeof relatedValue === 'boolean' &&
|
||||
(value || relatedValue)
|
||||
); // you can return a Promise<boolean> here as well, if you want to make async validation
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user