Skip to content

Commit

Permalink
refactor(cms): manually sync orders api with Orders & OrderItem from …
Browse files Browse the repository at this point in the history
…merch
  • Loading branch information
mrzzy committed Apr 7, 2024
1 parent 89ea61c commit d002cd4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 69 deletions.
118 changes: 58 additions & 60 deletions apps/cms/src/collections/Orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,49 @@ const Orders: CollectionConfig = {
},
fields: [
// by default, payload generates an 'id' field each order automatically
// order items
{
name: "paymentGateway",
type: "text",
required: true,
},
{
name: "status",
label: "Order Status",
type: "select",
options: [
name: "items",
type: "array",
fields: [
// by default, payload generates an 'id' field each order automatically
{
value: "pending",
label: "Pending Payment",
name: "name",
type: "text",
required: true,
},
{
value: "paid",
label: "Payment Completed",
name: "image",
type: "text",
},
{
value: "delivered",
label: "Order Completed",
name: "color",
type: "text",
required: true,
},
{
name: "size",
type: "text",
required: true,
},
{
name: "price",
type: "number",
required: true,
},
{
name: "quantity",
type: "number",
required: true,
},
],
required: true,
},
{
name: "customerEmail",
type: "email",
required: true,
// direct paylaod to generate a OrderItem type
interfaceName: "OrderItem",
// validate: orders should not be empty
minRows: 1,
},
{
name: "transactionID",
name: "transaction_id",
label: "Transaction ID",
admin: {
description: "Transaction ID provided by Payment Gateway",
Expand All @@ -56,8 +67,8 @@ const Orders: CollectionConfig = {
required: true,
},
{
name: "orderDateTime",
label: "Ordered On",
name: "transaction_time",
label: "Transaction Time",
type: "date",
admin: {
date: {
Expand All @@ -66,50 +77,37 @@ const Orders: CollectionConfig = {
},
required: true,
},
// ordered items for this order
{
name: "orderItems",
type: "array",
fields: [
{
name: "image",
type: "upload",
relationTo: Media.slug,
// validation: only allow image filetypes
filterOptions: {
mimeType: { contains: "image" },
},
},
{
name: "quantity",
type: "number",
required: true,
},
{
name: "size",
type: "text",
required: true,
},
name: "payment_method",
label: "Payment Method",
type: "text",
required: true,
},
{
name: "customerEmail",
label: "Customer Email",
type: "email",
required: true,
},
{
name: "status",
label: "Order Status",
type: "select",
options: [
{
name: "price",
type: "number",
required: true,
value: "pending",
label: "Pending Payment",
},
{
name: "name",
type: "text",
required: true,
value: "paid",
label: "Payment Completed",
},
{
name: "colorway",
type: "text",
required: true,
value: "delivered",
label: "Order Completed",
},
],
// direct paylaod to generate a OrderItem type
interfaceName: "OrderItem",
// validate: orders should not be empty
minRows: 1,
required: true,
},
],
};
Expand Down
18 changes: 9 additions & 9 deletions packages/types/src/lib/cms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
*/

export type OrderItem = {
image?: string | Media;
quantity: number;
name: string;
image?: string;
color: string;
size: string;
price: number;
name: string;
colorway: string;
quantity: number;
id?: string;
}[];

Expand Down Expand Up @@ -101,12 +101,12 @@ export interface User {
}
export interface Order {
id: string;
paymentGateway: string;
status: 'pending' | 'paid' | 'delivered';
items?: OrderItem;
transaction_id: string;
transaction_time: string;
payment_method: string;
customerEmail: string;
transactionID: string;
orderDateTime: string;
orderItems?: OrderItem;
status: 'pending' | 'paid' | 'delivered';
updatedAt: string;
createdAt: string;
}

0 comments on commit d002cd4

Please sign in to comment.