Skip to content

Commit

Permalink
changes in deletionUC, implement domainOperation and operationModel
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechGrancow committed Jan 18, 2024
1 parent 72bee55 commit ac8fe06
Show file tree
Hide file tree
Showing 18 changed files with 133 additions and 148 deletions.
19 changes: 9 additions & 10 deletions apps/server/src/modules/deletion/domain/deletion-log.do.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { DomainModel, EntityId } from '@shared/domain/types';
import { DomainModel, EntityId, OperationModel } from '@shared/domain/types';
import { AuthorizableObject, DomainObject } from '@shared/domain/domain-object';
import { DeletionOperationModel } from './types';

export interface DeletionLogProps extends AuthorizableObject {
createdAt?: Date;
updatedAt?: Date;
domain: DomainModel;
operation?: DeletionOperationModel;
modifiedCount: number;
deletedCount: number;
operation: OperationModel;
count: number;
refs: EntityId[];
deletionRequestId?: EntityId;
performedAt?: Date;
}
Expand All @@ -26,16 +25,16 @@ export class DeletionLog extends DomainObject<DeletionLogProps> {
return this.props.domain;
}

get operation(): DeletionOperationModel | undefined {
get operation(): OperationModel {
return this.props.operation;
}

get modifiedCount(): number {
return this.props.modifiedCount;
get count(): number {
return this.props.count;
}

get deletedCount(): number {
return this.props.deletedCount;
get refs(): EntityId[] {
return this.props.refs;
}

get deletionRequestId(): EntityId | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const deletionLogFactory = DoBaseFactory.define<DeletionLog, DeletionLogP
id: new ObjectId().toHexString(),
domain: DomainModel.USER,
operation: DeletionOperationModel.DELETE,
modifiedCount: 0,
deletedCount: 1,
count: 1,
refs: [new ObjectId().toHexString()],
deletionRequestId: new ObjectId().toHexString(),
performedAt: new Date(),
createdAt: new Date(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ describe(DeletionLogEntity.name, () => {
id: new ObjectId().toHexString(),
domain: DomainModel.USER,
operation: DeletionOperationModel.DELETE,
modifiedCount: 0,
deletedCount: 1,
count: 1,
refs: [new ObjectId().toHexString()],
deletionRequestId: new ObjectId(),
performedAt: new Date(),
createdAt: new Date(),
Expand Down Expand Up @@ -47,8 +47,8 @@ describe(DeletionLogEntity.name, () => {
id: entity.id,
domain: entity.domain,
operation: entity.operation,
modifiedCount: entity.modifiedCount,
deletedCount: entity.deletedCount,
count: entity.count,
refs: entity.refs,
deletionRequestId: entity.deletionRequestId,
performedAt: entity.performedAt,
createdAt: entity.createdAt,
Expand Down
23 changes: 10 additions & 13 deletions apps/server/src/modules/deletion/entity/deletion-log.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { DeletionOperationModel } from '../domain/types';
export interface DeletionLogEntityProps {
id?: EntityId;
domain: DomainModel;
operation?: DeletionOperationModel;
modifiedCount: number;
deletedCount: number;
operation: DeletionOperationModel;
count: number;
refs: EntityId[];
deletionRequestId?: ObjectId;
performedAt?: Date;
createdAt?: Date;
Expand All @@ -21,14 +21,14 @@ export class DeletionLogEntity extends BaseEntityWithTimestamps {
@Property()
domain: DomainModel;

@Property({ nullable: true })
operation?: DeletionOperationModel;
@Property()
operation: DeletionOperationModel;

@Property()
modifiedCount: number;
count: number;

@Property()
deletedCount: number;
refs: EntityId[];

@Property({ nullable: true })
deletionRequestId?: ObjectId;
Expand All @@ -44,12 +44,9 @@ export class DeletionLogEntity extends BaseEntityWithTimestamps {
}

this.domain = props.domain;

if (props.operation !== undefined) {
this.operation = props.operation;
}
this.modifiedCount = props.modifiedCount;
this.deletedCount = props.deletedCount;
this.operation = props.operation;
this.count = props.count;
this.refs = props.refs;

if (props.deletionRequestId !== undefined) {
this.deletionRequestId = props.deletionRequestId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const deletionLogEntityFactory = BaseFactory.define<DeletionLogEntity, De
id: new ObjectId().toHexString(),
domain: DomainModel.USER,
operation: DeletionOperationModel.DELETE,
modifiedCount: 0,
deletedCount: 1,
count: 1,
refs: [new ObjectId().toHexString()],
deletionRequestId: new ObjectId(),
createdAt: new Date(),
updatedAt: new Date(),
Expand Down
16 changes: 8 additions & 8 deletions apps/server/src/modules/deletion/repo/deletion-log.repo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ describe(DeletionLogRepo.name, () => {
id: domainObject.id,
domain: domainObject.domain,
operation: domainObject.operation,
modifiedCount: domainObject.modifiedCount,
deletedCount: domainObject.deletedCount,
count: domainObject.count,
refs: domainObject.refs,
deletionRequestId: domainObject.deletionRequestId,
performedAt: domainObject.performedAt,
createdAt: domainObject.createdAt,
Expand Down Expand Up @@ -93,8 +93,8 @@ describe(DeletionLogRepo.name, () => {
id: entity.id,
domain: entity.domain,
operation: entity.operation,
modifiedCount: entity.modifiedCount,
deletedCount: entity.deletedCount,
count: entity.count,
refs: entity.refs,
deletionRequestId: entity.deletionRequestId?.toHexString(),
performedAt: entity.performedAt,
createdAt: entity.createdAt,
Expand Down Expand Up @@ -152,8 +152,8 @@ describe(DeletionLogRepo.name, () => {
operation: deletionLogEntity1.operation,
deletionRequestId: deletionLogEntity1.deletionRequestId?.toHexString(),
performedAt: deletionLogEntity1.performedAt,
modifiedCount: deletionLogEntity1.modifiedCount,
deletedCount: deletionLogEntity1.deletedCount,
count: deletionLogEntity1.count,
refs: deletionLogEntity1.refs,
createdAt: deletionLogEntity1.createdAt,
updatedAt: deletionLogEntity1.updatedAt,
},
Expand All @@ -163,8 +163,8 @@ describe(DeletionLogRepo.name, () => {
operation: deletionLogEntity2.operation,
deletionRequestId: deletionLogEntity2.deletionRequestId?.toHexString(),
performedAt: deletionLogEntity2.performedAt,
modifiedCount: deletionLogEntity2.modifiedCount,
deletedCount: deletionLogEntity2.deletedCount,
count: deletionLogEntity2.count,
refs: deletionLogEntity2.refs,
createdAt: deletionLogEntity2.createdAt,
updatedAt: deletionLogEntity2.updatedAt,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe(DeletionLogMapper.name, () => {
operation: entity.operation,
deletionRequestId: entity.deletionRequestId?.toHexString(),
performedAt: entity.performedAt,
modifiedCount: entity.modifiedCount,
deletedCount: entity.deletedCount,
count: entity.count,
refs: entity.refs,
createdAt: entity.createdAt,
updatedAt: entity.updatedAt,
});
Expand Down Expand Up @@ -56,8 +56,8 @@ describe(DeletionLogMapper.name, () => {
operation: entity.operation,
deletionRequestId: entity.deletionRequestId?.toHexString(),
performedAt: entity.performedAt,
modifiedCount: entity.modifiedCount,
deletedCount: entity.deletedCount,
count: entity.count,
refs: entity.refs,
createdAt: entity.createdAt,
updatedAt: entity.updatedAt,
})
Expand Down Expand Up @@ -95,8 +95,8 @@ describe(DeletionLogMapper.name, () => {
operation: domainObject.operation,

Check failure on line 95 in apps/server/src/modules/deletion/repo/mapper/deletion-log.mapper.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Unsafe assignment of an `any` value
deletionRequestId: new ObjectId(domainObject.deletionRequestId),

Check failure on line 96 in apps/server/src/modules/deletion/repo/mapper/deletion-log.mapper.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Unsafe argument of type `any` assigned to a parameter of type `string | number | Buffer | Uint8Array | ObjectId | ObjectIdLike | undefined`
performedAt: domainObject.performedAt,

Check failure on line 97 in apps/server/src/modules/deletion/repo/mapper/deletion-log.mapper.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Unsafe assignment of an `any` value
modifiedCount: domainObject.modifiedCount,
deletedCount: domainObject.deletedCount,
count: domainObject.count,

Check failure on line 98 in apps/server/src/modules/deletion/repo/mapper/deletion-log.mapper.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Unsafe assignment of an `any` value
refs: domainObject.refs,

Check failure on line 99 in apps/server/src/modules/deletion/repo/mapper/deletion-log.mapper.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Unsafe assignment of an `any` value
createdAt: domainObject.createdAt,

Check failure on line 100 in apps/server/src/modules/deletion/repo/mapper/deletion-log.mapper.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Unsafe assignment of an `any` value
updatedAt: domainObject.updatedAt,
});
Expand Down Expand Up @@ -144,8 +144,8 @@ describe(DeletionLogMapper.name, () => {
operation: domainObject.operation,
deletionRequestId: new ObjectId(domainObject.deletionRequestId),
performedAt: domainObject.performedAt,
modifiedCount: domainObject.modifiedCount,
deletedCount: domainObject.deletedCount,
count: domainObject.count,
refs: domainObject.refs,
createdAt: domainObject.createdAt,
updatedAt: domainObject.updatedAt,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export class DeletionLogMapper {
updatedAt: entity.updatedAt,
domain: entity.domain,
operation: entity.operation,
modifiedCount: entity.modifiedCount,
deletedCount: entity.deletedCount,
count: entity.count,
refs: entity.refs,
deletionRequestId: entity.deletionRequestId?.toHexString(),
performedAt: entity.performedAt,
});
Expand All @@ -24,8 +24,8 @@ export class DeletionLogMapper {
updatedAt: domainObject.updatedAt,
domain: domainObject.domain,
operation: domainObject.operation,
modifiedCount: domainObject.modifiedCount,
deletedCount: domainObject.deletedCount,
count: domainObject.count,
refs: domainObject.refs,
deletionRequestId: new ObjectId(domainObject.deletionRequestId),
performedAt: domainObject.performedAt,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ describe(DeletionLogService.name, () => {
const deletionRequestId = '653e4833cc39e5907a1e18d2';
const domain = DomainModel.USER;
const operation = DeletionOperationModel.DELETE;
const modifiedCount = 0;
const deletedCount = 1;
const count = 1;
const refs = [new ObjectId().toHexString()];

return { deletionRequestId, domain, operation, modifiedCount, deletedCount };
return { deletionRequestId, domain, operation, count, refs };
};

it('should call deletionRequestRepo.create', async () => {
const { deletionRequestId, domain, operation, modifiedCount, deletedCount } = setup();
const { deletionRequestId, domain, operation, count, refs } = setup();

await service.createDeletionLog(deletionRequestId, domain, operation, modifiedCount, deletedCount);
await service.createDeletionLog(deletionRequestId, domain, operation, count, refs);

expect(deletionLogRepo.create).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -68,8 +68,8 @@ describe(DeletionLogService.name, () => {
deletionRequestId,
domain,
operation,
modifiedCount,
deletedCount,
count,
refs,
})
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ObjectId } from '@mikro-orm/mongodb';
import { Injectable } from '@nestjs/common';
import { DomainModel, EntityId } from '@shared/domain/types';
import { DomainModel, EntityId, OperationModel } from '@shared/domain/types';
import { DeletionLog } from '../domain/deletion-log.do';
import { DeletionOperationModel } from '../domain/types';
import { DeletionLogRepo } from '../repo';

@Injectable()
Expand All @@ -12,18 +11,18 @@ export class DeletionLogService {
async createDeletionLog(
deletionRequestId: EntityId,
domain: DomainModel,
operation: DeletionOperationModel,
modifiedCount: number,
deletedCount: number
operation: OperationModel,
count: number,
refs: EntityId[]
): Promise<void> {
const newDeletionLog = new DeletionLog({
id: new ObjectId().toHexString(),
performedAt: new Date(),
domain,
deletionRequestId,
operation,
modifiedCount,
deletedCount,
count,
refs,
});

await this.deletionLogRepo.create(newDeletionLog);
Expand Down
Loading

0 comments on commit ac8fe06

Please sign in to comment.