Skip to content

Commit

Permalink
feat: add aggregate, edit anemic, add data
Browse files Browse the repository at this point in the history
  • Loading branch information
ToxicToast committed Jun 2, 2024
1 parent 51b9d98 commit e34ff50
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 3 deletions.
71 changes: 71 additions & 0 deletions libs/group-domain/src/lib/aggregates/group.aggregate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Domain } from '@toxictoast/azkaban-base-domain';
import { GroupAnemic } from '../anemics';
import { Nullable } from '@toxictoast/azkaban-base-types';

export class GroupAggregate implements Domain<GroupAnemic> {
constructor(
private readonly id: string,
private title: string,
private slug: string,
private active: boolean,
private readonly created_at: Date,
private updated_at: Nullable<Date>,
private deleted_at: Nullable<Date>,
) {}

isActive(): boolean {
return this.active && !this.isDeleted();
}

isUpdated(): boolean {
return !!this.updated_at;
}

isDeleted(): boolean {
return !!this.deleted_at;
}

delete(): void {
this.deleted_at = new Date();
}

restore(): void {
this.deleted_at = null;
}

toAnemic(): GroupAnemic {
return {
id: this.id,
title: this.title,
slug: this.slug,
active: this.active,
created_at: this.created_at,
updated_at: this.updated_at,
deleted_at: this.deleted_at,
isActive: this.isActive(),
isUpdated: this.isUpdated(),
isDeleted: this.isDeleted(),
};
}

updateTitle(title: string): void {
if (this.title !== title) {
this.updated_at = new Date();
this.title = title;
}
}

updateSlug(slug: string): void {
if (this.slug !== slug) {
this.updated_at = new Date();
this.slug = slug;
}
}

updateActive(active: boolean): void {
if (this.active !== active) {
this.updated_at = new Date();
this.active = active;
}
}
}
2 changes: 1 addition & 1 deletion libs/group-domain/src/lib/aggregates/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {};
export * from './group.aggregate';
2 changes: 2 additions & 0 deletions libs/group-domain/src/lib/anemics/group.anemic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import { Anemic } from '@toxictoast/azkaban-base-domain';
export interface GroupAnemic extends Anemic {
readonly title: string;
readonly slug: string;
readonly active: boolean;
readonly isActive: boolean;
}
3 changes: 3 additions & 0 deletions libs/group-domain/src/lib/data/group.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface GroupData {
readonly title: string;
}
2 changes: 1 addition & 1 deletion libs/group-domain/src/lib/data/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {};
export * from './group.data';
9 changes: 8 additions & 1 deletion libs/group-domain/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
export {};
export * from './aggregates';
export * from './anemics';
export * from './data';
export * from './factories';
export * from './repositories';
export * from './services';
export * from './validations';
export * from './valueObjects';
1 change: 1 addition & 0 deletions libs/group-domain/src/lib/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions libs/group-domain/src/lib/validations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions libs/group-domain/src/lib/valueObjects/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};

0 comments on commit e34ff50

Please sign in to comment.