diff --git a/packages/domain-core/src/Domain/Common/Timestamps.spec.ts b/packages/domain-core/src/Domain/Common/Dates.spec.ts similarity index 56% rename from packages/domain-core/src/Domain/Common/Timestamps.spec.ts rename to packages/domain-core/src/Domain/Common/Dates.spec.ts index 98839a122..0bd8a9ebe 100644 --- a/packages/domain-core/src/Domain/Common/Timestamps.spec.ts +++ b/packages/domain-core/src/Domain/Common/Dates.spec.ts @@ -1,8 +1,8 @@ -import { Timestamps } from './Timestamps' +import { Dates } from './Dates' -describe('Timestamps', () => { +describe('Dates', () => { it('should create a value object', () => { - const valueOrError = Timestamps.create(new Date(1), new Date(2)) + const valueOrError = Dates.create(new Date(1), new Date(2)) expect(valueOrError.isFailed()).toBeFalsy() expect(valueOrError.getValue().createdAt).toEqual(new Date(1)) @@ -10,11 +10,11 @@ describe('Timestamps', () => { }) it('should not create an invalid value object', () => { - let valueOrError = Timestamps.create(null as unknown as Date, '2' as unknown as Date) + let valueOrError = Dates.create(null as unknown as Date, '2' as unknown as Date) expect(valueOrError.isFailed()).toBeTruthy() - valueOrError = Timestamps.create(new Date(2), '2' as unknown as Date) + valueOrError = Dates.create(new Date(2), '2' as unknown as Date) expect(valueOrError.isFailed()).toBeTruthy() }) diff --git a/packages/domain-core/src/Domain/Common/Dates.ts b/packages/domain-core/src/Domain/Common/Dates.ts new file mode 100644 index 000000000..693756c82 --- /dev/null +++ b/packages/domain-core/src/Domain/Common/Dates.ts @@ -0,0 +1,28 @@ +import { Result } from '../Core/Result' +import { ValueObject } from '../Core/ValueObject' +import { DatesProps } from './DatesProps' + +export class Dates extends ValueObject { + get createdAt(): Date { + return this.props.createdAt + } + + get updatedAt(): Date { + return this.props.updatedAt + } + + private constructor(props: DatesProps) { + super(props) + } + + static create(createdAt: Date, updatedAt: Date): Result { + if (!(createdAt instanceof Date)) { + return Result.fail(`Could not create Dates. Creation date should be a date object, given: ${createdAt}`) + } + if (!(updatedAt instanceof Date)) { + return Result.fail(`Could not create Dates. Update date should be a date object, given: ${createdAt}`) + } + + return Result.ok(new Dates({ createdAt, updatedAt })) + } +} diff --git a/packages/domain-core/src/Domain/Common/TimestampsProps.ts b/packages/domain-core/src/Domain/Common/DatesProps.ts similarity index 52% rename from packages/domain-core/src/Domain/Common/TimestampsProps.ts rename to packages/domain-core/src/Domain/Common/DatesProps.ts index de942dd98..2a250e42a 100644 --- a/packages/domain-core/src/Domain/Common/TimestampsProps.ts +++ b/packages/domain-core/src/Domain/Common/DatesProps.ts @@ -1,4 +1,4 @@ -export interface TimestampsProps { +export interface DatesProps { createdAt: Date updatedAt: Date } diff --git a/packages/domain-core/src/Domain/Common/Timestamps.ts b/packages/domain-core/src/Domain/Common/Timestamps.ts deleted file mode 100644 index 5fc42c510..000000000 --- a/packages/domain-core/src/Domain/Common/Timestamps.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { Result } from '../Core/Result' -import { ValueObject } from '../Core/ValueObject' -import { TimestampsProps } from './TimestampsProps' - -export class Timestamps extends ValueObject { - get createdAt(): Date { - return this.props.createdAt - } - - get updatedAt(): Date { - return this.props.updatedAt - } - - private constructor(props: TimestampsProps) { - super(props) - } - - static create(createdAt: Date, updatedAt: Date): Result { - if (!(createdAt instanceof Date)) { - return Result.fail( - `Could not create Timestamps. Creation date should be a date object, given: ${createdAt}`, - ) - } - if (!(updatedAt instanceof Date)) { - return Result.fail( - `Could not create Timestamps. Update date should be a date object, given: ${createdAt}`, - ) - } - - return Result.ok(new Timestamps({ createdAt, updatedAt })) - } -} diff --git a/packages/domain-core/src/Domain/index.ts b/packages/domain-core/src/Domain/index.ts index 8c40ab1c2..b9c95ca45 100644 --- a/packages/domain-core/src/Domain/index.ts +++ b/packages/domain-core/src/Domain/index.ts @@ -1,11 +1,11 @@ +export * from './Common/Dates' +export * from './Common/DatesProps' export * from './Common/Email' export * from './Common/EmailProps' export * from './Common/RoleName' export * from './Common/RoleNameProps' export * from './Common/RoleNameCollection' export * from './Common/RoleNameCollectionProps' -export * from './Common/Timestamps' -export * from './Common/TimestampsProps' export * from './Common/Uuid' export * from './Common/UuidProps'