Consistent and DRY declarations of ScheduleItem types
This commit is contained in:
parent
5e449ad69a
commit
c7d4792893
|
@ -1,19 +1,19 @@
|
|||
import { Mapper } from '@mobicoop/ddd-library';
|
||||
import { AdResponseDto } from './interface/dtos/ad.response.dto';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { AdEntity } from './core/domain/ad.entity';
|
||||
import {
|
||||
AdWriteModel,
|
||||
AdReadModel,
|
||||
WaypointModel,
|
||||
ScheduleItemModel,
|
||||
} from './infrastructure/ad.repository';
|
||||
import { Frequency, Status } from './core/domain/ad.types';
|
||||
import { WaypointProps } from './core/domain/value-objects/waypoint.value-object';
|
||||
import { v4 } from 'uuid';
|
||||
import { ScheduleItemProps } from './core/domain/value-objects/schedule-item.value-object';
|
||||
import { OUTPUT_DATETIME_TRANSFORMER } from './ad.di-tokens';
|
||||
import { DateTimeTransformerPort } from './core/application/ports/datetime-transformer.port';
|
||||
import { AdEntity } from './core/domain/ad.entity';
|
||||
import { Frequency, Status } from './core/domain/ad.types';
|
||||
import { ScheduleItemProps } from './core/domain/value-objects/schedule-item.value-object';
|
||||
import { WaypointProps } from './core/domain/value-objects/waypoint.value-object';
|
||||
import {
|
||||
AdReadModel,
|
||||
AdWriteModel,
|
||||
ScheduleItemModel,
|
||||
WaypointModel,
|
||||
} from './infrastructure/ad.repository';
|
||||
import { AdResponseDto } from './interface/dtos/ad.response.dto';
|
||||
|
||||
/**
|
||||
* Mapper constructs objects that are used in different layers:
|
||||
|
@ -47,7 +47,7 @@ export class AdMapper
|
|||
? {
|
||||
create: copy.schedule.map((scheduleItem: ScheduleItemProps) => ({
|
||||
uuid: v4(),
|
||||
day: scheduleItem.day as number,
|
||||
day: scheduleItem.day,
|
||||
time: new Date(
|
||||
1970,
|
||||
0,
|
||||
|
@ -55,7 +55,7 @@ export class AdMapper
|
|||
parseInt(scheduleItem.time.split(':')[0]),
|
||||
parseInt(scheduleItem.time.split(':')[1]),
|
||||
),
|
||||
margin: scheduleItem.margin as number,
|
||||
margin: scheduleItem.margin,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
})),
|
||||
|
@ -163,7 +163,7 @@ export class AdMapper
|
|||
response.schedule = props.schedule.map(
|
||||
(scheduleItem: ScheduleItemProps) => ({
|
||||
day: this.outputDatetimeTransformer.day(
|
||||
scheduleItem.day as number,
|
||||
scheduleItem.day,
|
||||
{
|
||||
date: props.fromDate,
|
||||
time: scheduleItem.time,
|
||||
|
@ -179,7 +179,7 @@ export class AdMapper
|
|||
},
|
||||
props.frequency,
|
||||
),
|
||||
margin: scheduleItem.margin as number,
|
||||
margin: scheduleItem.margin,
|
||||
}),
|
||||
);
|
||||
response.seatsProposed = props.seatsProposed as number;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { ScheduleItem } from '../../types/schedule-item';
|
||||
import { Waypoint } from '../../types/waypoint';
|
||||
import { Frequency } from '@modules/ad/core/domain/ad.types';
|
||||
import { Command, CommandProps } from '@mobicoop/ddd-library';
|
||||
import { Frequency } from '@modules/ad/core/domain/ad.types';
|
||||
import { ScheduleItemProps } from '@modules/ad/core/domain/value-objects/schedule-item.value-object';
|
||||
import { Waypoint } from '../../types/waypoint';
|
||||
|
||||
export class CreateAdCommand extends Command {
|
||||
readonly userId: string;
|
||||
|
@ -10,7 +10,7 @@ export class CreateAdCommand extends Command {
|
|||
readonly frequency: Frequency;
|
||||
readonly fromDate: string;
|
||||
readonly toDate: string;
|
||||
readonly schedule: ScheduleItem[];
|
||||
readonly schedule: ScheduleItemProps[];
|
||||
readonly seatsProposed?: number;
|
||||
readonly seatsRequested?: number;
|
||||
readonly strict: boolean;
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
||||
import { CreateAdCommand } from './create-ad.command';
|
||||
import { Inject } from '@nestjs/common';
|
||||
import { AggregateID, ConflictException } from '@mobicoop/ddd-library';
|
||||
import {
|
||||
AD_REPOSITORY,
|
||||
INPUT_DATETIME_TRANSFORMER,
|
||||
} from '@modules/ad/ad.di-tokens';
|
||||
import { AdEntity } from '@modules/ad/core/domain/ad.entity';
|
||||
import { Waypoint } from '../../types/waypoint';
|
||||
import { AdRepositoryPort } from '../../ports/ad.repository.port';
|
||||
import { AdAlreadyExistsException } from '@modules/ad/core/domain/ad.errors';
|
||||
import { AggregateID, ConflictException } from '@mobicoop/ddd-library';
|
||||
import { ScheduleItem } from '../../types/schedule-item';
|
||||
import { ScheduleItemProps } from '@modules/ad/core/domain/value-objects/schedule-item.value-object';
|
||||
import { Inject } from '@nestjs/common';
|
||||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
||||
import { AdRepositoryPort } from '../../ports/ad.repository.port';
|
||||
import { DateTimeTransformerPort } from '../../ports/datetime-transformer.port';
|
||||
import { Waypoint } from '../../types/waypoint';
|
||||
import { CreateAdCommand } from './create-ad.command';
|
||||
|
||||
@CommandHandler(CreateAdCommand)
|
||||
export class CreateAdService implements ICommandHandler {
|
||||
|
@ -51,7 +51,7 @@ export class CreateAdService implements ICommandHandler {
|
|||
},
|
||||
command.frequency,
|
||||
),
|
||||
schedule: command.schedule.map((scheduleItem: ScheduleItem) => ({
|
||||
schedule: command.schedule.map((scheduleItem: ScheduleItemProps) => ({
|
||||
day: this.datetimeTransformer.day(
|
||||
scheduleItem.day,
|
||||
{
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
export type ScheduleItem = {
|
||||
day: number;
|
||||
time: string;
|
||||
margin: number;
|
||||
};
|
|
@ -30,9 +30,9 @@ export class AdEntity extends AggregateRoot<AdProps> {
|
|||
fromDate: props.fromDate,
|
||||
toDate: props.toDate,
|
||||
schedule: props.schedule.map((day: ScheduleItemProps) => ({
|
||||
day: day.day as number,
|
||||
day: day.day,
|
||||
time: day.time,
|
||||
margin: day.margin as number,
|
||||
margin: day.margin,
|
||||
})),
|
||||
seatsProposed: props.seatsProposed,
|
||||
seatsRequested: props.seatsRequested,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { DomainEvent, DomainEventProps } from '@mobicoop/ddd-library';
|
||||
import { ScheduleItemProps } from '../value-objects/schedule-item.value-object';
|
||||
|
||||
export class AdCreatedDomainEvent extends DomainEvent {
|
||||
readonly userId: string;
|
||||
|
@ -7,7 +8,7 @@ export class AdCreatedDomainEvent extends DomainEvent {
|
|||
readonly frequency: string;
|
||||
readonly fromDate: string;
|
||||
readonly toDate: string;
|
||||
readonly schedule: ScheduleItem[];
|
||||
readonly schedule: ScheduleItemProps[];
|
||||
readonly seatsProposed: number;
|
||||
readonly seatsRequested: number;
|
||||
readonly strict: boolean;
|
||||
|
@ -31,12 +32,6 @@ export class AdCreatedDomainEvent extends DomainEvent {
|
|||
}
|
||||
}
|
||||
|
||||
export class ScheduleItem {
|
||||
day: number;
|
||||
time: string;
|
||||
margin: number;
|
||||
}
|
||||
|
||||
export class Waypoint {
|
||||
position: number;
|
||||
name?: string;
|
||||
|
|
|
@ -6,13 +6,13 @@ import { ValueObject } from '@mobicoop/ddd-library';
|
|||
* */
|
||||
|
||||
export interface ScheduleItemProps {
|
||||
day?: number;
|
||||
day: number;
|
||||
time: string;
|
||||
margin?: number;
|
||||
margin: number;
|
||||
}
|
||||
|
||||
export class ScheduleItem extends ValueObject<ScheduleItemProps> {
|
||||
get day(): number | undefined {
|
||||
get day(): number {
|
||||
return this.props.day;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ export class ScheduleItem extends ValueObject<ScheduleItemProps> {
|
|||
return this.props.time;
|
||||
}
|
||||
|
||||
get margin(): number | undefined {
|
||||
get margin(): number {
|
||||
return this.props.margin;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,9 @@ const punctualCreateAdProps = {
|
|||
toDate: '2023-06-22',
|
||||
schedule: [
|
||||
{
|
||||
day: 4,
|
||||
time: '08:30',
|
||||
margin: 900,
|
||||
},
|
||||
],
|
||||
frequency: Frequency.PUNCTUAL,
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { AD_REPOSITORY } from '@modules/ad/ad.di-tokens';
|
||||
import { FindAdsByIdsQuery } from '@modules/ad/core/application/queries/find-ads-by-ids/find-ads-by-ids.query';
|
||||
import { FindAdsByIdsQueryHandler } from '@modules/ad/core/application/queries/find-ads-by-ids/find-ads-by-ids.query-handler';
|
||||
import { AdEntity } from '@modules/ad/core/domain/ad.entity';
|
||||
import { CreateAdProps, Frequency } from '@modules/ad/core/domain/ad.types';
|
||||
import { WaypointProps } from '@modules/ad/core/domain/value-objects/waypoint.value-object';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { FindAdsByIdsQueryHandler } from '@modules/ad/core/application/queries/find-ads-by-ids/find-ads-by-ids.query-handler';
|
||||
import { FindAdsByIdsQuery } from '@modules/ad/core/application/queries/find-ads-by-ids/find-ads-by-ids.query';
|
||||
|
||||
const originWaypointProps: WaypointProps = {
|
||||
position: 0,
|
||||
|
@ -44,7 +44,9 @@ const punctualCreateAdProps = {
|
|||
toDate: '2023-06-22',
|
||||
schedule: [
|
||||
{
|
||||
day: 4,
|
||||
time: '08:30',
|
||||
margin: 900,
|
||||
},
|
||||
],
|
||||
frequency: Frequency.PUNCTUAL,
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { AD_REPOSITORY } from '@modules/ad/ad.di-tokens';
|
||||
import { FindAdsByUserIdQuery } from '@modules/ad/core/application/queries/find-ads-by-user-id/find-ads-by-user-id.query';
|
||||
import { FindAdsByUserIdQueryHandler } from '@modules/ad/core/application/queries/find-ads-by-user-id/find-ads-by-user-id.query-handler';
|
||||
import { AdEntity } from '@modules/ad/core/domain/ad.entity';
|
||||
import { CreateAdProps, Frequency } from '@modules/ad/core/domain/ad.types';
|
||||
import { WaypointProps } from '@modules/ad/core/domain/value-objects/waypoint.value-object';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { FindAdsByUserIdQueryHandler } from '@modules/ad/core/application/queries/find-ads-by-user-id/find-ads-by-user-id.query-handler';
|
||||
import { FindAdsByUserIdQuery } from '@modules/ad/core/application/queries/find-ads-by-user-id/find-ads-by-user-id.query';
|
||||
|
||||
const originWaypointProps: WaypointProps = {
|
||||
position: 0,
|
||||
|
@ -44,7 +44,9 @@ const punctualCreateAdProps = {
|
|||
toDate: '2023-06-22',
|
||||
schedule: [
|
||||
{
|
||||
day: 4,
|
||||
time: '08:30',
|
||||
margin: 900,
|
||||
},
|
||||
],
|
||||
frequency: Frequency.PUNCTUAL,
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AD_REPOSITORY } from '@modules/ad/ad.di-tokens';
|
||||
import { AggregateID } from '@mobicoop/ddd-library';
|
||||
import { AD_REPOSITORY } from '@modules/ad/ad.di-tokens';
|
||||
import { InvalidateAdCommand } from '@modules/ad/core/application/commands/invalidate-ad/invalidate-ad.command';
|
||||
import { InvalidateAdService } from '@modules/ad/core/application/commands/invalidate-ad/invalidate-ad.service';
|
||||
import { AdEntity } from '@modules/ad/core/domain/ad.entity';
|
||||
import { CreateAdProps, Frequency } from '@modules/ad/core/domain/ad.types';
|
||||
import { WaypointProps } from '@modules/ad/core/domain/value-objects/waypoint.value-object';
|
||||
import { InvalidateAdService } from '@modules/ad/core/application/commands/invalidate-ad/invalidate-ad.service';
|
||||
import { InvalidateAdCommand } from '@modules/ad/core/application/commands/invalidate-ad/invalidate-ad.command';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
const originWaypointProps: WaypointProps = {
|
||||
position: 0,
|
||||
|
@ -45,7 +45,9 @@ const punctualCreateAdProps = {
|
|||
toDate: '2023-06-22',
|
||||
schedule: [
|
||||
{
|
||||
day: 4,
|
||||
time: '08:30',
|
||||
margin: 900,
|
||||
},
|
||||
],
|
||||
frequency: Frequency.PUNCTUAL,
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AD_REPOSITORY } from '@modules/ad/ad.di-tokens';
|
||||
import { AggregateID } from '@mobicoop/ddd-library';
|
||||
import { AD_REPOSITORY } from '@modules/ad/ad.di-tokens';
|
||||
import { ValidateAdCommand } from '@modules/ad/core/application/commands/validate-ad/validate-ad.command';
|
||||
import { ValidateAdService } from '@modules/ad/core/application/commands/validate-ad/validate-ad.service';
|
||||
import { AdEntity } from '@modules/ad/core/domain/ad.entity';
|
||||
import { CreateAdProps, Frequency } from '@modules/ad/core/domain/ad.types';
|
||||
import { ValidateAdService } from '@modules/ad/core/application/commands/validate-ad/validate-ad.service';
|
||||
import { ValidateAdCommand } from '@modules/ad/core/application/commands/validate-ad/validate-ad.command';
|
||||
import { WaypointProps } from '@modules/ad/core/domain/value-objects/waypoint.value-object';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
const originWaypointProps: WaypointProps = {
|
||||
position: 0,
|
||||
|
@ -45,7 +45,9 @@ const punctualCreateAdProps = {
|
|||
toDate: '2023-06-22',
|
||||
schedule: [
|
||||
{
|
||||
day: 4,
|
||||
time: '08:30',
|
||||
margin: 900,
|
||||
},
|
||||
],
|
||||
frequency: Frequency.PUNCTUAL,
|
||||
|
|
Loading…
Reference in New Issue