Merge branch 'fixAdValidation' into 'main'
Fix ad validation See merge request v3/service/ad!36
This commit is contained in:
commit
61c1d6ffcb
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@mobicoop/ad",
|
||||
"version": "2.4.3",
|
||||
"version": "2.4.5",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@mobicoop/ad",
|
||||
"version": "2.4.3",
|
||||
"version": "2.4.5",
|
||||
"license": "AGPL",
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "^1.9.14",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@mobicoop/ad",
|
||||
"version": "2.4.3",
|
||||
"version": "2.4.5",
|
||||
"description": "Mobicoop V3 Ad",
|
||||
"author": "sbriat",
|
||||
"private": true,
|
||||
|
|
|
@ -43,7 +43,8 @@ export class AdMapper
|
|||
frequency: copy.frequency,
|
||||
fromDate: new Date(copy.fromDate),
|
||||
toDate: new Date(copy.toDate),
|
||||
schedule: {
|
||||
schedule: copy.schedule
|
||||
? {
|
||||
create: copy.schedule.map((scheduleItem: ScheduleItemProps) => ({
|
||||
uuid: v4(),
|
||||
day: scheduleItem.day as number,
|
||||
|
@ -58,11 +59,13 @@ export class AdMapper
|
|||
createdAt: now,
|
||||
updatedAt: now,
|
||||
})),
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
seatsProposed: copy.seatsProposed as number,
|
||||
seatsRequested: copy.seatsRequested as number,
|
||||
strict: copy.strict as boolean,
|
||||
waypoints: {
|
||||
waypoints: copy.waypoints
|
||||
? {
|
||||
create: copy.waypoints.map((waypoint: WaypointProps) => ({
|
||||
uuid: v4(),
|
||||
position: waypoint.position,
|
||||
|
@ -77,9 +80,8 @@ export class AdMapper
|
|||
createdAt: now,
|
||||
updatedAt: now,
|
||||
})),
|
||||
},
|
||||
createdAt: copy.createdAt,
|
||||
updatedAt: copy.updatedAt,
|
||||
}
|
||||
: undefined,
|
||||
};
|
||||
return record;
|
||||
};
|
||||
|
@ -97,7 +99,7 @@ export class AdMapper
|
|||
frequency: record.frequency as Frequency,
|
||||
fromDate: record.fromDate.toISOString().split('T')[0],
|
||||
toDate: record.toDate.toISOString().split('T')[0],
|
||||
schedule: record.schedule.map((scheduleItem: ScheduleItemModel) => ({
|
||||
schedule: record.schedule?.map((scheduleItem: ScheduleItemModel) => ({
|
||||
day: scheduleItem.day,
|
||||
time: `${scheduleItem.time
|
||||
.getUTCHours()
|
||||
|
@ -111,7 +113,7 @@ export class AdMapper
|
|||
seatsProposed: record.seatsProposed,
|
||||
seatsRequested: record.seatsRequested,
|
||||
strict: record.strict,
|
||||
waypoints: record.waypoints.map((waypoint: WaypointModel) => ({
|
||||
waypoints: record.waypoints?.map((waypoint: WaypointModel) => ({
|
||||
position: waypoint.position,
|
||||
address: {
|
||||
name: waypoint.name,
|
||||
|
|
|
@ -15,8 +15,8 @@ export class ValidateAdService implements ICommandHandler {
|
|||
|
||||
async execute(command: ValidateAdCommand): Promise<AggregateID> {
|
||||
const ad: AdEntity = await this.repository.findOneById(command.id, {
|
||||
waypoints: true,
|
||||
schedule: true,
|
||||
waypoints: false,
|
||||
schedule: false,
|
||||
});
|
||||
ad.valid();
|
||||
await this.repository.update(ad.id, ad);
|
||||
|
|
|
@ -24,22 +24,26 @@ export type AdBaseModel = {
|
|||
seatsProposed: number;
|
||||
seatsRequested: number;
|
||||
strict: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
};
|
||||
|
||||
export type AdReadModel = AdBaseModel & {
|
||||
waypoints: WaypointModel[];
|
||||
schedule: ScheduleItemModel[];
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
};
|
||||
|
||||
export type AdWriteModel = AdBaseModel & {
|
||||
waypoints: {
|
||||
create: WaypointModel[];
|
||||
};
|
||||
schedule: {
|
||||
schedule: ScheduleWriteModel | undefined;
|
||||
waypoints: WaypointWriteModel | undefined;
|
||||
};
|
||||
|
||||
export type ScheduleWriteModel = {
|
||||
create: ScheduleItemModel[];
|
||||
};
|
||||
};
|
||||
|
||||
export type WaypointWriteModel = {
|
||||
create: WaypointModel[];
|
||||
};
|
||||
|
||||
export type ScheduleItemModel = {
|
||||
|
|
|
@ -144,9 +144,9 @@ describe('Ad Mapper', () => {
|
|||
|
||||
it('should map domain entity to persistence data', async () => {
|
||||
const mapped: AdWriteModel = adMapper.toPersistence(adEntity);
|
||||
expect(mapped.waypoints.create[0].uuid.length).toBe(36);
|
||||
expect(mapped.waypoints.create[1].uuid.length).toBe(36);
|
||||
expect(mapped.schedule.create.length).toBe(1);
|
||||
expect(mapped.waypoints?.create[0].uuid.length).toBe(36);
|
||||
expect(mapped.waypoints?.create[1].uuid.length).toBe(36);
|
||||
expect(mapped.schedule?.create.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should map persisted data to domain entity', async () => {
|
||||
|
|
Loading…
Reference in New Issue