Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export default interface NotificationParams {
status: AllowedNotificationStatus;
idUser: string;
deletedAt: Date | null;
type: string;
}
13 changes: 12 additions & 1 deletion backend/src/modules/notification/core/model/Notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@ import NotificationAlreadyRead from '../error/NotificationAlreadyRead';
import type NotificationParams from '../interfaces/NotificationParams';
import IdNotification from '../objects/IdNotification';
import NotificationStatus from '../objects/NotificationStatus';
import type { NotificationTypes } from '../types/NotificationTypes';

export default class Notification extends Entity {
private eventKey!: string;
private status!: NotificationStatus;
private type!: NotificationTypes;

private constructor(
idNotification: IdNotification,
eventKey: string,
status: NotificationStatus,
type: NotificationTypes,
idUser: IdEntity,
) {
super(idNotification, idUser);
this.eventKey = eventKey;
this.status = status;
this.type = type;
}

public static create(
Expand All @@ -30,8 +34,9 @@ export default class Notification extends Entity {
eventKey: string,
idUser: IdEntity,
actor: IdEntity,
type: NotificationTypes,
): Notification {
const notification = new Notification(idNotification, eventKey, NotificationStatus.unread(), idUser);
const notification = new Notification(idNotification, eventKey, NotificationStatus.unread(), type, idUser);
notification.create();
notification.addEvent(
new NotificationCreated(key, DateTime.now(), actor, idUser, idNotification, notification.toPrimitives()),
Expand All @@ -44,6 +49,7 @@ export default class Notification extends Entity {
new IdNotification(params.id),
params.eventKey,
NotificationStatus.create(params.status),
params.type as NotificationTypes,
new IdEntity(params.idUser),
);

Expand Down Expand Up @@ -81,13 +87,18 @@ export default class Notification extends Entity {
return super.getOwner() as IdEntity;
}

public getType(): NotificationTypes {
return this.type;
}

public toPrimitives(): NotificationParams {
return {
id: this.getId().getID(),
eventKey: this.eventKey,
status: this.status.getStatus(),
idUser: this.getIdUser().getID(),
deletedAt: super.getDeletedAt().toPrimitive(),
type: this.type,
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const NOTIFICATION_TYPES = ['INFO', 'INVITATION'] as const;

export enum NotificationTypes {
info = 'INFO',
invitation = 'INVITATION',
}
12 changes: 12 additions & 0 deletions backend/src/modules/project/core/interfaces/ProjectCriteria.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default interface ProjectCriteria{
page?: number;
limit?: number;
title?: string;
archived?: boolean;
closed?: boolean;
idUser?: string;
watching?: boolean;
favorited?: boolean;
sortBy?: 'ASC' | 'DESC';
priority?: 'WATCHING' | 'FAVORITE' | 'ALL';
}
10 changes: 10 additions & 0 deletions backend/src/modules/project/core/repository/ProjectRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type IdEntity from "../../../shared/core/objects/IdEntity";
import type ProjectCriteria from "../interfaces/ProjectCriteria";
import type Project from "../model/Project";

export default interface ProjectRepository {
create(project: Project): Promise<void>;
update(project: Project): Promise<void>;
getById(id: IdEntity): Promise<Project | null>;
getByCriteria(criteria: ProjectCriteria): Promise<Project[]>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import NotificationAlreadyRead from '../../../../../src/modules/notification/cor
import Notification from '../../../../../src/modules/notification/core/model/Notification';
import IdNotification from '../../../../../src/modules/notification/core/objects/IdNotification';
import { AllowedNotificationStatus } from '../../../../../src/modules/notification/core/types/AllowedNotificationStatus';
import { NotificationTypes } from '../../../../../src/modules/notification/core/types/NotificationTypes';
import type DomainEvent from '../../../../../src/modules/shared/core/events/DomainEvent';
import IdEntity from '../../../../../src/modules/shared/core/objects/IdEntity';

Expand All @@ -17,6 +18,7 @@ const createNotificationParams = (
eventKey: string;
status: AllowedNotificationStatus;
idUser: string;
type: NotificationTypes;
deletedAt: Date | null;
key: string;
}>,
Expand All @@ -25,6 +27,7 @@ const createNotificationParams = (
eventKey: EVENT_ID,
status: AllowedNotificationStatus.unread,
idUser: USER_ID,
type: NotificationTypes.info,
deletedAt: null,
key: 'test-key',
...overrides,
Expand All @@ -39,6 +42,7 @@ const buildNotification = (overrides?: Parameters<typeof createNotificationParam
params.eventKey,
new IdEntity(params.idUser),
new IdEntity(ACTOR_ID),
params.type,
);
};

Expand All @@ -51,6 +55,7 @@ describe('Notification Entity', () => {
expect(notification.getEventKey()).toBe(EVENT_ID);
expect(notification.getIdUser().getID()).toBe(USER_ID);
expect(notification.getStatus().getStatus()).toBe(AllowedNotificationStatus.unread);
expect(notification.getType()).toBe(NotificationTypes.info);
expect(notification.exists()).toBe(true);
});

Expand Down Expand Up @@ -124,6 +129,7 @@ describe('Notification Entity', () => {
eventKey: params.eventKey,
status: params.status,
idUser: params.idUser,
type: params.type,
deletedAt: params.deletedAt,
});
});
Expand All @@ -137,6 +143,7 @@ describe('Notification Entity', () => {
expect(notification.getEventKey()).toBe(params.eventKey);
expect(notification.getIdUser().getID()).toBe(params.idUser);
expect(notification.getStatus().getStatus()).toBe(AllowedNotificationStatus.read);
expect(notification.getType()).toBe(params.type);
});

it('should preserve immutable details after marking as read', () => {
Expand All @@ -148,6 +155,7 @@ describe('Notification Entity', () => {
expect(primitives.id).toBe(DEFAULT_ID);
expect(primitives.eventKey).toBe(EVENT_ID);
expect(primitives.idUser).toBe(USER_ID);
expect(primitives.type).toBe(NotificationTypes.info);
expect(primitives.status).toBe(AllowedNotificationStatus.read);
});
});
Expand Down
Loading