-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from jamalsoueidan/additional-endpoint-for-ge…
…t-order-and-by-group feat(openapi): add new CustomerOrderWithLookup and CustomerOrderGetBy…
- Loading branch information
Showing
13 changed files
with
429 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
openapi/paths/customer/order/get/get.yaml → ...tomer/order/_types/order-with-lookup.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/functions/customer/services/order/get-by-group.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
Oops, something went wrong.