Skip to content

Commit

Permalink
feat(customer-order): add customer order function and controllers
Browse files Browse the repository at this point in the history
- Add a new file `customer-order.function.ts` to handle customer order related requests
- Implement `CustomerOrderControllerGet` function in `customer/controllers/order/get.ts` to handle GET requests for retrieving customer order details
- Implement `CustomerOrderControllerList` function in `customer/controllers/order/list.ts` to handle GET requests for listing customer orders
- Define request and response types for `CustomerOrderControllerGet` and `CustomerOrderControllerList`
- Update `order.schema.ts` to remove unused schemas and properties
- Update `order.types.ts` to remove unused types and properties
  • Loading branch information
jamalsoueidan committed Dec 9, 2023
1 parent 810ebb7 commit 136cad0
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 123 deletions.
20 changes: 20 additions & 0 deletions src/functions/customer-order.function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import "module-alias/register";

import { app } from "@azure/functions";

import { CustomerOrderControllerGet } from "./customer/controllers/order/get";
import { CustomerOrderControllerList } from "./customer/controllers/order/list";

app.http("customerOrderGet", {
methods: ["GET"],
authLevel: "anonymous",
route: "customer/{customerId?}/lineItemId/{lineItemId?}",
handler: CustomerOrderControllerGet,
});

app.http("customerOrderList", {
methods: ["GET"],
authLevel: "anonymous",
route: "customer/{customerId?}/orders/{year?}/{month?}",
handler: CustomerOrderControllerList,
});
24 changes: 24 additions & 0 deletions src/functions/customer/controllers/order/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { z } from "zod";
import { _ } from "~/library/handler";
import { NumberOrStringType } from "~/library/zod";
import { CustomerOrderServiceGet } from "../../services/order/get";

export type CustomerOrderControllerGetRequest = {
query: z.infer<typeof CustomerOrderControllerGetSchema>;
};

export const CustomerOrderControllerGetSchema = z.object({
customerId: NumberOrStringType,
lineItemId: NumberOrStringType,
});

export type CustomerOrderControllerGetResponse = Awaited<
ReturnType<typeof CustomerOrderServiceGet>
>;

export const CustomerOrderControllerGet = _(
async ({ query }: CustomerOrderControllerGetRequest) => {
const validateData = CustomerOrderControllerGetSchema.parse(query);
return CustomerOrderServiceGet(validateData);
}
);
26 changes: 26 additions & 0 deletions src/functions/customer/controllers/order/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { _ } from "~/library/handler";

import { z } from "zod";
import { NumberOrStringType } from "~/library/zod";
import { CustomerOrderServiceList } from "../../services/order/list";

export type CustomerOrderControllerListRequest = {
query: z.infer<typeof CustomerOrderControllerListSchema>;
};

export const CustomerOrderControllerListSchema = z.object({
customerId: NumberOrStringType,
year: NumberOrStringType,
month: NumberOrStringType,
});

export type CustomerOrderControllerListResponse = Awaited<
ReturnType<typeof CustomerOrderServiceList>
>;

export const CustomerOrderControllerList = _(
async ({ query }: CustomerOrderControllerListRequest) => {
const validateData = CustomerOrderControllerListSchema.parse(query);
return CustomerOrderServiceList(validateData);
}
);
58 changes: 0 additions & 58 deletions src/functions/order/order.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,6 @@ const PriceSetSchema = new Schema(
}
);

const TaxLineSchema = new Schema(
{
channel_liable: Boolean,
price: String,
price_set: PriceSetSchema,
rate: Number,
title: String,
},
{
autoIndex: false,
_id: false,
}
);

const DiscountAllocationSchema = new Schema(
{
amount: String,
amount_set: PriceSetSchema,
discount_application_index: Number,
},
{
autoIndex: false,
_id: false,
}
);

const DiscountCodeSchema = new Schema(
{
code: String,
Expand Down Expand Up @@ -158,13 +132,6 @@ const LineItemSchema = new Schema(
variant_inventory_management: String,
variant_title: String,
vendor: String,
tax_lines: [TaxLineSchema],
duties: [
{
/* Schema definition if available */
},
],
discount_allocations: [DiscountAllocationSchema],
},
{
autoIndex: false,
Expand Down Expand Up @@ -211,8 +178,6 @@ const FulfillmentSchema = new Schema(
location_id: Number,
name: String,
order_id: Number,
origin_address: {},
receipt: {},
service: String,
shipment_status: String,
status: String,
Expand Down Expand Up @@ -282,10 +247,7 @@ const RefundSchema = new Schema(
restock: Boolean,
total_duties_set: PriceSetSchema,
user_id: Number,
order_adjustments: [{}],
transactions: [{}],
refund_line_items: [RefundLineItemSchema],
duties: [{}],
},
{
autoIndex: false,
Expand All @@ -310,8 +272,6 @@ const ShippingLineSchema = new Schema(
requested_fulfillment_service_id: String,
source: String,
title: String,
tax_lines: [{}],
discount_allocations: [{}],
},
{
autoIndex: false,
Expand All @@ -327,16 +287,10 @@ export const OrdreMongooseSchema = new Schema<IOrderDocument, IOrderModel>({
index: true,
},
admin_graphql_api_id: String,
app_id: Number,
browser_ip: String,
buyer_accepts_marketing: Boolean,
cancel_reason: String,
cancelled_at: Date,
cart_token: String,
checkout_id: Number,
checkout_token: String,
closed_at: Date,
confirmation_number: String,
confirmed: Boolean,
contact_email: String,
created_at: Date,
Expand All @@ -352,42 +306,30 @@ export const OrdreMongooseSchema = new Schema<IOrderDocument, IOrderModel>({
current_total_tax: String,
current_total_tax_set: PriceSetSchema,
customer_locale: String,
device_id: Number,
discount_codes: [DiscountCodeSchema],
email: String,
estimated_taxes: Boolean,
financial_status: String,
fulfillment_status: String,
landing_site: String,
landing_site_ref: String,
location_id: Number,
merchant_of_record_app_id: Number,
name: String,
note: String,
note_attributes: [{}],
number: Number,
order_number: Number,
order_status_url: String,
original_total_additional_fees_set: PriceSetSchema,
original_total_duties_set: PriceSetSchema,
payment_gateway_names: [String],
phone: String,
po_number: String,
presentment_currency: String,
processed_at: Date,
reference: String,
referring_site: String,
source_identifier: String,
source_name: String,
source_url: String,
subtotal_price: String,
subtotal_price_set: PriceSetSchema,
tags: String,
tax_exempt: Boolean,
tax_lines: [{}],
taxes_included: Boolean,
test: Boolean,
token: String,
total_discounts: String,
total_discounts_set: PriceSetSchema,
total_line_items_price: String,
Expand Down
66 changes: 1 addition & 65 deletions src/functions/order/order.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const CustomerZod = z.object({
const propertySchema = z.object({
name: z.string(),
value: z.union([z.string(), z.number(), z.coerce.date()]), // Allow string, number, or date
kind: z.string().optional(),
kind: z.string(),
});

const propertiesSchema = z
Expand Down Expand Up @@ -145,21 +145,6 @@ const LineItemZod = z.object({
variant_inventory_management: z.string().nullable(),
variant_title: z.string().nullable(),
vendor: z.string().nullable(),
tax_lines: z.array(
z.object({
/* ... */
})
),
duties: z.array(
z.object({
/* ... */
})
),
discount_allocations: z.array(
z.object({
/* ... */
})
),
});

export type OrderLineItem = z.infer<typeof LineItemZod>;
Expand All @@ -171,12 +156,6 @@ const FulfillmentZod = z.object({
location_id: z.number(),
name: z.string(),
order_id: z.number(),
origin_address: z.object({
/* ... */
}), // Define further if structure is known
receipt: z.object({
/* ... */
}), // Define further if structure is known
service: z.string(),
shipment_status: z.string().nullable(),
status: z.string(),
Expand Down Expand Up @@ -229,16 +208,6 @@ const RefundZod = z.object({
restock: z.boolean(),
total_duties_set: MoneySetZod.nullable(),
user_id: z.number(),
order_adjustments: z.array(
z.object({
/* ... */
})
), // Define further if structure is known
transactions: z.array(
z.object({
/* ... */
})
), // Define further if structure is known
refund_line_items: z
.array(RefundLineItemZod)
.transform((items) =>
Expand All @@ -255,11 +224,6 @@ const RefundZod = z.object({
},
}))
),
duties: z.array(
z.object({
/* ... */
})
), // Define further if structure is known
});

export type OrderRefund = z.infer<typeof RefundZod>;
Expand All @@ -276,32 +240,16 @@ const ShippingLineZod = z.object({
requested_fulfillment_service_id: z.string().nullable(),
source: z.string(),
title: z.string(),
tax_lines: z.array(
z.object({
/* ... */
})
), // Define further if structure is known
discount_allocations: z.array(
z.object({
/* ... */
})
), // Define further if structure is known
});

export const Order = z.object({
id: z.number(),
admin_graphql_api_id: z.string(),
app_id: z.number().nullable(),
browser_ip: z.string(),
buyer_accepts_marketing: z.boolean(),
cancel_reason: z.string().nullable(),
cancelled_at: z.string().nullable(),
cart_token: z.string(),
checkout_id: z.number().nullable(),
checkout_token: z.string().nullable(),
client_details: ClientDetailsZod,
closed_at: z.string().nullable(),
confirmation_number: z.string().nullable(),
confirmed: z.boolean(),
contact_email: z.string().nullable(),
created_at: z.string(),
Expand All @@ -317,34 +265,23 @@ export const Order = z.object({
current_total_tax: z.string(),
current_total_tax_set: MoneySetZod,
customer_locale: z.string().nullable(),
device_id: z.number().nullable(),
discount_codes: z.array(DiscountCodeZod),
email: z.string(),
estimated_taxes: z.boolean(),
financial_status: z.string(),
fulfillment_status: z.string().nullable(),
landing_site: z.string(),
landing_site_ref: z.string().nullable(),
location_id: z.number().nullable(),
merchant_of_record_app_id: z.number().nullable(),
name: z.string(),
note: z.string().nullable(),
note_attributes: z.array(z.object({ name: z.string(), value: z.string() })),
number: z.number(),
order_number: z.number(),
order_status_url: z.string(),
original_total_additional_fees_set: MoneySetZod.nullable(),
original_total_duties_set: MoneySetZod.nullable(),
payment_gateway_names: z.array(z.string()),
phone: z.string().nullable(),
po_number: z.string().nullable(),
presentment_currency: z.string(),
processed_at: z.string(),
reference: z.string().nullable(),
referring_site: z.string().nullable(),
source_identifier: z.string().nullable(),
source_name: z.string(),
source_url: z.string().nullable(),
subtotal_price: z.string(),
subtotal_price_set: MoneySetZod,
tags: z.string(),
Expand All @@ -356,7 +293,6 @@ export const Order = z.object({
),
taxes_included: z.boolean(),
test: z.boolean(),
token: z.string(),
total_discounts: z.string(),
total_discounts_set: MoneySetZod,
total_line_items_price: z.string(),
Expand Down

0 comments on commit 136cad0

Please sign in to comment.