Skip to content

Commit

Permalink
Merge pull request #106 from jamalsoueidan/additional-endpoint-for-ge…
Browse files Browse the repository at this point in the history
…t-order-and-by-group

feat(openapi): add new CustomerOrderWithLookup and CustomerOrderGetBy…
  • Loading branch information
jamalsoueidan authored Feb 29, 2024
2 parents e9e3f2e + 798921a commit c6ff43c
Show file tree
Hide file tree
Showing 13 changed files with 429 additions and 35 deletions.
10 changes: 7 additions & 3 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ components:
$ref: paths/customer/order/_types/shipping_lines.yaml
CustomerOrderFulfillment:
$ref: paths/customer/order/_types/fulfillment.yaml
CustomerOrderGet:
$ref: paths/customer/order/get/get.yaml
CustomerOrderWithLookup:
$ref: paths/customer/order/_types/order-with-lookup.yaml
CustomerOrderGetResponse:
$ref: paths/customer/order/get/response.yaml
CustomerOrderGetByGroupIdResponse:
$ref: paths/customer/order/get-by-group/response.yaml
CustomerOrderRangeResponse:
$ref: paths/customer/order/range/response.yaml

Expand Down Expand Up @@ -324,7 +326,9 @@ paths:
$ref: "./paths/customer/product/list-ids/index.yaml"
/customer/{customerId}/product/{productId}:
$ref: "paths/customer/product/product.yaml"
/customer/{customerId}/orders/{orderId}/groupId/{groupId}:
/customer/{customerId}/orders/{orderId}/group/{groupId}:
$ref: "paths/customer/order/get-by-group/index.yaml"
/customer/{customerId}/orders/{orderId}:
$ref: "paths/customer/order/get/index.yaml"
/customer/{customerId}/orders-range:
$ref: "paths/customer/order/range/index.yaml"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
allOf:
- $ref: "../_types/order.yaml"
- $ref: "./order.yaml"
- type: object
properties:
user:
Expand Down
43 changes: 43 additions & 0 deletions openapi/paths/customer/order/get-by-group/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
get:
parameters:
- name: customerId
in: path
description: customerId for the customer
required: true
schema:
type: string
- name: orderId
in: path
description: orderId for the order
required: true
schema:
type: string
- name: groupId
in: path
description: groupId for the order
required: true
schema:
type: string
tags:
- CustomerOrder
operationId: customerOrderGetByGroup
summary: GET Get order with lineItems array for specific groupId
description: This endpoint gets order with lineItems array of objects specific for groupId
responses:
"200":
description: Response with payload
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: []
10 changes: 10 additions & 0 deletions openapi/paths/customer/order/get-by-group/response.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type: object
properties:
success:
type: boolean
example: true
payload:
$ref: ../_types/order-with-lookup.yaml
required:
- success
- payload
6 changes: 0 additions & 6 deletions openapi/paths/customer/order/get/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ get:
required: true
schema:
type: string
- name: groupId
in: path
description: groupId for the order
required: true
schema:
type: string
tags:
- CustomerOrder
operationId: customerOrderGet
Expand Down
2 changes: 1 addition & 1 deletion openapi/paths/customer/order/get/response.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ properties:
type: boolean
example: true
payload:
$ref: get.yaml
$ref: ../_types/order-with-lookup.yaml
required:
- success
- payload
10 changes: 9 additions & 1 deletion src/functions/customer-order.function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ import "module-alias/register";
import { app } from "@azure/functions";

import { CustomerOrderControllerGet } from "./customer/controllers/order/get";
import { CustomerOrderControllerGetByGroup } from "./customer/controllers/order/get-by-group";
import { CustomerOrderControllerRange } from "./customer/controllers/order/range";

app.http("customerOrderGetByGroupId", {
methods: ["GET"],
authLevel: "anonymous",
route: "customer/{customerId?}/orders/{orderId?}/group/{groupId?}",
handler: CustomerOrderControllerGetByGroup,
});

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

Expand Down
25 changes: 25 additions & 0 deletions src/functions/customer/controllers/order/get-by-group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { z } from "zod";
import { _ } from "~/library/handler";
import { NumberOrStringType } from "~/library/zod";
import { CustomerOrderServiceGetByGroup } from "../../services/order/get-by-group";

export type CustomerOrderControllerGetByGroupRequest = {
query: z.infer<typeof CustomerOrderControllerGetByGroupSchema>;
};

export const CustomerOrderControllerGetByGroupSchema = z.object({
customerId: NumberOrStringType,
orderId: NumberOrStringType,
groupId: z.string(),
});

export type CustomerOrderControllerGetByGroupResponse = Awaited<
ReturnType<typeof CustomerOrderServiceGetByGroup>
>;

export const CustomerOrderControllerGetByGroup = _(
async ({ query }: CustomerOrderControllerGetByGroupRequest) => {
const validateData = CustomerOrderControllerGetByGroupSchema.parse(query);
return CustomerOrderServiceGetByGroup(validateData);
}
);
1 change: 0 additions & 1 deletion src/functions/customer/controllers/order/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export type CustomerOrderControllerGetRequest = {
export const CustomerOrderControllerGetSchema = z.object({
customerId: NumberOrStringType,
orderId: NumberOrStringType,
groupId: z.string(),
});

export type CustomerOrderControllerGetResponse = Awaited<
Expand Down
44 changes: 44 additions & 0 deletions src/functions/customer/services/order/get-by-group.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { OrderModel } from "~/functions/order/order.models";
import { Order } from "~/functions/order/order.types";
import { orderWithfulfillmentAndRefunds } from "~/functions/webhook/data-order-with-fullfilment-and-refunds";
import { createUser } from "~/library/jest/helpers";
import { createLocation } from "~/library/jest/helpers/location";
import { CustomerOrderServiceGetByGroup } from "./get-by-group";
require("~/library/jest/mongoose/mongodb.jest");

describe("CustomerOrderServiceGetByGroup", () => {
it("should return order with the correct lineitems for customer/groupId", async () => {
const customerId = 7106990342471;
const groupId = "2332";
const user = await createUser({ customerId });
const location = await createLocation({ customerId });
const dumbData = Order.parse(orderWithfulfillmentAndRefunds);
dumbData.line_items[0].properties!.customerId = user.customerId;
dumbData.line_items[0].properties!.locationId = location._id.toString();
dumbData.line_items[0].properties!.groupId = groupId;
const response = await OrderModel.create(dumbData);

const orderId = response.id;
const ownerCustomerId = user.customerId;

let order = await CustomerOrderServiceGetByGroup({
customerId: ownerCustomerId,
orderId,
groupId,
});

expect(order.line_items.length).toBe(1);
expect(order.fulfillments.length).toBe(1);
expect(order.refunds.length).toBe(1);

order = await CustomerOrderServiceGetByGroup({
customerId: ownerCustomerId,
orderId,
groupId: "123",
});

expect(order.line_items.length).toBe(2);
expect(order.fulfillments.length).toBe(2);
expect(order.refunds.length).toBe(0);
});
});
Loading

0 comments on commit c6ff43c

Please sign in to comment.