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(),