From 86f4c757e33497fb74ad767ad043d8dacc06f794 Mon Sep 17 00:00:00 2001 From: Jean Jacques Avril Date: Sun, 9 Mar 2025 20:37:03 +0000 Subject: [PATCH] feat: Refactor entity types to include BaseEntity properties and update date handling --- frontend/src/types/activity.ts | 7 ++++++- frontend/src/types/company.ts | 7 ++++++- frontend/src/types/customer.ts | 7 ++++++- frontend/src/types/project.ts | 7 ++++++- frontend/src/types/timeentry.ts | 15 +++++++++++++-- frontend/src/types/user.ts | 6 +++++- frontend/src/types/value-ids.ts | 3 ++- 7 files changed, 44 insertions(+), 8 deletions(-) diff --git a/frontend/src/types/activity.ts b/frontend/src/types/activity.ts index 5d5fcdc..acb506a 100644 --- a/frontend/src/types/activity.ts +++ b/frontend/src/types/activity.ts @@ -1,9 +1,14 @@ +import { BaseEntity } from "./base"; import { ActivityDto, ActivityCreateDto, ActivityUpdateDto } from "./dto"; +import { UserId } from "./value-ids"; -export type Activity = ActivityDto; +export type Activity = Omit & BaseEntity; export const mapActivityDtoToActivity = (dto: ActivityDto): Activity => ({ ...dto, + createdAt: new Date(dto.createdAt), + updatedAt: new Date(dto.updatedAt), + lastEditorID: dto.lastEditorID as UserId, }); export type ActivityCreate = ActivityCreateDto; diff --git a/frontend/src/types/company.ts b/frontend/src/types/company.ts index d19a311..5ef59e5 100644 --- a/frontend/src/types/company.ts +++ b/frontend/src/types/company.ts @@ -1,9 +1,14 @@ +import { BaseEntity } from "./base"; import { CompanyDto, CompanyCreateDto, CompanyUpdateDto } from "./dto"; +import { UserId } from "./value-ids"; -export type Company = CompanyDto; +export type Company = Omit & BaseEntity; export const mapCompanyDtoToCompany = (dto: CompanyDto): Company => ({ ...dto, + createdAt: new Date(dto.createdAt), + updatedAt: new Date(dto.updatedAt), + lastEditorID: dto.lastEditorID as UserId, }); export type CompanyCreate = CompanyCreateDto; diff --git a/frontend/src/types/customer.ts b/frontend/src/types/customer.ts index 4240c11..9a2752a 100644 --- a/frontend/src/types/customer.ts +++ b/frontend/src/types/customer.ts @@ -1,9 +1,14 @@ +import { BaseEntity } from "./base"; import { CustomerDto, CustomerCreateDto, CustomerUpdateDto } from "./dto"; +import { UserId } from "./value-ids"; -export type Customer = CustomerDto; +export type Customer = Omit & BaseEntity; export const mapCustomerDtoToCustomer = (dto: CustomerDto): Customer => ({ ...dto, + createdAt: new Date(dto.createdAt), + updatedAt: new Date(dto.updatedAt), + lastEditorID: dto.lastEditorID as UserId, }); export type CustomerCreate = CustomerCreateDto; diff --git a/frontend/src/types/project.ts b/frontend/src/types/project.ts index ba052a4..75a6cf7 100644 --- a/frontend/src/types/project.ts +++ b/frontend/src/types/project.ts @@ -1,9 +1,14 @@ +import { BaseEntity } from "./base"; import { ProjectDto, ProjectCreateDto, ProjectUpdateDto } from "./dto"; +import { UserId } from "./value-ids"; -export type Project = ProjectDto; +export type Project = Omit & BaseEntity; export const mapProjectDtoToProject = (dto: ProjectDto): Project => ({ ...dto, + createdAt: new Date(dto.createdAt), + updatedAt: new Date(dto.updatedAt), + lastEditorID: dto.lastEditorID as UserId, }); export type ProjectCreate = ProjectCreateDto; diff --git a/frontend/src/types/timeentry.ts b/frontend/src/types/timeentry.ts index 4f5a31d..4fc674f 100644 --- a/frontend/src/types/timeentry.ts +++ b/frontend/src/types/timeentry.ts @@ -1,14 +1,25 @@ +import { BaseEntity } from "./base"; import { TimeEntryDto, TimeEntryCreateDto, TimeEntryUpdateDto } from "./dto"; +import { UserId, ProjectId, ActivityId } from "./value-ids"; -export type TimeEntry = Omit & { +export type TimeEntry = Omit & { start: Date; end: Date; -}; + userId: UserId; + projectId: ProjectId; + activityId: ActivityId; +} & BaseEntity; export const mapTimeEntryDtoToTimeEntry = (dto: TimeEntryDto): TimeEntry => ({ ...dto, start: new Date(dto.start), end: new Date(dto.end), + userId: dto.userId.toString() as UserId, + projectId: dto.projectId.toString() as ProjectId, + activityId: dto.activityId.toString() as ActivityId, + createdAt: new Date(dto.createdAt), + updatedAt: new Date(dto.updatedAt), + lastEditorID: dto.lastEditorID as UserId, }); export type TimeEntryCreate = Omit & { diff --git a/frontend/src/types/user.ts b/frontend/src/types/user.ts index ddd9cf2..04cd7a8 100644 --- a/frontend/src/types/user.ts +++ b/frontend/src/types/user.ts @@ -1,10 +1,14 @@ import { BaseEntity } from "./base"; import { UserDto, UserCreateDto, UserUpdateDto } from "./dto"; +import { UserId } from "./value-ids"; -export type User = Omit; +export type User = Omit & BaseEntity; export const mapUserDtoToUser = (dto: UserDto): User => ({ ...dto, + createdAt: new Date(dto.createdAt), + updatedAt: new Date(dto.updatedAt), + lastEditorID: dto.lastEditorID as UserId, }); export type UserCreate = Omit; diff --git a/frontend/src/types/value-ids.ts b/frontend/src/types/value-ids.ts index ddca1cf..03759bb 100644 --- a/frontend/src/types/value-ids.ts +++ b/frontend/src/types/value-ids.ts @@ -6,4 +6,5 @@ export type TimeEntryId = ValueId<"TimeEntryId">; export type CompanyId = ValueId<"CompanyId">; export type UserId = ValueId<"UserId">; export type RoleId = ValueId<"RoleId">; -export type PermissionId = ValueId<"PermissionId">; \ No newline at end of file +export type PermissionId = ValueId<"PermissionId">; +export type ActivityId = ValueId<"ActivityId">;