Skip to content

Commit

Permalink
[スキーマ変更] readyAt: Date <- orderReady: boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
toririm committed Oct 21, 2024
1 parent 113c496 commit 733ae64
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
9 changes: 5 additions & 4 deletions common/models/order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ describe("[unit] order entity", () => {

test("beReady", () => {
const order = OrderEntity.createNew({ orderId: 2024 });
expect(order.orderReady).toBe(false);
expect(order.readyAt).toBe(null);

order.beReady();
expect(order.orderReady).toBe(true);
expect(order.readyAt).not.toBe(null);
expect(order.readyAt).toBeInstanceOf(Date);
});

test("beServed", () => {
Expand Down Expand Up @@ -102,10 +103,10 @@ describe("[unit] order entity", () => {
id: "1",
orderId: 99999,
createdAt: new Date(),
readyAt: null,
servedAt: null,
items: itemEntities.slice(0, 1),
total: 900,
orderReady: false,
description: null,
billingAmount: 900,
received: 0,
Expand Down Expand Up @@ -159,10 +160,10 @@ describe("[unit] order entity", () => {
id: "1",
orderId: 99999,
createdAt: new Date(),
readyAt: null,
servedAt: null,
items: itemEntities,
total: 900,
orderReady: false,
description: null,
billingAmount: 900,
received: 0,
Expand Down
29 changes: 17 additions & 12 deletions common/models/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export const orderSchema = z.object({
id: z.string().optional(), // Firestore のドキュメント ID
orderId: z.number(),
createdAt: z.date(),
readyAt: z.date().nullable(),
servedAt: z.date().nullable(),
items: z.array(itemSchema.required()),
total: z.number(), // sum of item.price
orderReady: z.boolean(),
description: z.string().nullable(),
billingAmount: z.number(), // total - discount
received: z.number(), // お預かり金額
Expand All @@ -31,10 +31,10 @@ export class OrderEntity implements Order {
private readonly _id: string | undefined,
private _orderId: number,
private _createdAt: Date,
private _readyAt: Date | null,
private _servedAt: Date | null,
private _items: WithId<ItemEntity>[],
private _total: number,
private _orderReady: boolean,
private _description: string | null,
private _billingAmount: number,
private _received: number,
Expand All @@ -50,9 +50,9 @@ export class OrderEntity implements Order {
orderId,
new Date(),
null,
null,
[],
0,
false,
null,
0,
0,
Expand All @@ -72,10 +72,10 @@ export class OrderEntity implements Order {
order.id,
order.orderId,
order.createdAt,
order.readyAt,
order.servedAt,
order.items.map((item) => ItemEntity.fromItem(item)),
order.total,
order.orderReady,
order.description,
order.billingAmount,
order.received,
Expand Down Expand Up @@ -105,6 +105,10 @@ export class OrderEntity implements Order {
return this._createdAt;
}

get readyAt() {
return this._readyAt;
}

get servedAt() {
return this._servedAt;
}
Expand All @@ -124,10 +128,6 @@ export class OrderEntity implements Order {
return this._total;
}

get orderReady() {
return this._orderReady;
}

get description() {
return this._description;
}
Expand Down Expand Up @@ -190,15 +190,20 @@ export class OrderEntity implements Order {
* オーダーを準備完了状態に変更する
*/
beReady() {
// orderReady は false -> true にしか変更できないようにする
this._orderReady = true;
this._readyAt = new Date();
}

/**
* 準備完了状態を取り消す
*/
undoReady() {
this._readyAt = null;
}

/**
* オーダーを提供済み状態に変更する
*/
beServed() {
// servedAt は null -> Date にしか変更できないようにする
this._servedAt = new Date();
}

Expand Down Expand Up @@ -251,10 +256,10 @@ export class OrderEntity implements Order {
id: this.id,
orderId: this.orderId,
createdAt: this.createdAt,
readyAt: this.readyAt,
servedAt: this.servedAt,
items: this.items.map((item) => item.toItem()),
total: this.total,
orderReady: this.orderReady,
description: this.description,
billingAmount: this.billingAmount,
received: this.received,
Expand Down

0 comments on commit 733ae64

Please sign in to comment.