Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
toririm committed Sep 23, 2024
1 parent e02ac2a commit 41fea1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/models/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class ItemEntity implements Item {
public readonly name: string,
public readonly price: number,
public readonly type: ItemType,
public assignee: string | null = null,
public assignee: string | null,
) {}

static createNew({ name, price, type }: Omit<Item, "assignee">): ItemEntity {
Expand All @@ -47,6 +47,7 @@ export class ItemEntity implements Item {
item.name,
item.price,
item.type,
item.assignee,
) as WithId<ItemEntity>;
}
}
16 changes: 12 additions & 4 deletions app/routes/_header.casher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ const mockOrder: Order = {
// price: 300,
// },
],
assignee: "1st",
total: 0,
orderReady: false,
description: "",
};

export default function Casher() {
Expand Down Expand Up @@ -207,7 +207,13 @@ export const clientAction: ClientActionFunction = async ({ request }) => {

const newItem = submission.value;
// あとでマシなエラーハンドリングにする
const savedItem = await itemRepository.save(ItemEntity.createNew(newItem));
const savedItem = await itemRepository.save(
ItemEntity.createNew({
name: newItem.name,
price: newItem.price,
type: newItem.type,
}),
);

console.log("Document written with ID: ", savedItem.id);
return new Response(null, { status: 204 });
Expand Down Expand Up @@ -236,10 +242,11 @@ export class ItemEntity implements Item {
public readonly name: string,
public readonly price: number,
public readonly type: ItemType,
public assignee: string | null,
) {}

static createNew({ name, price, type }: Item): ItemEntity {
return new ItemEntity(undefined, name, price, type);
static createNew({ name, price, type }: Omit<Item, "assignee">): ItemEntity {
return new ItemEntity(undefined, name, price, type, null);
}

static fromItem(item: WithId<Item>): WithId<ItemEntity> {
Expand All @@ -248,6 +255,7 @@ export class ItemEntity implements Item {
item.name,
item.price,
item.type,
item.assignee,
) as WithId<ItemEntity>;
}
}

0 comments on commit 41fea1b

Please sign in to comment.