From e2430d9cb833ae5a6d315cd50feacda641d22cf7 Mon Sep 17 00:00:00 2001 From: Jamal Soueidan Date: Mon, 26 Feb 2024 17:56:10 +0100 Subject: [PATCH] feat(openapi): add new endpoint for getting orders destinations for a customer feat(openapi): add response schema for getting orders destinations feat(openapi): add schema for listing order shipping details feat(functions): add CustomerOrderControllerShipping for handling shipping requests feat(functions): add CustomerOrderServiceShipping for processing shipping data feat(shipping): update ShippingMongooseSchema to include origin information feat(tests): add test for CustomerOrderServiceShipping feat(tests): add test for createShipping function in jest helpers --- .../paths/customer/order/shipping/index.yaml | 42 +++++++++++++++++++ .../paths/customer/order/shipping/list.yaml | 25 +++++++++++ .../customer/order/shipping/response.yaml | 12 ++++++ src/functions/customer-order.function.ts | 8 ++++ .../customer/services/order/shipping.spec.ts | 2 + .../customer/services/order/shipping.ts | 4 ++ src/functions/shipping/shipping.schema.ts | 2 +- src/library/jest/helpers/shipping.ts | 3 +- 8 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 openapi/paths/customer/order/shipping/index.yaml create mode 100644 openapi/paths/customer/order/shipping/list.yaml create mode 100644 openapi/paths/customer/order/shipping/response.yaml diff --git a/openapi/paths/customer/order/shipping/index.yaml b/openapi/paths/customer/order/shipping/index.yaml new file mode 100644 index 00000000..9506bea9 --- /dev/null +++ b/openapi/paths/customer/order/shipping/index.yaml @@ -0,0 +1,42 @@ +get: + parameters: + - name: customerId + in: path + description: customerId for the customer + required: true + schema: + type: string + - name: start + in: query + description: start of date + required: true + schema: + type: string + - name: end + in: query + description: end of date + required: true + schema: + type: string + tags: + - CustomerOrder + operationId: customerOrderShipping + summary: GET Get only all orders destinations for customer + description: Get all driving information that are included in the orders + responses: + "200": + description: "Response" + content: + application/json: + schema: + $ref: "./response.yaml" + "400": + $ref: "../../../../responses/bad.yaml" + "401": + $ref: "../../../../responses/unauthorized.yaml" + "403": + $ref: "../../../../responses/forbidden.yaml" + "404": + $ref: "../../../../responses/not-found.yaml" + + security: [] diff --git a/openapi/paths/customer/order/shipping/list.yaml b/openapi/paths/customer/order/shipping/list.yaml new file mode 100644 index 00000000..7e1c9378 --- /dev/null +++ b/openapi/paths/customer/order/shipping/list.yaml @@ -0,0 +1,25 @@ +type: object +properties: + id: + type: number + order_number: + type: number + customer: + $ref: customer.yaml + start: + type: string + end: + type: string + title: + type: string + shipping: + $ref: ../../customer/shipping/_types/shipping.yaml + +required: + - id + - customer + - start + - end + - title + - order_number + - shipping diff --git a/openapi/paths/customer/order/shipping/response.yaml b/openapi/paths/customer/order/shipping/response.yaml new file mode 100644 index 00000000..eb232183 --- /dev/null +++ b/openapi/paths/customer/order/shipping/response.yaml @@ -0,0 +1,12 @@ +type: object +properties: + success: + type: boolean + example: true + payload: + type: array + items: + $ref: list.yaml +required: + - success + - payload diff --git a/src/functions/customer-order.function.ts b/src/functions/customer-order.function.ts index f0791046..23e3e462 100644 --- a/src/functions/customer-order.function.ts +++ b/src/functions/customer-order.function.ts @@ -5,6 +5,7 @@ import { app } from "@azure/functions"; import { CustomerOrderControllerGet } from "./customer/controllers/order/get"; import { CustomerOrderControllerGetLineItem } from "./customer/controllers/order/get-lineitem"; import { CustomerOrderControllerList } from "./customer/controllers/order/list"; +import { CustomerOrderControllerShipping } from "./customer/controllers/order/shipping"; app.http("customerOrderLineItemGet", { methods: ["GET"], @@ -26,3 +27,10 @@ app.http("customerOrderList", { route: "customer/{customerId?}/orders-range", handler: CustomerOrderControllerList, }); + +app.http("customerOrderShipping", { + methods: ["GET"], + authLevel: "anonymous", + route: "customer/{customerId?}/shipping-range", + handler: CustomerOrderControllerShipping, +}); diff --git a/src/functions/customer/services/order/shipping.spec.ts b/src/functions/customer/services/order/shipping.spec.ts index b68e0075..2e3d6455 100644 --- a/src/functions/customer/services/order/shipping.spec.ts +++ b/src/functions/customer/services/order/shipping.spec.ts @@ -38,5 +38,7 @@ describe("CustomerOrderServiceList", () => { expect(item).toHaveProperty("shipping"); expect(item.shipping).toBeDefined(); }); + + console.log(JSON.stringify(orders[0])); }); }); diff --git a/src/functions/customer/services/order/shipping.ts b/src/functions/customer/services/order/shipping.ts index 80fd99d0..73511c28 100644 --- a/src/functions/customer/services/order/shipping.ts +++ b/src/functions/customer/services/order/shipping.ts @@ -1,3 +1,4 @@ +import { Location } from "~/functions/location"; import { OrderModel } from "~/functions/order/order.models"; import { Shipping } from "~/functions/shipping/shipping.types"; import { OrderAggregate } from "./_types"; @@ -16,6 +17,7 @@ export type CustomerOrderServiceShippingAggregate = Pick< end: Date; title: Date; shipping: Shipping; + location: Location; }; export const CustomerOrderServiceShipping = async ({ @@ -30,6 +32,7 @@ export const CustomerOrderServiceShipping = async ({ { $match: { $and: [ + { "line_items.properties.shippingId": { $exists: true } }, { $or: [ { @@ -61,6 +64,7 @@ export const CustomerOrderServiceShipping = async ({ { $match: { $and: [ + { "line_items.properties.shippingId": { $exists: true } }, { $or: [ { diff --git a/src/functions/shipping/shipping.schema.ts b/src/functions/shipping/shipping.schema.ts index b8918970..f81031da 100644 --- a/src/functions/shipping/shipping.schema.ts +++ b/src/functions/shipping/shipping.schema.ts @@ -22,7 +22,7 @@ export const ShippingMongooseSchema = new mongoose.Schema< }, origin: { /*------------------*/ - /* we are moving these information from location, in case the user changes them while booking an appointment */ + /* we are moving these information from location, in case the user changes them or delete them while booking an appointment */ /*------------------*/ customerId: { type: Number, diff --git a/src/library/jest/helpers/shipping.ts b/src/library/jest/helpers/shipping.ts index 33e099b4..071dfc09 100644 --- a/src/library/jest/helpers/shipping.ts +++ b/src/library/jest/helpers/shipping.ts @@ -27,7 +27,8 @@ const getOriginObject = (props: Partial = {}): Location => ({ export const createShipping = (filter: Partial) => { const shipping = new ShippingModel(); - shipping.location = filter.location || new mongoose.Types.ObjectId(); + shipping.location = + filter.location?.toString() || new mongoose.Types.ObjectId(); shipping.origin = getOriginObject({}); shipping.destination = { name: faker.company.buzzPhrase(),