Skip to content

Commit

Permalink
impl: ItemEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
toririm committed Sep 7, 2024
1 parent 1c42686 commit 8942c3b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/models/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,20 @@ export type Item = z.infer<typeof itemSchema>;
export type ItemWithId = Required<Item>;

export type ItemType = Pick<Item, "type">["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);
}
}

0 comments on commit 8942c3b

Please sign in to comment.