Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(location): location-startfree-maxmin-distance #70

Merged
merged 9 commits into from
Nov 3, 2023
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen",
"azureFunctions.projectLanguageModel": 4,
"azureFunctions.preDeployTask": "npm prune (functions)"
}
"azureFunctions.preDeployTask": "npm prune (functions)",
"docify.commentService.programmingLanguage": "javascript"
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ let responseJson = pm.response.json();
let token = responseJson.payload.token;
pm.environment.set("bearerToken", token);
```

## Index.ts

We try to NOT export all internal files from index folder file because we would like to mock single methods in jest.
It's eaiser when not using index file.
12 changes: 10 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 @@ -131,6 +133,8 @@ components:

CustomerLocation:
$ref: paths/customer/location/_types/location.yaml
CustomerLocationBody:
$ref: paths/customer/location/_types/location-body.yaml
CustomerLocationIsDefault:
$ref: paths/customer/location/_types/location-is-default.yaml
CustomerLocationGetAllOriginsRepsonse:
Expand Down Expand Up @@ -185,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 @@ -258,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 @@ -12,12 +14,14 @@ properties:
type: string
fullAddress:
type: string
minDistanceForFree:
type: string
distanceForFree:
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
33 changes: 33 additions & 0 deletions openapi/paths/customer/location/_types/location-body.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
type: object
properties:
name:
type: string
fullAddress:
type: string
originType:
type: string
enum: [home, commercial]
distanceForFree:
oneOf:
- type: number
- type: string
distanceHourlyRate:
oneOf:
- type: number
- type: string
fixedRatePerKm:
oneOf:
- type: number
- type: string
minDriveDistance:
oneOf:
- type: number
- type: string
maxDriveDistance:
oneOf:
- type: number
- type: string
startFee:
oneOf:
- type: number
- type: string
19 changes: 17 additions & 2 deletions openapi/paths/customer/location/_types/location.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,24 @@ properties:
type: array
items:
type: number
minDistanceForFree:
distanceForFree:
type: number
distanceHourlyRate:
type: number
fixedRatePerKm:
type: number
minDriveDistance:
oneOf:
- type: number
- type: string
maxDriveDistance:
oneOf:
- type: number
- type: string
startFee:
oneOf:
- type: number
- type: string

required:
- _id
Expand All @@ -43,6 +55,9 @@ required:
- name
- fullAddress
- geoLocation
- minDistanceForFree
- distanceForFree
- distanceHourlyRate
- fixedRatePerKm
- minDriveDistance
- maxDriveDistance
- startFree
27 changes: 6 additions & 21 deletions openapi/paths/customer/location/create/body.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
type: object
properties:
name:
type: string
fullAddress:
type: string
locationType:
type: string
enum: [origin, destination]
originType:
type: string
enum: [home, commercial]
minDistanceForFree:
oneOf:
- type: number
- type: string
distanceHourlyRate:
oneOf:
- type: number
- type: string
fixedRatePerKm:
oneOf:
- type: number
- type: string

allOf:
- $ref: ../_types/location-body.yaml
required:
- name
- fullAddress
- locationType
- originType
- minDistanceForFree
- distanceForFree
- distanceHourlyRate
- fixedRatePerKm
- minDriveDistance
- maxDriveDistance
- startFree
22 changes: 2 additions & 20 deletions openapi/paths/customer/location/update/body.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
type: object
properties:
name:
type: string
fullAddress:
type: string
originType:
type: string
enum: [home, commercial]
minDistanceForFree:
oneOf:
- type: number
- type: string
distanceHourlyRate:
oneOf:
- type: number
- type: string
fixedRatePerKm:
oneOf:
- type: number
- type: string
allOf:
- $ref: ../_types/location-body.yaml
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
4 changes: 2 additions & 2 deletions src/functions/availability/availability.types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Lookup } from "../lookup/lookup.type";
import { Shipping } from "../shipping/shipping.types";
import { User } from "../user/user.types";

export type Availability = {
date: Date;
customer: Pick<User, "fullname" | "customerId">;
lookup?: Lookup;
shipping?: Shipping;
slots: {
from: Date;
to: Date;
Expand Down
7 changes: 1 addition & 6 deletions src/functions/customer/controllers/availability/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { _ } from "~/library/handler";

import { UserZodSchema } from "~/functions/user";

import { LocationZodSchema } from "~/functions/location";
import { NumberOrStringType, StringOrObjectIdType } from "~/library/zod";
import { CustomerAvailabilityServiceGet } from "../../services/availability";
import { CustomerProductsServiceListIds } from "../../services/product";
Expand All @@ -21,11 +20,7 @@ export const CustomerAvailabilityControllerGetQuerySchema = z.object({
export const CustomerAvailabilityControllerGetBodySchema = z.object({
productIds: z.array(NumberOrStringType),
startDate: z.string(),
destination: LocationZodSchema.pick({
name: true,
fullAddress: true,
originType: true,
}).optional(),
shippingId: z.union([z.string(), z.undefined()]),
});

export type CustomerAvailabilityControllerGetResponse = Awaited<
Expand Down
Loading