Skip to content

Commit

Permalink
fix(openapi): update references to shipping types in openapi.yaml
Browse files Browse the repository at this point in the history
feat(openapi): add ShippingCreate endpoint to openapi.yaml
feat(openapi): add ShippingBody and ShippingCreateResponse types to openapi.yaml
feat(openapi): add shippingId property to customer availability get body
feat(openapi): add ShippingBody type to shipping calculate endpoint in openapi.yaml
feat(openapi): add ShippingCreate endpoint to openapi.yaml
feat(openapi): add ShippingCreateResponse type to openapi.yaml
feat(openapi): add NumberOrString type to openapi.yaml
fix(server.ts): change port variable case from lowercase port to uppercase PORT
feat(server.ts): add support for process.env.PORT environment variable
fix(shipping/controllers/calculate.ts): add customerId property to ShippingControllerCalculateRequest
fix(shipping/services/calculate.ts): add comment about using customerId to find locationId
  • Loading branch information
jamalsoueidan committed Nov 3, 2023
1 parent f5ce656 commit 07ee45e
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 24 deletions.
10 changes: 8 additions & 2 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ components:
$ref: "./responses/unauthorized.yaml"

schemas:
NumberOrString:
$ref: "types/_numberOrString.yaml"
Errors:
$ref: "./schemas/errors.yaml"
MetaItem:
Expand Down Expand Up @@ -187,8 +189,10 @@ components:
$ref: paths/location/validate-address/response.yaml

# Shipping
ShippingCalculateBody:
$ref: paths/shipping/calculate/body.yaml
ShippingBody:
$ref: paths/shipping/_types/body.yaml
ShippingCreateResponse:
$ref: paths/shipping/create/response.yaml
ShippingCalculateResponse:
$ref: paths/shipping/calculate/response.yaml
paths:
Expand Down Expand Up @@ -260,5 +264,7 @@ paths:
$ref: "./paths/location/get-travel-time/index.yaml"

# shipping
/shipping/create:
$ref: "./paths/shipping/create/index.yaml"
/shipping/calculate:
$ref: "./paths/shipping/calculate/index.yaml"
4 changes: 2 additions & 2 deletions openapi/paths/customer/availability/_types/availability.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ properties:
required:
- customerId
- fullname
lookup:
$ref: "../_types/lookup.yaml"
shipping:
$ref: "../_types/shipping.yaml"
slots:
type: array
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ type: object
properties:
_id:
type: string
location:
type: string
origin:
type: object
properties:
Expand All @@ -13,11 +15,13 @@ properties:
fullAddress:
type: string
distanceForFree:
type: string
type: number
distanceHourlyRate:
type: string
type: number
fixedRatePerKm:
type: string
type: number
startFee:
type: number
destination:
type: object
properties:
Expand All @@ -39,9 +43,12 @@ properties:
type: string
value:
type: number
cost:
type: number
required:
- _id
- origin
- destination
- duration
- distance
- cost
16 changes: 2 additions & 14 deletions openapi/paths/customer/availability/get/body.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,8 @@ properties:
type: array
items:
type: string
destination:
type: object
properties:
name:
type: string
fullAddress:
type: string
originType:
type: string
enum: [home, commercial]
required:
- name
- fullAddress
- originType
shippingId:
type: string

required:
- startDate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
type: object
properties:
customerId:
$ref: "../../../types/_numberOrString.yaml"
locationId:
type: string
destination:
type: object
properties:
name:
type: string
fullAddress:
type: string
required:
- name
- fullAddress

required:
Expand Down
2 changes: 1 addition & 1 deletion openapi/paths/shipping/calculate/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ post:
content:
application/json:
schema:
$ref: "./body.yaml"
$ref: "../_types/body.yaml"
responses:
"200":
description: "Response"
Expand Down
25 changes: 25 additions & 0 deletions openapi/paths/shipping/create/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
post:
tags:
- ShippingCreate
operationId: shippingCreate
summary: POST create shipping
requestBody:
required: true
content:
application/json:
schema:
$ref: "../_types/body.yaml"
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"
security: []
27 changes: 27 additions & 0 deletions openapi/paths/shipping/create/response.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
type: object
properties:
success:
type: boolean
example: true
payload:
type: object
allOf:
- $ref: ../../location/_types/travel-time.yaml
- type: object
properties:
cost:
type: object
properties:
currency:
type: string
value:
type: integer
required:
- currency
- value
required:
- cost

required:
- success
- payload
3 changes: 3 additions & 0 deletions openapi/types/_numberOrString.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
oneOf:
- type: number
- type: string
3 changes: 2 additions & 1 deletion src/functions/shipping/controllers/calculate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { _ } from "~/library/handler";

import { z } from "zod";
import { StringOrObjectIdType } from "~/library/zod";
import { NumberOrStringType, StringOrObjectIdType } from "~/library/zod";
import { ShippingServiceCalculate } from "../services/calculate";
import { ShippingZodSchema } from "../shipping.types";

Expand All @@ -11,6 +11,7 @@ export type ShippingControllerCalculateRequest = {

export const ShippingControllerCalculateSchema = z
.object({
customerId: NumberOrStringType,
locationId: StringOrObjectIdType,
})
.merge(ShippingZodSchema.pick({ destination: true }));
Expand Down
2 changes: 1 addition & 1 deletion src/functions/shipping/services/calculate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ShippingServiceCalculateCost } from "./calculate-cost";
export const ShippingServiceCalculate = async (
props: Required<LocationServiceGetProps & Pick<Shipping, "destination">>
) => {
const location = await LocationServiceGet(props);
const location = await LocationServiceGet(props); // we should properly use the customerId to find the locationId
const { destination } = props;

if (!destination) {
Expand Down

0 comments on commit 07ee45e

Please sign in to comment.