Skip to content

Commit

Permalink
Add customer blocked feature to OpenAPI spec and update backend funct…
Browse files Browse the repository at this point in the history
…ions

 • Introduce new OpenAPI components for managing customer block lists, including create, destroy, list, and range operations.
 • Add corresponding paths and methods to the OpenAPI spec for the new blocked feature.
 • Create new schema files for blocked types and operations.
 • Implement backend functions for creating, deleting, listing, and querying customer block ranges.
 • Update blocked schema and types in the backend to include the title field.
 • Write and adjust tests for the new blocked functionality.
  • Loading branch information
jamalsoueidan committed Mar 5, 2024
1 parent fd8998c commit 2dc4b86
Show file tree
Hide file tree
Showing 27 changed files with 353 additions and 14 deletions.
26 changes: 26 additions & 0 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ components:
CustomerOrderGetResponse:
$ref: paths/customer/order/get/response.yaml

# Blocked
CustomerBlocked:
$ref: paths/customer/blocked/_types/blocked.yaml
CustomerBlockedCreateBody:
$ref: paths/customer/blocked/create/body.yaml
CustomerBlockedCreateResponse:
$ref: paths/customer/blocked/create/response.yaml
CustomerBlockedDestroyResponse:
$ref: paths/customer/blocked/destroy/response.yaml
CustomerBlockedList:
$ref: paths/customer/blocked/list/list.yaml
CustomerBlockedListResponse:
$ref: paths/customer/blocked/list/response.yaml
CustomerBlockedRangeResponse:
$ref: paths/customer/blocked/range/response.yaml

# Booking
CustomerBooking:
$ref: paths/customer/booking/_types/booking.yaml
Expand Down Expand Up @@ -389,3 +405,13 @@ paths:
# Orchestrators
/orchestrators/upload:
$ref: "./paths/orchestrators/upload/index.yaml"

# blocked
/customer/{customerId}/blocked:
$ref: "./paths/customer/blocked/create/index.yaml"
/customer/{customerId}/blocked/({blockedId}):
$ref: "./paths/customer/blocked/destroy/index.yaml"
/customer/{customerId}/blocked/list:
$ref: "./paths/customer/blocked/list/index.yaml"
/customer/{customerId}/blocked/range:
$ref: paths/customer/blocked/range/index.yaml
18 changes: 18 additions & 0 deletions openapi/paths/customer/blocked/_types/blocked.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
type: object
properties:
_id:
type: string
customerId:
type: number
start:
type: string
end:
type: string
title:
type: string
required:
- id
- customerId
- start
- end
- title
20 changes: 20 additions & 0 deletions openapi/paths/customer/blocked/blocked.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
parameters:
- name: customerId
in: path
description: The ID of the customerId
required: true
schema:
type: string
- name: scheduleId
in: path
description: The ID of the scheduleId
required: true
schema:
type: string

get:
$ref: "./get/index.yaml#/get"
put:
$ref: "./update/index.yaml#/put"
delete:
$ref: "./destroy/index.yaml#/delete"
12 changes: 12 additions & 0 deletions openapi/paths/customer/blocked/create/body.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type: object
properties:
title:
type: string
start:
type: string
end:
type: string
required:
- title
- start
- end
37 changes: 37 additions & 0 deletions openapi/paths/customer/blocked/create/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
parameters:
- name: customerId
in: path
description: The ID of the customerId
required: true
schema:
type: string
post:
tags:
- CustomerBlocked
operationId: customerBlockedCreate
summary: POST Create blocked
description: This endpoint create new blocked
requestBody:
required: true
content:
application/json:
schema:
$ref: "./body.yaml"

responses:
"200":
description: Response with blocked 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/blocked/create/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/blocked.yaml
required:
- success
- payload
10 changes: 10 additions & 0 deletions openapi/paths/customer/blocked/destroy/destroy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type: object
properties:
deletedCount:
type: number
acknowledged:
type: boolean

required:
- deletedCount
- acknowledged
34 changes: 34 additions & 0 deletions openapi/paths/customer/blocked/destroy/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
delete:
parameters:
- name: customerId
in: path
description: The ID of the customerId
required: true
schema:
type: string
- name: blockedId
in: path
description: The ID of the blockedId to be destroyed
required: true
schema:
type: string
tags:
- CustomerBlocked
operationId: customerBlockedDestroy
summary: DEL destroy blocked
description: This endpoint destroy blocked for customer
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: []
10 changes: 10 additions & 0 deletions openapi/paths/customer/blocked/destroy/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: ./destroy.yaml
required:
- success
- payload
40 changes: 40 additions & 0 deletions openapi/paths/customer/blocked/list/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
get:
parameters:
- name: customerId
in: path
description: The ID of the customerId
required: true
schema:
type: string
- name: nextCursor
in: query
description: paginate
required: false
schema:
type: string
- name: limit
in: query
description: limit counts of documents
required: true
schema:
type: string
tags:
- CustomerBlocked
operationId: customerBlockedList
summary: GET Get all blocked documents for customer
description: This endpoint get all blocked documents for customer
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: []
13 changes: 13 additions & 0 deletions openapi/paths/customer/blocked/list/list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type: object
properties:
nextCursor:
type: string
totalCount:
type: boolean
results:
type: array
items:
$ref: ../_types/blocked.yaml
required:
- totalCount
- results
12 changes: 12 additions & 0 deletions openapi/paths/customer/blocked/list/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: ../_types/blocked.yaml
required:
- success
- payload
42 changes: 42 additions & 0 deletions openapi/paths/customer/blocked/range/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:
- CustomerBlocked
operationId: customerBlockedRange
summary: GET Get all blocked documents for customer
description: This endpoint get all blocked documents
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: []
12 changes: 12 additions & 0 deletions openapi/paths/customer/blocked/range/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: ../_types/blocked.yaml
required:
- success
- payload
1 change: 1 addition & 0 deletions src/functions/blocked/blocked.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const BlockedMongooseSchema = new mongoose.Schema<
type: Number,
index: true,
},
title: String,
start: {
index: true,
required: true,
Expand Down
1 change: 1 addition & 0 deletions src/functions/blocked/blocked.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const BlockDateZodSchema = z.object({
customerId: GidFormat,
end: z.coerce.date(),
start: z.coerce.date(),
title: z.string(),
});

export type Blocked = z.infer<typeof BlockDateZodSchema>;
35 changes: 35 additions & 0 deletions src/functions/customer-blocked.function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import "module-alias/register";

import { app } from "@azure/functions";

import { CustomerBlockedControllerCreate } from "./customer/controllers/blocked/create";
import { CustomerBlockedControlleDestroy } from "./customer/controllers/blocked/destroy";
import { CustomerBlockedControllerList } from "./customer/controllers/blocked/list";

app.http("customerBlockedDestroy", {
methods: ["DELETE"],
authLevel: "anonymous",
route: "customer/{customerId?}/blocked/{blockedId?}",
handler: CustomerBlockedControlleDestroy,
});

app.http("customerBlockedCreate", {
methods: ["POST"],
authLevel: "anonymous",
route: "customer/{customerId?}/blocked",
handler: CustomerBlockedControllerCreate,
});

app.http("customerBlockedList", {
methods: ["GET"],
authLevel: "anonymous",
route: "customer/{customerId?}/blocked/list",
handler: CustomerBlockedControllerList,
});

app.http("customerBlockedRange", {
methods: ["GET"],
authLevel: "anonymous",
route: "customer/{customerId?}/blocked/range",
handler: CustomerBlockedControllerList,
});
3 changes: 1 addition & 2 deletions src/functions/customer/controllers/blocked/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { z } from "zod";
import { BlockDateZodSchema } from "~/functions/blocked/blocked.types";
import { _ } from "~/library/handler";
import { CustomerBlockedServiceCreate } from "../../services/blocked/create";
import { CustomerServiceUpdate } from "../../services/customer";

export type CustomerControllerCreateRequest = {
query: z.infer<typeof CustomerBlockedControllerQuerySchema>;
Expand All @@ -18,7 +17,7 @@ export const CustomerBlockedControllerCreateSchema = BlockDateZodSchema.omit({
}).strip();

export type CustomerBlockedControllerCreateResponse = Awaited<
ReturnType<typeof CustomerServiceUpdate>
ReturnType<typeof CustomerBlockedServiceCreate>
>;

export const CustomerBlockedControllerCreate = _(
Expand Down
Loading

0 comments on commit 2dc4b86

Please sign in to comment.