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
20 changes: 12 additions & 8 deletions backend/src/modules/account/core/model/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,20 @@ export default class Account extends Entity {
}

public static create(
id: IdAccount,
email: Email,
name: AccountName,
provider: string,
profileImage: Url | None,
owner: IdEntity,
isPrimary: boolean
params: Omit<AccountParams, 'createdAt'>,
): Account {
const profileImage = params.profileImage ? new Url(params.profileImage) : new None();
const createdAt = DateTime.now();
const account = new Account(id, email, isPrimary, name, provider, profileImage, owner, createdAt);
const account = new Account(
new IdAccount(params.id),
new Email(params.email),
params.isPrimary,
new AccountName(params.name),
params.provider,
profileImage,
new IdEntity(params.userId),
createdAt,
);
return account;
}

Expand Down
14 changes: 7 additions & 7 deletions backend/src/modules/category/core/model/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ export default class Category extends Entity {
}

public static create(
key: string,
id: IdCategory,
name: CategoryName,
color: CategoryColor,
actorId: IdEntity,
projectID: IdEntity,
params: CategoryParams & { key: string; actorId: string },
) {
const id = new IdCategory(params.id);
const name = new CategoryName(params.name);
const color = new CategoryColor(params.color as AllowedColors);
const projectID = new IdEntity(params.idProject);
const actorId = new IdEntity(params.actorId);
const category = new Category(
name,
color,
projectID,
id
);

category.addEvent(new CategoryCreated(key, DateTime.now(), actorId, projectID, id));
category.addEvent(new CategoryCreated(params.key, DateTime.now(), actorId, projectID, id));
return category;
}

Expand Down
18 changes: 11 additions & 7 deletions backend/src/modules/checklist/core/model/CheckList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@ export default class CheckList extends Entity {
}

public static create(
id: IdCheckList,
owner: IdEntity,
name: CheckListName,
actor: IdEntity,
key: string,
items: ChecklistItem[] = [],
params: Pick<CheckListParams, 'id' | 'idOwner' | 'name'> & {
actor: string;
key: string;
items?: CheckListParams['items'];
},
): CheckList {
const id = new IdCheckList(params.id);
const owner = new IdEntity(params.idOwner);
const name = new CheckListName(params.name);
const actor = new IdEntity(params.actor);
const items = (params.items ?? []).map((item) => ChecklistItem.fromPrimitives(item));
const checklist = new CheckList(id, owner, name, items, new PercentageCompleted(0));
checklist.recalculateCompletedPercentage();
checklist.addEvent(new CheckListCreated(key, DateTime.now(), actor, checklist.getTaskId(), id, checklist.toPrimitives()));
checklist.addEvent(new CheckListCreated(params.key, DateTime.now(), actor, checklist.getTaskId(), id, checklist.toPrimitives()));
return checklist;
}

Expand Down
19 changes: 11 additions & 8 deletions backend/src/modules/comment/core/model/Comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ export default class Comment extends Entity {
}

public static create(
idComment: IdComment,
creator: IdEntity,
task: IdEntity,
content: Text,
key: string,
mentions?: Collection
params: CommentParams & { key: string }
): Comment {
const mentionsCollection = mentions || new Collection([], [], []);
const idComment = new IdComment(params.id);
const creator = new IdEntity(params.creator);
const task = new IdEntity(params.idTask);
const content = new Text(params.content);
const mentionsCollection = new Collection(
params.mentions.map((mention) => new IdEntity(mention)),
[],
[]
);
const comment = new Comment(idComment, creator, task ,content, mentionsCollection);
comment.addEvent(new CommentCreated(key, DateTime.now(), creator, task, idComment, comment.toPrimitives()));
comment.addEvent(new CommentCreated(params.key, DateTime.now(), creator, task, idComment, comment.toPrimitives()));
return comment;
}

Expand Down
8 changes: 6 additions & 2 deletions backend/src/modules/invitation/core/model/Invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ export default class Invitation extends Entity {
this.guest = guest;
}

public static create(key: string, id: IdInvitation, host: IdEntity, projectId: IdEntity, guest: Email): Invitation {
public static create(params: Omit<InvitationParams, 'status'> & { key: string }): Invitation {
const id = new IdInvitation(params.id);
const host = new IdEntity(params.host);
const projectId = new IdEntity(params.projectId);
const guest = new Email(params.guest);
const invitation = new Invitation(id, host, projectId, InvitationStatus.pending(), guest);
invitation.addEvent(new InvitationCreated(key, DateTime.now(), host, host, id, invitation.toPrimitives()));
invitation.addEvent(new InvitationCreated(params.key, DateTime.now(), host, host, id, invitation.toPrimitives()));
return invitation;
}

Expand Down
14 changes: 7 additions & 7 deletions backend/src/modules/link/core/model/Link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export default class Link extends Entity {
}

public static create(
id: LinkId,
task: IdEntity,
url: Url,
key: string,
actor: IdEntity,
visibleText?: Text,
params: LinkParams & { key: string; actor: string },
): Link {
const id = new LinkId(params.id);
const task = new IdEntity(params.idTask);
const url = new Url(params.url);
const actor = new IdEntity(params.actor);
const visibleText = params.visibleText ? new Text(params.visibleText) : undefined;
const link = new Link(id, task, url, visibleText ?? new None());
link.addEvent(new LinkCreated(key, DateTime.now(), actor, task, id, link.toPrimitives()));
link.addEvent(new LinkCreated(params.key, DateTime.now(), actor, task, id, link.toPrimitives()));
return link;
}

Expand Down
11 changes: 6 additions & 5 deletions backend/src/modules/list/core/model/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ export default class List extends Entity{
}

public static create(
id: ListId,
title: ListTitle,
position: PositiveInteger,
tasks: TaskList[],
projectId: IdEntity
params: Pick<ListParams, 'id' | 'title' | 'position' | 'tasks' | 'projectId'>
){
const id = new ListId(params.id);
const title = new ListTitle(new Text(params.title));
const position = new PositiveInteger(params.position);
const projectId = new IdEntity(params.projectId);
const tasks = params.tasks;
const list = new List(id, title, position, tasks, projectId);
return list;
}
Expand Down
17 changes: 8 additions & 9 deletions backend/src/modules/member/core/model/Member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ export default class Member extends Entity {
}

public static create(
idMember:IdMember,
idProject: IdEntity,
idAccount: IdEntity,
role: MemberRole,
status: MemberStatus,
modifier: IdEntity,
key: string

params: Omit<MemberParams, 'projectMetadata'> & { actor: string; key: string }
): Member {
const idMember = new IdMember(params.id);
const idProject = new IdEntity(params.idProject);
const idAccount = new IdEntity(params.idAccount);
const role = new MemberRole(params.role);
const status = MemberStatus.create(params.status);
const actor = new IdEntity(params.actor);

const member = new Member(
idMember,
Expand All @@ -56,7 +55,7 @@ export default class Member extends Entity {
);

member.addEvent(
new MemberAddedToProject(key, DateTime.now(), modifier, idProject, idMember, member.toPrimitives()),
new MemberAddedToProject(params.key, DateTime.now(), actor, idProject, idMember, member.toPrimitives()),
);
return member;
}
Expand Down
15 changes: 7 additions & 8 deletions backend/src/modules/notification/core/model/Notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ export default class Notification extends Entity {
}

public static create(
key: string,
idNotification: IdNotification,
eventKey: string,
idUser: IdEntity,
actor: IdEntity,
type: NotificationTypes,
params: Omit<NotificationParams, 'status'> & { key: string; actor: string },
): Notification {
const notification = new Notification(idNotification, eventKey, NotificationStatus.unread(), type, idUser);
const idNotification = new IdNotification(params.id);
const idUser = new IdEntity(params.idUser);
const actor = new IdEntity(params.actor);
const type = params.type as NotificationTypes;
const notification = new Notification(idNotification, params.eventKey, NotificationStatus.unread(), type, idUser);
notification.addEvent(
new NotificationCreated(key, DateTime.now(), actor, idUser, idNotification, notification.toPrimitives()),
new NotificationCreated(params.key, DateTime.now(), actor, idUser, idNotification, notification.toPrimitives()),
);
return notification;
}
Expand Down
40 changes: 21 additions & 19 deletions backend/src/modules/project/core/model/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,36 @@ export default class Project extends Entity {
}

public static create(
id: ProjectId,
projectName: ProjectName,
projectDescription: ProjectDescription | None,
background: ProjectBackGroundImage | ProjectBackGroundColor,
lists: ProjectList[],
commentAuthorization: ProjectSetting,
inmutableComment: boolean,
addMemberSettings: ProjectSetting,
createResourcesSettings: ProjectSetting,
showCompletedTasks: boolean,
actor: IdEntity,
key: string,
params: Omit<ProjectParams, 'status' | 'invitaionToken'> & { actor: string; key: string },
): Project {
const id = new ProjectId(params.id);
const projectName = new ProjectName(params.projectName);
const projectDescription = params.projectDescription ? new ProjectDescription(params.projectDescription) : new None();
const imageParams = params.background as ProjectBackgroundImageParams;
const background = params.backgroundType === AllowedBackgroundType.image
? new ProjectBackGroundImage(new Attachment(
new Url(imageParams.url),
imageParams.type as AllowedAttachments,
new Text(imageParams.name),
new IntNumber(imageParams.size),
))
: new ProjectBackGroundColor(params.background as AllowedColors);
const actor = new IdEntity(params.actor);
const project = new Project(
id,
ProjectStatus.open(),
projectName,
projectDescription,
background,
lists,
commentAuthorization,
inmutableComment,
addMemberSettings,
createResourcesSettings,
showCompletedTasks,
params.lists,
new ProjectSetting(params.commentAuthorization),
params.inmutableComment,
new ProjectSetting(params.addMemberSettings),
new ProjectSetting(params.createResourcesSettings),
params.showCompletedTasks,
);

project.addEvent(new ProjectCreated(key, DateTime.now(), actor, id, project.toPrimitives()));
project.addEvent(new ProjectCreated(params.key, DateTime.now(), actor, id, project.toPrimitives()));
return project;
}

Expand Down
30 changes: 15 additions & 15 deletions backend/src/modules/task/core/model/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,21 @@ export default class Task extends Entity {

//mutable methods
public static create(
title: TaskTitle,
listContainer: IdEntity,
positionInList: PositiveInteger,
state: TaskState,
archived: boolean,
id: TaskId,
idProject: IdEntity,
description: Text | None,
startDate: DateTime | None,
dueDate: DateTime | None,
categories: Collection,
assigned: Collection,
actor: IdEntity,
key: string
params: Omit<TaskParams, 'isOverdue' | 'isStarted'> & { actor: string; key: string }
): Task {
const title = new TaskTitle(params.title);
const listContainer = new IdEntity(params.listContainer);
const positionInList = new PositiveInteger(params.positionInList);
const state = TaskState.create(params.state as AllowedTaskState);
const archived = params.archived;
const id = new TaskId(params.id);
const idProject = new IdEntity(params.idProject);
const description = params.description ? new Text(params.description) : new None();
const startDate = params.startDate instanceof Date ? DateTime.create(params.startDate) : new None();
const dueDate = params.dueDate instanceof Date ? DateTime.create(params.dueDate) : new None();
const categories = new Collection(params.categories.map((category) => new IdEntity(category)), [], []);
const assigned = new Collection(params.assigned.map((assign) => new IdEntity(assign)), [], []);
const actor = new IdEntity(params.actor);

const task = new Task(
title,
Expand All @@ -154,7 +154,7 @@ export default class Task extends Entity {
);

task.addEvent(
new TaskCreated(key, DateTime.now(), actor, task.getIdProject(), task.getID(), task.toPrimitives()),
new TaskCreated(params.key, DateTime.now(), actor, task.getIdProject(), task.getID(), task.toPrimitives()),
);
return task;
}
Expand Down
17 changes: 11 additions & 6 deletions backend/src/modules/taskAttachment/core/model/TaskAttachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@ export default class TaskAttachment extends Entity {
}

public static create(
attachment: Attachment,
id: TaskAttachmentId,
task: IdEntity,
actor: IdEntity,
key: string,
params: TaskAttachmentParams & { actor: string; key: string },
): TaskAttachment {
const attachment = new Attachment(
new Url(params.attachment.url),
params.attachment.type as AllowedAttachments,
new Text(params.attachment.name),
new IntNumber(params.attachment.size),
);
const id = new TaskAttachmentId(params.id);
const task = new IdEntity(params.idTask);
const actor = new IdEntity(params.actor);
const taskAttachment = new TaskAttachment(attachment, id, task);
taskAttachment.addEvent(
new TaskAttachmentCreated(
key,
params.key,
DateTime.now(),
actor,
task,
Expand Down
28 changes: 14 additions & 14 deletions backend/tests/modules/account/core/model/Account.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import Account from '../../../../../src/modules/account/core/model/Account';
import IdAccount from '../../../../../src/modules/account/core/objects/IdAccount';
import IdEntity from '../../../../../src/modules/shared/core/objects/IdEntity';
import ID from '../../../../../src/modules/shared/core/objects/ID';
import Email from '../../../../../src/modules/shared/core/objects/Email';
import AccountName from '../../../../../src/modules/account/core/objects/AccountName';
import Url from '../../../../../src/modules/shared/core/objects/URL';
import None from '../../../../../src/modules/shared/core/objects/None';
import InvalidParameters from '../../../../../src/modules/shared/core/errors/InvalidParameters';
import { describe, it, expect } from 'vitest';

describe('Account model', () => {
it('create builds account with current signature', () => {
const id = new IdAccount(ID.generateId().toString());
const owner = new IdEntity(ID.generateId().toString());
const email = new Email('test@example.com');
const name = new AccountName('Test');
const profileImage = new Url('https://example.com/photo.png');
it('create builds account with primitive params', () => {
const id = ID.generateId().toString();
const userId = ID.generateId().toString();

const account = Account.create(id, email, name, 'google', profileImage, owner, true);
const account = Account.create({
id,
userId,
email: 'test@example.com',
name: 'Test',
provider: 'google',
profileImage: 'https://example.com/photo.png',
isPrimary: true,
});
const primitives = account.toPrimitives();

expect(primitives.id).toBe(id.getID());
expect(primitives.userId).toBe(owner.getID());
expect(primitives.id).toBe(id);
expect(primitives.userId).toBe(userId);
expect(primitives.email).toBe('test@example.com');
expect(primitives.name).toBe('Test');
expect(primitives.provider).toBe('google');
Expand Down
Loading
Loading