fix ad validation : remove schedule and waypoints duplication
This commit is contained in:
parent
2009355b18
commit
b039dbb3bd
|
@ -43,43 +43,45 @@ export class AdMapper
|
||||||
frequency: copy.frequency,
|
frequency: copy.frequency,
|
||||||
fromDate: new Date(copy.fromDate),
|
fromDate: new Date(copy.fromDate),
|
||||||
toDate: new Date(copy.toDate),
|
toDate: new Date(copy.toDate),
|
||||||
schedule: {
|
schedule: copy.schedule
|
||||||
create: copy.schedule.map((scheduleItem: ScheduleItemProps) => ({
|
? {
|
||||||
uuid: v4(),
|
create: copy.schedule.map((scheduleItem: ScheduleItemProps) => ({
|
||||||
day: scheduleItem.day as number,
|
uuid: v4(),
|
||||||
time: new Date(
|
day: scheduleItem.day as number,
|
||||||
1970,
|
time: new Date(
|
||||||
0,
|
1970,
|
||||||
1,
|
0,
|
||||||
parseInt(scheduleItem.time.split(':')[0]),
|
1,
|
||||||
parseInt(scheduleItem.time.split(':')[1]),
|
parseInt(scheduleItem.time.split(':')[0]),
|
||||||
),
|
parseInt(scheduleItem.time.split(':')[1]),
|
||||||
margin: scheduleItem.margin as number,
|
),
|
||||||
createdAt: now,
|
margin: scheduleItem.margin as number,
|
||||||
updatedAt: now,
|
createdAt: now,
|
||||||
})),
|
updatedAt: now,
|
||||||
},
|
})),
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
seatsProposed: copy.seatsProposed as number,
|
seatsProposed: copy.seatsProposed as number,
|
||||||
seatsRequested: copy.seatsRequested as number,
|
seatsRequested: copy.seatsRequested as number,
|
||||||
strict: copy.strict as boolean,
|
strict: copy.strict as boolean,
|
||||||
waypoints: {
|
waypoints: copy.waypoints
|
||||||
create: copy.waypoints.map((waypoint: WaypointProps) => ({
|
? {
|
||||||
uuid: v4(),
|
create: copy.waypoints.map((waypoint: WaypointProps) => ({
|
||||||
position: waypoint.position,
|
uuid: v4(),
|
||||||
name: waypoint.address.name,
|
position: waypoint.position,
|
||||||
houseNumber: waypoint.address.houseNumber,
|
name: waypoint.address.name,
|
||||||
street: waypoint.address.street,
|
houseNumber: waypoint.address.houseNumber,
|
||||||
locality: waypoint.address.locality,
|
street: waypoint.address.street,
|
||||||
postalCode: waypoint.address.postalCode,
|
locality: waypoint.address.locality,
|
||||||
country: waypoint.address.country,
|
postalCode: waypoint.address.postalCode,
|
||||||
lon: waypoint.address.coordinates.lon,
|
country: waypoint.address.country,
|
||||||
lat: waypoint.address.coordinates.lat,
|
lon: waypoint.address.coordinates.lon,
|
||||||
createdAt: now,
|
lat: waypoint.address.coordinates.lat,
|
||||||
updatedAt: now,
|
createdAt: now,
|
||||||
})),
|
updatedAt: now,
|
||||||
},
|
})),
|
||||||
createdAt: copy.createdAt,
|
}
|
||||||
updatedAt: copy.updatedAt,
|
: undefined,
|
||||||
};
|
};
|
||||||
return record;
|
return record;
|
||||||
};
|
};
|
||||||
|
@ -97,7 +99,7 @@ export class AdMapper
|
||||||
frequency: record.frequency as Frequency,
|
frequency: record.frequency as Frequency,
|
||||||
fromDate: record.fromDate.toISOString().split('T')[0],
|
fromDate: record.fromDate.toISOString().split('T')[0],
|
||||||
toDate: record.toDate.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,
|
day: scheduleItem.day,
|
||||||
time: `${scheduleItem.time
|
time: `${scheduleItem.time
|
||||||
.getUTCHours()
|
.getUTCHours()
|
||||||
|
@ -111,7 +113,7 @@ export class AdMapper
|
||||||
seatsProposed: record.seatsProposed,
|
seatsProposed: record.seatsProposed,
|
||||||
seatsRequested: record.seatsRequested,
|
seatsRequested: record.seatsRequested,
|
||||||
strict: record.strict,
|
strict: record.strict,
|
||||||
waypoints: record.waypoints.map((waypoint: WaypointModel) => ({
|
waypoints: record.waypoints?.map((waypoint: WaypointModel) => ({
|
||||||
position: waypoint.position,
|
position: waypoint.position,
|
||||||
address: {
|
address: {
|
||||||
name: waypoint.name,
|
name: waypoint.name,
|
||||||
|
|
|
@ -24,22 +24,26 @@ export type AdBaseModel = {
|
||||||
seatsProposed: number;
|
seatsProposed: number;
|
||||||
seatsRequested: number;
|
seatsRequested: number;
|
||||||
strict: boolean;
|
strict: boolean;
|
||||||
createdAt: Date;
|
|
||||||
updatedAt: Date;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AdReadModel = AdBaseModel & {
|
export type AdReadModel = AdBaseModel & {
|
||||||
waypoints: WaypointModel[];
|
waypoints: WaypointModel[];
|
||||||
schedule: ScheduleItemModel[];
|
schedule: ScheduleItemModel[];
|
||||||
|
createdAt: Date;
|
||||||
|
updatedAt: Date;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AdWriteModel = AdBaseModel & {
|
export type AdWriteModel = AdBaseModel & {
|
||||||
waypoints: {
|
schedule: ScheduleWriteModel | undefined;
|
||||||
create: WaypointModel[];
|
waypoints: WaypointWriteModel | undefined;
|
||||||
};
|
};
|
||||||
schedule: {
|
|
||||||
create: ScheduleItemModel[];
|
export type ScheduleWriteModel = {
|
||||||
};
|
create: ScheduleItemModel[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WaypointWriteModel = {
|
||||||
|
create: WaypointModel[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ScheduleItemModel = {
|
export type ScheduleItemModel = {
|
||||||
|
|
|
@ -144,9 +144,9 @@ describe('Ad Mapper', () => {
|
||||||
|
|
||||||
it('should map domain entity to persistence data', async () => {
|
it('should map domain entity to persistence data', async () => {
|
||||||
const mapped: AdWriteModel = adMapper.toPersistence(adEntity);
|
const mapped: AdWriteModel = adMapper.toPersistence(adEntity);
|
||||||
expect(mapped.waypoints.create[0].uuid.length).toBe(36);
|
expect(mapped.waypoints?.create[0].uuid.length).toBe(36);
|
||||||
expect(mapped.waypoints.create[1].uuid.length).toBe(36);
|
expect(mapped.waypoints?.create[1].uuid.length).toBe(36);
|
||||||
expect(mapped.schedule.create.length).toBe(1);
|
expect(mapped.schedule?.create.length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should map persisted data to domain entity', async () => {
|
it('should map persisted data to domain entity', async () => {
|
||||||
|
|
Loading…
Reference in New Issue