From 8942c3bb0247c25e9f9b539e539ad31781b47d0f Mon Sep 17 00:00:00 2001 From: toririm Date: Sat, 7 Sep 2024 19:57:38 +0900 Subject: [PATCH] impl: ItemEntity --- app/models/item.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/models/item.ts b/app/models/item.ts index 5c4982d8..46765bd2 100644 --- a/app/models/item.ts +++ b/app/models/item.ts @@ -17,3 +17,20 @@ export type Item = z.infer; export type ItemWithId = Required; export type ItemType = Pick["type"]; + +export class ItemEntity implements Item { + private constructor( + public readonly id: string | undefined, + public readonly name: string, + public readonly price: number, + public readonly type: ItemType, + ) {} + + static createNew({ name, price, type }: Item): ItemEntity { + return new ItemEntity(undefined, name, price, type); + } + + static fromItem(item: ItemWithId): ItemEntity { + return new ItemEntity(item.id, item.name, item.price, item.type); + } +}