Skip to content

Commit

Permalink
feat(order): add new shipping controller for customer orders
Browse files Browse the repository at this point in the history
feat(order): update LineItemSchema in order schema to include 'to' field
feat(webhook): update orderWithfulfillmentAndRefunds data with locationId
and shippingId
feat(jest): update createShipping function to use faker data for location
and duration
  • Loading branch information
jamalsoueidan committed Feb 26, 2024
1 parent 0253cf9 commit 44378d2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
26 changes: 26 additions & 0 deletions src/functions/customer/controllers/order/shipping.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 { CustomerOrderServiceShipping } from "../../services/order/shipping";

export type CustomerOrderControllerShippingRequest = {
query: z.infer<typeof CustomerOrderControllerShippingSchema>;
};

export const CustomerOrderControllerShippingSchema = z.object({
customerId: NumberOrStringType,
start: z.string(),
end: z.string(),
});

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

export const CustomerOrderControllerShipping = _(
async ({ query }: CustomerOrderControllerShippingRequest) => {
const validateData = CustomerOrderControllerShippingSchema.parse(query);
return CustomerOrderServiceShipping(validateData);
}
);
5 changes: 4 additions & 1 deletion src/functions/order/order.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ const LineItemSchema = new Schema(
type: Date,
index: true,
},
to: Date,
to: {
type: Date,
index: true,
},
customerId: { type: Number, index: true },
locationId: String,
shippingId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ export const orderWithfulfillmentAndRefunds = {
{ name: "_from", value: "2023-12-18T07:00:00.000Z" },
{ name: "_to", value: "2023-12-18T08:15:00.000Z" },
{ name: "_customerId", value: "7106990342471" },
{ name: "_locationId", value: "" },
{ name: "Tid", value: "mandag, 18. december 10:00" },
{ name: "Varighed", value: "1 time(r)" },
],
Expand Down Expand Up @@ -484,6 +483,8 @@ export const orderWithfulfillmentAndRefunds = {
{ name: "_from", value: "2024-01-01T06:15:00.000Z" },
{ name: "_to", value: "2024-01-01T07:30:00.000Z" },
{ name: "_customerId", value: "7106990342471" },
{ name: "_locationId", value: "65dc739939e83647f048b4d5" },
{ name: "_shippingId", value: "65dc739939e83647f048b4d5" },
{ name: "Skønhedsekspert", value: "hana nielsen" },
{ name: "Tid", value: "mandag, 1. januar 09:15" },
{ name: "Varighed", value: "1 time(r)" },
Expand Down Expand Up @@ -572,6 +573,8 @@ export const orderWithfulfillmentAndRefunds = {
{ name: "_from", value: "2023-12-18T07:00:00.000Z" },
{ name: "_to", value: "2023-12-18T08:15:00.000Z" },
{ name: "_customerId", value: "7106990342471" },
{ name: "_locationId", value: "65dc739939e83647f048b4d5" },
{ name: "_shippingId", value: "65dc739939e83647f048b4d5" },
{ name: "Skønhedsekspert", value: "hana nielsen" },
{ name: "Tid", value: "mandag, 18. december 10:00" },
{ name: "Varighed", value: "1 time(r)" },
Expand Down
14 changes: 7 additions & 7 deletions src/library/jest/helpers/shipping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ const getOriginObject = (props: Partial<Location> = {}): Location => ({

export const createShipping = (filter: Partial<Shipping>) => {
const shipping = new ShippingModel();
shipping.location = new mongoose.Types.ObjectId();
shipping.location = filter.location || new mongoose.Types.ObjectId();
shipping.origin = getOriginObject({});
shipping.destination = {
name: faker.word.sample(),
fullAddress: faker.word.conjunction(),
name: faker.company.buzzPhrase(),
fullAddress: faker.location.streetAddress(),
};
shipping.duration = {
text: "123 km",
value: 1,
text: "2 hours 59 mins",
value: 179.31666666666666,
};
shipping.distance = {
text: "123 km",
value: 1,
text: "187 km",
value: 186.586,
};
shipping.cost = {
currency: "DKK",
Expand Down

0 comments on commit 44378d2

Please sign in to comment.