Skip to content

Commit

Permalink
タイムスタンプの作成 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
BruCandy authored Nov 10, 2024
1 parent 59b0eae commit 4401a80
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/components/organisms/kitchen/OrderCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FC, memo } from "react"
import PropTypes from "prop-types"

type Props = {
orderTime: string
orderId: number
productNames: (string | null | undefined)[]
status: string
Expand All @@ -12,7 +13,8 @@ type Props = {
}

export const OrderCard: FC<Props> = memo((props) => {
const { orderId, productNames, status, quantities, tableNumber } = props
const { orderTime, orderId, productNames, status, quantities, tableNumber } =
props

return (
<Box
Expand All @@ -24,7 +26,7 @@ export const OrderCard: FC<Props> = memo((props) => {
p={4}
overflowY="auto"
>
<h1>{orderId}</h1>
<Text>{orderTime}</Text>
<Stack textAlign={"center"}>
{productNames.map((name, index) => (
<Text key={index}>
Expand Down Expand Up @@ -70,6 +72,7 @@ export const OrderCard: FC<Props> = memo((props) => {
OrderCard.displayName = "OrderCard"

OrderCard.propTypes = {
orderTime: PropTypes.string.isRequired,
orderId: PropTypes.number.isRequired,
productNames: PropTypes.arrayOf(PropTypes.string).isRequired,
status: PropTypes.string.isRequired,
Expand Down
13 changes: 13 additions & 0 deletions app/routes/kitchen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,22 @@ export default function Kitchen() {
)
const quantities = filteredDetails.map((detail) => detail.quantity)

const createTime = new Date(order.createTime).toLocaleString(
"ja-JP",
{
timeZone: "Asia/Tokyo",
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
},
)

return (
<WrapItem key={order.order_id} mx="auto">
<OrderCard
orderTime={createTime}
orderId={order.order_id}
productNames={productNames}
quantities={quantities}
Expand Down
1 change: 1 addition & 0 deletions app/type/typeorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export type TypeOrder = {
order_id: number
table_number: number
status: string
createTime: string
}
14 changes: 14 additions & 0 deletions prisma/migrations/20241108093853_add_order_date_time/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Orders" (
"order_id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"table_number" INTEGER NOT NULL,
"status" TEXT NOT NULL,
"createTime" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO "new_Orders" ("order_id", "status", "table_number") SELECT "order_id", "status", "table_number" FROM "Orders";
DROP TABLE "Orders";
ALTER TABLE "new_Orders" RENAME TO "Orders";
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ model Orders {
table_number Int
status String
orderDetails Order_details[]
createTime DateTime @default(now())
}

model Order_details{
Expand Down

0 comments on commit 4401a80

Please sign in to comment.