feat: Update entity types to include specific ID types and adjust DTO mappings
This commit is contained in:
parent
86f4c757e3
commit
115f2667f6
@ -3,7 +3,7 @@ package entities
|
|||||||
import "github.com/oklog/ulid/v2"
|
import "github.com/oklog/ulid/v2"
|
||||||
|
|
||||||
type Customer struct {
|
type Customer struct {
|
||||||
ID ulid.ULID
|
EntityBase
|
||||||
Name string
|
Name string
|
||||||
CompanyID int
|
CompanyID int
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package entities
|
|||||||
import "github.com/oklog/ulid/v2"
|
import "github.com/oklog/ulid/v2"
|
||||||
|
|
||||||
type Project struct {
|
type Project struct {
|
||||||
ID ulid.ULID
|
EntityBase
|
||||||
Name string
|
Name string
|
||||||
CustomerID int
|
CustomerID int
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
import { BaseEntity } from "./base";
|
import { BaseEntity } from "./base";
|
||||||
import { ActivityDto, ActivityCreateDto, ActivityUpdateDto } from "./dto";
|
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 => ({
|
export const mapActivityDtoToActivity = (dto: ActivityDto): Activity => ({
|
||||||
...dto,
|
...dto,
|
||||||
|
id: dto.id as ActivityId,
|
||||||
createdAt: new Date(dto.createdAt),
|
createdAt: new Date(dto.createdAt),
|
||||||
updatedAt: new Date(dto.updatedAt),
|
updatedAt: new Date(dto.updatedAt),
|
||||||
lastEditorID: dto.lastEditorID as UserId,
|
lastEditorID: dto.lastEditorID as UserId,
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
import { UserId } from "./value-ids";
|
||||||
|
|
||||||
export type BaseEntity = {
|
export type BaseEntity = {
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
lastEditorID: string;
|
lastEditorID: UserId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
import { BaseEntity } from "./base";
|
import { BaseEntity } from "./base";
|
||||||
import { CompanyDto, CompanyCreateDto, CompanyUpdateDto } from "./dto";
|
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 => ({
|
export const mapCompanyDtoToCompany = (dto: CompanyDto): Company => ({
|
||||||
...dto,
|
...dto,
|
||||||
|
id: dto.id as CompanyId,
|
||||||
createdAt: new Date(dto.createdAt),
|
createdAt: new Date(dto.createdAt),
|
||||||
updatedAt: new Date(dto.updatedAt),
|
updatedAt: new Date(dto.updatedAt),
|
||||||
lastEditorID: dto.lastEditorID as UserId,
|
lastEditorID: dto.lastEditorID as UserId,
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
import { BaseEntity } from "./base";
|
import { BaseEntity } from "./base";
|
||||||
import { CustomerDto, CustomerCreateDto, CustomerUpdateDto } from "./dto";
|
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 => ({
|
export const mapCustomerDtoToCustomer = (dto: CustomerDto): Customer => ({
|
||||||
...dto,
|
...dto,
|
||||||
|
id: dto.id as CustomerId,
|
||||||
createdAt: new Date(dto.createdAt),
|
createdAt: new Date(dto.createdAt),
|
||||||
updatedAt: new Date(dto.updatedAt),
|
updatedAt: new Date(dto.updatedAt),
|
||||||
lastEditorID: dto.lastEditorID as UserId,
|
lastEditorID: dto.lastEditorID as UserId,
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
import { BaseEntity } from "./base";
|
import { BaseEntity } from "./base";
|
||||||
import { ProjectDto, ProjectCreateDto, ProjectUpdateDto } from "./dto";
|
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 => ({
|
export const mapProjectDtoToProject = (dto: ProjectDto): Project => ({
|
||||||
...dto,
|
...dto,
|
||||||
|
id: dto.id as ProjectId,
|
||||||
createdAt: new Date(dto.createdAt),
|
createdAt: new Date(dto.createdAt),
|
||||||
updatedAt: new Date(dto.updatedAt),
|
updatedAt: new Date(dto.updatedAt),
|
||||||
lastEditorID: dto.lastEditorID as UserId,
|
lastEditorID: dto.lastEditorID as UserId,
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { BaseEntity } from "./base";
|
import { BaseEntity } from "./base";
|
||||||
import { TimeEntryDto, TimeEntryCreateDto, TimeEntryUpdateDto } from "./dto";
|
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;
|
start: Date;
|
||||||
end: Date;
|
end: Date;
|
||||||
userId: UserId;
|
userId: UserId;
|
||||||
@ -12,6 +13,7 @@ export type TimeEntry = Omit<TimeEntryDto, "start" | "end" | "userId" | "project
|
|||||||
|
|
||||||
export const mapTimeEntryDtoToTimeEntry = (dto: TimeEntryDto): TimeEntry => ({
|
export const mapTimeEntryDtoToTimeEntry = (dto: TimeEntryDto): TimeEntry => ({
|
||||||
...dto,
|
...dto,
|
||||||
|
id: dto.id as TimeEntryId,
|
||||||
start: new Date(dto.start),
|
start: new Date(dto.start),
|
||||||
end: new Date(dto.end),
|
end: new Date(dto.end),
|
||||||
userId: dto.userId.toString() as UserId,
|
userId: dto.userId.toString() as UserId,
|
||||||
|
@ -2,10 +2,13 @@ import { BaseEntity } from "./base";
|
|||||||
import { UserDto, UserCreateDto, UserUpdateDto } from "./dto";
|
import { UserDto, UserCreateDto, UserUpdateDto } from "./dto";
|
||||||
import { UserId } from "./value-ids";
|
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 => ({
|
export const mapUserDtoToUser = (dto: UserDto): User => ({
|
||||||
...dto,
|
...dto,
|
||||||
|
id: dto.id as UserId,
|
||||||
createdAt: new Date(dto.createdAt),
|
createdAt: new Date(dto.createdAt),
|
||||||
updatedAt: new Date(dto.updatedAt),
|
updatedAt: new Date(dto.updatedAt),
|
||||||
lastEditorID: dto.lastEditorID as UserId,
|
lastEditorID: dto.lastEditorID as UserId,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user