Skip to content

Commit

Permalink
add service in task, modify DomainModel interface
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechGrancow committed Dec 27, 2023
1 parent 2a7b5ae commit bfec4ab
Show file tree
Hide file tree
Showing 37 changed files with 184 additions and 128 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeletionDomainModel } from '../domain/types';
import { DomainModel } from '@shared/domain/types';
import { DeletionLogStatisticBuilder } from '.';

describe(DeletionLogStatisticBuilder.name, () => {
Expand All @@ -8,7 +8,7 @@ describe(DeletionLogStatisticBuilder.name, () => {

it('should build generic deletionLogStatistic with all attributes', () => {
// Arrange
const domain = DeletionDomainModel.PSEUDONYMS;
const domain = DomainModel.PSEUDONYMS;
const modifiedCount = 0;
const deletedCount = 2;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DeletionDomainModel } from '../domain/types';
import { DeletionLogStatistic } from '../interface';
import { DomainOperation } from '@shared/domain/interface';
import { DomainModel } from '@shared/domain/types';

export class DeletionLogStatisticBuilder {
static build(domain: DeletionDomainModel, modifiedCount?: number, deletedCount?: number): DeletionLogStatistic {
static build(domain: DomainModel, modifiedCount?: number, deletedCount?: number): DomainOperation {
const deletionLogStatistic = { domain, modifiedCount, deletedCount };

return deletionLogStatistic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ObjectId } from 'bson';
import { DeletionDomainModel } from '../domain/types';
import { DomainModel } from '@shared/domain/types';
import { DeletionRequestBodyPropsBuilder } from './deletion-request-body-props.builder';

describe(DeletionRequestBodyPropsBuilder.name, () => {
Expand All @@ -8,7 +8,7 @@ describe(DeletionRequestBodyPropsBuilder.name, () => {
});
describe('when create deletionRequestBodyParams', () => {
const setup = () => {
const domain = DeletionDomainModel.PSEUDONYMS;
const domain = DomainModel.PSEUDONYMS;
const refId = new ObjectId().toHexString();
const deleteInMinutes = 1000;
return { domain, refId, deleteInMinutes };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { EntityId } from '@shared/domain/types';
import { DomainModel, EntityId } from '@shared/domain/types';
import { DeletionRequestBodyProps } from '../controller/dto';
import { DeletionDomainModel } from '../domain/types';

export class DeletionRequestBodyPropsBuilder {
static build(domain: DeletionDomainModel, id: EntityId, deleteInMinutes?: number): DeletionRequestBodyProps {
static build(domain: DomainModel, id: EntityId, deleteInMinutes?: number): DeletionRequestBodyProps {
const deletionRequestItem = {
targetRef: { domain, id },
deleteInMinutes,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeletionDomainModel } from '../domain/types';
import { DomainModel } from '@shared/domain/types';
import { DeletionLogStatisticBuilder, DeletionRequestLogResponseBuilder, DeletionTargetRefBuilder } from '.';

describe(DeletionRequestLogResponseBuilder, () => {
Expand All @@ -8,7 +8,7 @@ describe(DeletionRequestLogResponseBuilder, () => {

it('should build generic deletionRequestLog with all attributes', () => {
// Arrange
const targetRefDomain = DeletionDomainModel.PSEUDONYMS;
const targetRefDomain = DomainModel.PSEUDONYMS;
const targetRefId = '653e4833cc39e5907a1e18d2';
const targetRef = DeletionTargetRefBuilder.build(targetRefDomain, targetRefId);
const deletionPlannedAt = new Date();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { DomainOperation } from '@shared/domain/interface';
import { DeletionRequestLogResponse } from '../controller/dto';
import { DeletionLogStatistic, DeletionTargetRef } from '../interface';
import { DeletionTargetRef } from '../interface';

export class DeletionRequestLogResponseBuilder {
static build(
targetRef: DeletionTargetRef,
deletionPlannedAt: Date,
statistics?: DeletionLogStatistic[]
statistics?: DomainOperation[]
): DeletionRequestLogResponse {
const deletionRequestLog = { targetRef, deletionPlannedAt, statistics };

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeletionDomainModel } from '../domain/types';
import { DomainModel } from '@shared/domain/types';
import { DeletionTargetRefBuilder } from './index';

describe(DeletionTargetRefBuilder.name, () => {
Expand All @@ -8,7 +8,7 @@ describe(DeletionTargetRefBuilder.name, () => {

it('should build generic deletionTargetRef with all attributes', () => {
// Arrange
const domain = DeletionDomainModel.PSEUDONYMS;
const domain = DomainModel.PSEUDONYMS;
const refId = '653e4833cc39e5907a1e18d2';

const result = DeletionTargetRefBuilder.build(domain, refId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { EntityId } from '@shared/domain/types';
import { DeletionDomainModel } from '../domain/types';
import { DomainModel, EntityId } from '@shared/domain/types';
import { DeletionTargetRef } from '../interface';

export class DeletionTargetRefBuilder {
static build(domain: DeletionDomainModel, id: EntityId): DeletionTargetRef {
static build(domain: DomainModel, id: EntityId): DeletionTargetRef {
const deletionTargetRef = { domain, id };

return deletionTargetRef;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ObjectId } from '@mikro-orm/mongodb';
import { DomainModel } from '@shared/domain/types';
import { deletionLogFactory } from './testing/factory/deletion-log.factory';
import { DeletionLog } from './deletion-log.do';
import { DeletionOperationModel, DeletionDomainModel } from './types';
import { DeletionOperationModel } from './types';

describe(DeletionLog.name, () => {
describe('constructor', () => {
Expand Down Expand Up @@ -35,7 +36,7 @@ describe(DeletionLog.name, () => {
const setup = () => {
const props = {
id: new ObjectId().toHexString(),
domain: DeletionDomainModel.USER,
domain: DomainModel.USER,
operation: DeletionOperationModel.DELETE,
modifiedCount: 0,
deletedCount: 1,
Expand Down
8 changes: 4 additions & 4 deletions apps/server/src/modules/deletion/domain/deletion-log.do.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { EntityId } from '@shared/domain/types';
import { DomainModel, EntityId } from '@shared/domain/types';
import { AuthorizableObject, DomainObject } from '@shared/domain/domain-object';
import { DeletionDomainModel, DeletionOperationModel } from './types';
import { DeletionOperationModel } from './types';

export interface DeletionLogProps extends AuthorizableObject {
createdAt?: Date;
updatedAt?: Date;
domain: DeletionDomainModel;
domain: DomainModel;
operation?: DeletionOperationModel;
modifiedCount?: number;
deletedCount?: number;
Expand All @@ -22,7 +22,7 @@ export class DeletionLog extends DomainObject<DeletionLogProps> {
return this.props.updatedAt;
}

get domain(): DeletionDomainModel {
get domain(): DomainModel {
return this.props.domain;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ObjectId } from '@mikro-orm/mongodb';
import { DomainModel } from '@shared/domain/types';
import { DeletionRequest } from './deletion-request.do';
import { DeletionDomainModel, DeletionStatusModel } from './types';
import { DeletionStatusModel } from './types';
import { deletionRequestFactory } from './testing/factory/deletion-request.factory';

describe(DeletionRequest.name, () => {
Expand Down Expand Up @@ -35,7 +36,7 @@ describe(DeletionRequest.name, () => {
const setup = () => {
const props = {
id: new ObjectId().toHexString(),
targetRefDomain: DeletionDomainModel.USER,
targetRefDomain: DomainModel.USER,
deleteAfter: new Date(),
targetRefId: new ObjectId().toHexString(),
status: DeletionStatusModel.REGISTERED,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { EntityId } from '@shared/domain/types';
import { DomainModel, EntityId } from '@shared/domain/types';
import { AuthorizableObject, DomainObject } from '@shared/domain/domain-object';
import { DeletionDomainModel, DeletionStatusModel } from './types';
import { DeletionStatusModel } from './types';

export interface DeletionRequestProps extends AuthorizableObject {
createdAt?: Date;
updatedAt?: Date;
targetRefDomain: DeletionDomainModel;
targetRefDomain: DomainModel;
deleteAfter: Date;
targetRefId: EntityId;
status: DeletionStatusModel;
Expand All @@ -20,7 +20,7 @@ export class DeletionRequest extends DomainObject<DeletionRequestProps> {
return this.props.updatedAt;
}

get targetRefDomain(): DeletionDomainModel {
get targetRefDomain(): DomainModel {
return this.props.targetRefDomain;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { DoBaseFactory } from '@shared/testing';
import { ObjectId } from '@mikro-orm/mongodb';
import { DomainModel } from '@shared/domain/types';
import { DeletionLog, DeletionLogProps } from '../../deletion-log.do';
import { DeletionOperationModel, DeletionDomainModel } from '../../types';
import { DeletionOperationModel } from '../../types';

export const deletionLogFactory = DoBaseFactory.define<DeletionLog, DeletionLogProps>(DeletionLog, () => {
return {
id: new ObjectId().toHexString(),
domain: DeletionDomainModel.USER,
domain: DomainModel.USER,
operation: DeletionOperationModel.DELETE,
modifiedCount: 0,
deletedCount: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { DoBaseFactory } from '@shared/testing';
import { ObjectId } from '@mikro-orm/mongodb';
import { DeepPartial } from 'fishery';
import { DomainModel } from '@shared/domain/types';
import { DeletionRequest, DeletionRequestProps } from '../../deletion-request.do';
import { DeletionDomainModel, DeletionStatusModel } from '../../types';
import { DeletionStatusModel } from '../../types';

class DeletionRequestFactory extends DoBaseFactory<DeletionRequest, DeletionRequestProps> {
withUserIds(id: string): this {
Expand All @@ -17,7 +18,7 @@ class DeletionRequestFactory extends DoBaseFactory<DeletionRequest, DeletionRequ
export const deletionRequestFactory = DeletionRequestFactory.define(DeletionRequest, () => {
return {
id: new ObjectId().toHexString(),
targetRefDomain: DeletionDomainModel.USER,
targetRefDomain: DomainModel.USER,
deleteAfter: new Date(),
targetRefId: new ObjectId().toHexString(),
status: DeletionStatusModel.REGISTERED,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { setupEntities } from '@shared/testing';
import { ObjectId } from '@mikro-orm/mongodb';
import { DomainModel } from '@shared/domain/types';
import { DeletionLogEntity } from './deletion-log.entity';
import { DeletionOperationModel, DeletionDomainModel } from '../domain/types';
import { DeletionOperationModel } from '../domain/types';

describe(DeletionLogEntity.name, () => {
beforeAll(async () => {
Expand All @@ -13,7 +14,7 @@ describe(DeletionLogEntity.name, () => {
const setup = () => {
const props = {
id: new ObjectId().toHexString(),
domain: DeletionDomainModel.USER,
domain: DomainModel.USER,
operation: DeletionOperationModel.DELETE,
modifiedCount: 0,
deletedCount: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Entity, Index, Property } from '@mikro-orm/core';
import { BaseEntityWithTimestamps } from '@shared/domain/entity/base.entity';
import { EntityId } from '@shared/domain/types';
import { DomainModel, EntityId } from '@shared/domain/types';
import { ObjectId } from 'bson';
import { DeletionDomainModel, DeletionOperationModel } from '../domain/types';
import { DeletionOperationModel } from '../domain/types';

export interface DeletionLogEntityProps {
id?: EntityId;
domain: DeletionDomainModel;
domain: DomainModel;
operation?: DeletionOperationModel;
modifiedCount?: number;
deletedCount?: number;
Expand All @@ -19,7 +19,7 @@ export interface DeletionLogEntityProps {
@Entity({ tableName: 'deletionlogs' })
export class DeletionLogEntity extends BaseEntityWithTimestamps {
@Property()
domain: DeletionDomainModel;
domain: DomainModel;

@Property({ nullable: true })
operation?: DeletionOperationModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { setupEntities } from '@shared/testing';
import { ObjectId } from '@mikro-orm/mongodb';
import { DeletionDomainModel, DeletionStatusModel } from '../domain/types';
import { DomainModel } from '@shared/domain/types';
import { DeletionStatusModel } from '../domain/types';
import { DeletionRequestEntity } from '.';

describe(DeletionRequestEntity.name, () => {
Expand All @@ -15,7 +16,7 @@ describe(DeletionRequestEntity.name, () => {
const setup = () => {
const props = {
id: new ObjectId().toHexString(),
targetRefDomain: DeletionDomainModel.USER,
targetRefDomain: DomainModel.USER,
deleteAfter: new Date(),
targetRefId: new ObjectId().toHexString(),
status: DeletionStatusModel.REGISTERED,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Entity, Index, Property, Unique } from '@mikro-orm/core';
import { BaseEntityWithTimestamps } from '@shared/domain/entity/base.entity';
import { EntityId } from '@shared/domain/types';
import { DeletionDomainModel, DeletionStatusModel } from '../domain/types';
import { DomainModel, EntityId } from '@shared/domain/types';
import { DeletionStatusModel } from '../domain/types';

const SECONDS_OF_90_DAYS = 90 * 24 * 60 * 60;
export interface DeletionRequestEntityProps {
id?: EntityId;
targetRefDomain: DeletionDomainModel;
targetRefDomain: DomainModel;
deleteAfter: Date;
targetRefId: EntityId;
status: DeletionStatusModel;
Expand All @@ -25,7 +25,7 @@ export class DeletionRequestEntity extends BaseEntityWithTimestamps {
targetRefId!: EntityId;

@Property()
targetRefDomain: DeletionDomainModel;
targetRefDomain: DomainModel;

@Property()
status: DeletionStatusModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { ObjectId } from '@mikro-orm/mongodb';
import { BaseFactory } from '@shared/testing';
import { DomainModel } from '@shared/domain/types';
import { DeletionLogEntity, DeletionLogEntityProps } from '../../deletion-log.entity';
import { DeletionOperationModel, DeletionDomainModel } from '../../../domain/types';
import { DeletionOperationModel } from '../../../domain/types';

export const deletionLogEntityFactory = BaseFactory.define<DeletionLogEntity, DeletionLogEntityProps>(
DeletionLogEntity,
() => {
return {
id: new ObjectId().toHexString(),
domain: DeletionDomainModel.USER,
domain: DomainModel.USER,
operation: DeletionOperationModel.DELETE,
modifiedCount: 0,
deletedCount: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { ObjectId } from '@mikro-orm/mongodb';
import { BaseFactory } from '@shared/testing';
import { DeletionStatusModel, DeletionDomainModel } from '../../../domain/types';
import { DomainModel } from '@shared/domain/types';
import { DeletionStatusModel } from '../../../domain/types';
import { DeletionRequestEntity, DeletionRequestEntityProps } from '../../deletion-request.entity';

export const deletionRequestEntityFactory = BaseFactory.define<DeletionRequestEntity, DeletionRequestEntityProps>(
DeletionRequestEntity,
() => {
return {
id: new ObjectId().toHexString(),
targetRefDomain: DeletionDomainModel.USER,
targetRefDomain: DomainModel.USER,
deleteAfter: new Date(),
targetRefId: new ObjectId().toHexString(),
status: DeletionStatusModel.REGISTERED,
Expand Down
11 changes: 2 additions & 9 deletions apps/server/src/modules/deletion/interface/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { EntityId } from '@shared/domain/types';
import { DeletionDomainModel } from '../domain/types';
import { DomainModel, EntityId } from '@shared/domain/types';

export interface DeletionTargetRef {
domain: DeletionDomainModel;
domain: DomainModel;
id: EntityId;
}

export interface DeletionLogStatistic {
domain: DeletionDomainModel;
modifiedCount?: number;
deletedCount?: number;
}
Loading

0 comments on commit bfec4ab

Please sign in to comment.