From a4cabb55b5c29c556181824ce79544ccd351e613 Mon Sep 17 00:00:00 2001 From: Thiago Zanivan Date: Tue, 14 Apr 2020 23:07:34 -0300 Subject: [PATCH] fix: minor typing fixes & lint --- src/core/Entity.ts | 3 ++- src/repository/CrudRepository.ts | 16 ++++++++-------- test/command/CommandRunner.test.ts | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/core/Entity.ts b/src/core/Entity.ts index cdcc882..2275e6f 100644 --- a/src/core/Entity.ts +++ b/src/core/Entity.ts @@ -1,5 +1,6 @@ import { Object } from './Object' import { EntityId } from './EntityId' +import { cloneDeep } from 'lodash' const isEntity = (v: unknown): v is Entity => { return v instanceof Entity @@ -38,7 +39,7 @@ export abstract class Entity implements Object { constructor(props: T, id: EntityId = new EntityId()) { this._id = id - this.props = props + this.props = cloneDeep(props) } get id(): EntityId { diff --git a/src/repository/CrudRepository.ts b/src/repository/CrudRepository.ts index f780106..0573ca1 100644 --- a/src/repository/CrudRepository.ts +++ b/src/repository/CrudRepository.ts @@ -35,7 +35,7 @@ export interface CrudRepository, ID extends EntityId> * @param id of the entity. * @return the entity with the given ID or `undefined` if none found. */ - findById: (id: ID) => Promise + findById: (id: ID) => Promise /** * Returns whether an entity with the given ID exists. @@ -43,14 +43,14 @@ export interface CrudRepository, ID extends EntityId> * @param id of the entity. * @return `true` if an entity with the given id exists, `false` otherwise. */ - existsById: (id: ID) => Promise + existsById: (id: ID) => Promise /** * Returns all instances of the type. * * @return all entities */ - findAll: () => Promise + findAll: () => Promise /** * Returns all instances of the type `T` with the given IDs. @@ -62,33 +62,33 @@ export interface CrudRepository, ID extends EntityId> * @param ids of entities to be retuned. * @return the entities. */ - findAllById: (ids: ID[]) => Promise + findAllById: (ids: ID[]) => Promise /** * Returns the number of entities. * * @return the number of entities. */ - count: () => Promise + count: () => Promise /** * Deletes the entity with the given id. * * @param id of entity to delete. */ - deleteById: (id: ID) => Promise + deleteById: (id: ID) => Promise /** * Deletes a given entity. * * @param entity to delete. */ - delete: (entity: T) => Promise + delete: (entity: T) => Promise /** * Deletes the given entities, or all when no arguments are provided. * * @param entities to delete or `undefined` to delete all. */ - deleteAll: (entities?: T[]) => Promise + deleteAll: (entities?: T[]) => Promise } diff --git a/test/command/CommandRunner.test.ts b/test/command/CommandRunner.test.ts index 5de818d..3e355e7 100644 --- a/test/command/CommandRunner.test.ts +++ b/test/command/CommandRunner.test.ts @@ -85,7 +85,7 @@ describe('CommandRunner test', () => { it('should notify subscribers', async () => { const input = CreateUserInput.populate({ email: 'hi+github@thiagozf.com' }) - const output = await runner.run(CreateUserCommand, input) + await runner.run(CreateUserCommand, input) expect(watchers.before).toStrictEqual([2, 1, 0]) expect(watchers.after).toHaveLength(1) })