Skip to content

Commit

Permalink
feat(openapi): add new endpoint for getting orders destinations for a…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
jamalsoueidan committed Feb 26, 2024
1 parent 44378d2 commit e2430d9
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 2 deletions.
42 changes: 42 additions & 0 deletions openapi/paths/customer/order/shipping/index.yaml
Original file line number Diff line number Diff line change
@@ -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: []
25 changes: 25 additions & 0 deletions openapi/paths/customer/order/shipping/list.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions openapi/paths/customer/order/shipping/response.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type: object
properties:
success:
type: boolean
example: true
payload:
type: array
items:
$ref: list.yaml
required:
- success
- payload
8 changes: 8 additions & 0 deletions src/functions/customer-order.function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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,
});
2 changes: 2 additions & 0 deletions src/functions/customer/services/order/shipping.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ describe("CustomerOrderServiceList", () => {
expect(item).toHaveProperty("shipping");
expect(item.shipping).toBeDefined();
});

console.log(JSON.stringify(orders[0]));
});
});
4 changes: 4 additions & 0 deletions src/functions/customer/services/order/shipping.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -16,6 +17,7 @@ export type CustomerOrderServiceShippingAggregate = Pick<
end: Date;
title: Date;
shipping: Shipping;
location: Location;
};

export const CustomerOrderServiceShipping = async ({
Expand All @@ -30,6 +32,7 @@ export const CustomerOrderServiceShipping = async ({
{
$match: {
$and: [
{ "line_items.properties.shippingId": { $exists: true } },
{
$or: [
{
Expand Down Expand Up @@ -61,6 +64,7 @@ export const CustomerOrderServiceShipping = async ({
{
$match: {
$and: [
{ "line_items.properties.shippingId": { $exists: true } },
{
$or: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/functions/shipping/shipping.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/library/jest/helpers/shipping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const getOriginObject = (props: Partial<Location> = {}): Location => ({

export const createShipping = (filter: Partial<Shipping>) => {
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(),
Expand Down

0 comments on commit e2430d9

Please sign in to comment.