feat: Update entity types to include specific ID types and adjust DTO mappings

This commit is contained in:
Jean Jacques Avril 2025-03-09 20:44:46 +00:00
parent 86f4c757e3
commit 115f2667f6
9 changed files with 33 additions and 14 deletions

View File

@ -3,7 +3,7 @@ package entities
import "github.com/oklog/ulid/v2"
type Customer struct {
ID ulid.ULID
EntityBase
Name string
CompanyID int
}

View File

@ -3,7 +3,7 @@ package entities
import "github.com/oklog/ulid/v2"
type Project struct {
ID ulid.ULID
EntityBase
Name string
CustomerID int
}

View File

@ -1,11 +1,14 @@
import { BaseEntity } from "./base";
import { ActivityDto, ActivityCreateDto, ActivityUpdateDto } from "./dto";
import { UserId } from "./value-ids";
import { UserId, ActivityId } from "./value-ids";
export type Activity = Omit<ActivityDto, "createdAt" | "updatedAt" | "lastEditorID"> & BaseEntity;
export type Activity = Omit<ActivityDto, "id" | "createdAt" | "updatedAt" | "lastEditorID"> & {
id: ActivityId;
} & BaseEntity;
export const mapActivityDtoToActivity = (dto: ActivityDto): Activity => ({
...dto,
id: dto.id as ActivityId,
createdAt: new Date(dto.createdAt),
updatedAt: new Date(dto.updatedAt),
lastEditorID: dto.lastEditorID as UserId,

View File

@ -1,6 +1,8 @@
import { UserId } from "./value-ids";
export type BaseEntity = {
createdAt: Date;
updatedAt: Date;
lastEditorID: string;
lastEditorID: UserId;
};

View File

@ -1,11 +1,14 @@
import { BaseEntity } from "./base";
import { CompanyDto, CompanyCreateDto, CompanyUpdateDto } from "./dto";
import { UserId } from "./value-ids";
import { UserId, CompanyId } from "./value-ids";
export type Company = Omit<CompanyDto, "createdAt" | "updatedAt" | "lastEditorID"> & BaseEntity;
export type Company = Omit<CompanyDto, "id" | "createdAt" | "updatedAt" | "lastEditorID"> & {
id: CompanyId;
} & BaseEntity;
export const mapCompanyDtoToCompany = (dto: CompanyDto): Company => ({
...dto,
id: dto.id as CompanyId,
createdAt: new Date(dto.createdAt),
updatedAt: new Date(dto.updatedAt),
lastEditorID: dto.lastEditorID as UserId,

View File

@ -1,11 +1,14 @@
import { BaseEntity } from "./base";
import { CustomerDto, CustomerCreateDto, CustomerUpdateDto } from "./dto";
import { UserId } from "./value-ids";
import { UserId, CustomerId } from "./value-ids";
export type Customer = Omit<CustomerDto, "createdAt" | "updatedAt" | "lastEditorID"> & BaseEntity;
export type Customer = Omit<CustomerDto, "id" | "createdAt" | "updatedAt" | "lastEditorID"> & {
id: CustomerId;
} & BaseEntity;
export const mapCustomerDtoToCustomer = (dto: CustomerDto): Customer => ({
...dto,
id: dto.id as CustomerId,
createdAt: new Date(dto.createdAt),
updatedAt: new Date(dto.updatedAt),
lastEditorID: dto.lastEditorID as UserId,

View File

@ -1,11 +1,14 @@
import { BaseEntity } from "./base";
import { ProjectDto, ProjectCreateDto, ProjectUpdateDto } from "./dto";
import { UserId } from "./value-ids";
import { UserId, ProjectId } from "./value-ids";
export type Project = Omit<ProjectDto, "createdAt" | "updatedAt" | "lastEditorID"> & BaseEntity;
export type Project = Omit<ProjectDto, "id" | "createdAt" | "updatedAt" | "lastEditorID"> & {
id: ProjectId;
} & BaseEntity;
export const mapProjectDtoToProject = (dto: ProjectDto): Project => ({
...dto,
id: dto.id as ProjectId,
createdAt: new Date(dto.createdAt),
updatedAt: new Date(dto.updatedAt),
lastEditorID: dto.lastEditorID as UserId,

View File

@ -1,8 +1,9 @@
import { BaseEntity } from "./base";
import { TimeEntryDto, TimeEntryCreateDto, TimeEntryUpdateDto } from "./dto";
import { UserId, ProjectId, ActivityId } from "./value-ids";
import { UserId, ProjectId, ActivityId, TimeEntryId } from "./value-ids";
export type TimeEntry = Omit<TimeEntryDto, "start" | "end" | "userId" | "projectId" | "activityId" | "lastEditorID" | "createdAt" | "updatedAt"> & {
export type TimeEntry = Omit<TimeEntryDto, "id" | "start" | "end" | "userId" | "projectId" | "activityId" | "lastEditorID" | "createdAt" | "updatedAt"> & {
id: TimeEntryId;
start: Date;
end: Date;
userId: UserId;
@ -12,6 +13,7 @@ export type TimeEntry = Omit<TimeEntryDto, "start" | "end" | "userId" | "project
export const mapTimeEntryDtoToTimeEntry = (dto: TimeEntryDto): TimeEntry => ({
...dto,
id: dto.id as TimeEntryId,
start: new Date(dto.start),
end: new Date(dto.end),
userId: dto.userId.toString() as UserId,

View File

@ -2,10 +2,13 @@ import { BaseEntity } from "./base";
import { UserDto, UserCreateDto, UserUpdateDto } from "./dto";
import { UserId } from "./value-ids";
export type User = Omit<UserDto, "createdAt" | "updatedAt" | "lastEditorID"> & BaseEntity;
export type User = Omit<UserDto, "id" | "createdAt" | "updatedAt" | "lastEditorID"> & {
id: UserId;
} & BaseEntity;
export const mapUserDtoToUser = (dto: UserDto): User => ({
...dto,
id: dto.id as UserId,
createdAt: new Date(dto.createdAt),
updatedAt: new Date(dto.updatedAt),
lastEditorID: dto.lastEditorID as UserId,