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

Add specialties #118

Merged
merged 6 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
"request": "attach",
"port": 9229,
"preLaunchTask": "func: host start"
},
{
"type": "node",
"request": "launch",
"name": "Debug Jest Tests",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"${workspaceFolder}/src/functions/user/services/availability/get.spec.ts"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js"
}
}
]
}
}
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ module.exports = {
moduleNameMapper: {
"^~/(.*)$": "<rootDir>/src/$1",
},
setupFiles: ["./jest/load-env.js"],
};
4 changes: 4 additions & 0 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ components:
$ref: paths/user/list/response.yaml
UsersProfessionsResponse:
$ref: paths/user/professions/response.yaml
UsersSpecialtiesResponse:
$ref: paths/user/specialties/response.yaml

# UserAvailability
UserAvailabilitySlot:
Expand Down Expand Up @@ -326,6 +328,8 @@ paths:
$ref: "./paths/user/schedule/get-by-location/index.yaml"
/users/professions:
$ref: "./paths/user/professions/index.yaml"
/users/specialties:
$ref: "./paths/user/specialties/index.yaml"
/user/{username}/availability/{locationId}/generate:
$ref: "paths/user/availability/generate/index.yaml"
/user/{username}/availability/{locationId}/get:
Expand Down
9 changes: 8 additions & 1 deletion openapi/paths/user/list/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ parameters:
type: string
- name: profession
in: query
description: profession like makeup_artist
description: profession
schema:
type: string
- name: specialties
in: query
description: specialties
schema:
type: array
items:
type: string
- name: sortOrder
in: query
description: asc or desc
Expand Down
23 changes: 23 additions & 0 deletions openapi/paths/user/specialties/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
get:
tags:
- User
operationId: usersSpecialties
summary: GET Get all users specialties with total count
description: This endpoint get all users
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: []
13 changes: 13 additions & 0 deletions openapi/paths/user/specialties/response.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type: object
properties:
success:
type: boolean
example: true
payload:
type: object
additionalProperties:
type: number

required:
- success
- payload
8 changes: 8 additions & 0 deletions src/functions/user.function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { app } from "@azure/functions";
import { UserControllerGet } from "./user/controllers/user/get";
import { UserControllerList } from "./user/controllers/user/list";
import { UserControllerProfessions } from "./user/controllers/user/professions";
import { UserControllerSpecialties } from "./user/controllers/user/specialties";
import { UserControllerUsernameTaken } from "./user/controllers/user/username-taken";

app.http("userGet", {
Expand Down Expand Up @@ -33,3 +34,10 @@ app.http("usersProfessions", {
route: "users/professions",
handler: UserControllerProfessions,
});

app.http("usersSpecialties", {
methods: ["GET"],
authLevel: "anonymous",
route: "users/specialties",
handler: UserControllerSpecialties,
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from "zod";
import { _ } from "~/library/handler";

import { CustomerProductsServiceList } from "~/functions/customer/services/product/list";
import { UserServiceGetCustomerId } from "~/functions/user";
import { UserServiceGetCustomerId } from "../../services/user/get-customer-id";

export type UserProductsControllerListByScheduleRequest = {
query: z.infer<typeof UserProductsControllerListByScheduleSchema>;
Expand Down
2 changes: 1 addition & 1 deletion src/functions/user/controllers/schedule/get-by-product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from "zod";

import { _ } from "~/library/handler";
import { UserScheduleServiceGetByProductId as UserScheduleServiceGetByProduct } from "../../services/schedule/get-by-product";
import { UserServiceGetCustomerId } from "../../services/user";
import { UserServiceGetCustomerId } from "../../services/user/get-customer-id";

export type UserScheduleControllerGetByProductRequest = {
query: z.infer<typeof UserScheduleControllerGetByProductQuerySchema>;
Expand Down
2 changes: 1 addition & 1 deletion src/functions/user/controllers/schedule/locations-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from "zod";

import { _ } from "~/library/handler";
import { UserScheduleServiceLocationsList } from "../../services/schedule/locations-list";
import { UserServiceGet } from "../../services/user";
import { UserServiceGet } from "../../services/user/get";

export type UserScheduleControllerLocationsListRequest = {
query: z.infer<typeof UserScheduleControllerLocationsListQuerySchema>;
Expand Down
3 changes: 1 addition & 2 deletions src/functions/user/controllers/user/get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { z } from "zod";
import { _ } from "~/library/handler";

import { UserServiceGet } from "../../services/user";
import { UserServiceGet } from "../../services/user/get";

export type UserControllerGetRequest = {
query: z.infer<typeof UserServiceGetSchema>;
Expand Down
5 changes: 3 additions & 2 deletions src/functions/user/controllers/user/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { _ } from "~/library/handler";

import { z } from "zod";
import { NumberOrStringType } from "~/library/zod";
import { UserServiceList } from "../../services/user";
import { UserServiceList } from "../../services/user/list";

export type UserControllerListRequest = {
query: z.infer<typeof UserControllerListSchema>;
Expand All @@ -17,6 +17,7 @@ export const UserControllerListSchema = z.object({
nextCursor: z.string().optional(),
limit: NumberOrStringType.optional(),
profession: z.string().optional(),
specialties: z.array(z.string()).optional(),
sortOrder: z.nativeEnum(SortOrder).optional(),
});

Expand All @@ -27,6 +28,6 @@ export type UserControllerListResponse = Awaited<
export const UserControllerList = _(
async ({ query }: UserControllerListRequest) => {
const validateData = UserControllerListSchema.parse(query);
return await UserServiceList(validateData);
return UserServiceList(validateData);
}
);
3 changes: 1 addition & 2 deletions src/functions/user/controllers/user/professions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { _ } from "~/library/handler";

import { UserServiceProfessions } from "../../services/user";
import { UserServiceProfessions } from "../../services/user/professions";

export type UserControllerProfessionsResponse = Awaited<
ReturnType<typeof UserServiceProfessions>
Expand Down
23 changes: 23 additions & 0 deletions src/functions/user/controllers/user/specialties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { _ } from "~/library/handler";

import { z } from "zod";
import { UserServiceSpecialties } from "../../services/user/specialties";

export type UserControllerSpecialtiesRequest = {
query: z.infer<typeof UserControllerSpecialtiesSchema>;
};

export const UserControllerSpecialtiesSchema = z.object({
profession: z.string(),
});

export type UserControllerSpecialtiesResponse = Awaited<
ReturnType<typeof UserServiceSpecialties>
>;

export const UserControllerSpecialties = _(
async ({ query }: UserControllerSpecialtiesRequest) => {
const validateData = UserControllerSpecialtiesSchema.parse(query);
return UserServiceSpecialties(validateData);
}
);
3 changes: 1 addition & 2 deletions src/functions/user/controllers/user/username-taken.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { z } from "zod";
import { _ } from "~/library/handler";

import { UserServiceUsernameTaken } from "../../services/user";
import { UserServiceUsernameTaken } from "../../services/user/username-taken";

export type UserControllerUsernameTakenRequest = {
query: z.infer<typeof UserControllerUsernameTakenSchema>;
Expand Down
1 change: 0 additions & 1 deletion src/functions/user/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./services/user";
export * from "./user.model";
export * from "./user.schema";
export * from "./user.types";
3 changes: 2 additions & 1 deletion src/functions/user/services/availability/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { findStartAndEndDate } from "~/library/availability/find-start-end-date-
import { generateAvailability } from "~/library/availability/generate-availability";
import { removeBookedSlots } from "~/library/availability/remove-booked-slots";
import { StringOrObjectId } from "~/library/zod";
import { UserServiceGetCustomerId } from "../user";

import { UserServiceGetCustomerId } from "../user/get-customer-id";
import { UserAvailabilityServiceGetOrders } from "./get-orders";

export type UserAvailabilityServiceGenerateProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/user/services/location.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LocationModel } from "~/functions/location";
import { NotFoundError } from "~/library/handler";
import { StringOrObjectId } from "~/library/zod";
import { UserServiceGet } from "./user";
import { UserServiceGet } from "./user/get";

export const UserLocationServiceGetOne = async ({
username,
Expand Down
2 changes: 1 addition & 1 deletion src/functions/user/services/products/get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ScheduleModel } from "~/functions/schedule";
import { NotFoundError } from "~/library/handler";
import { UserServiceGetCustomerId } from "../user";
import { UserServiceGetCustomerId } from "../user/get-customer-id";

export type UserProductServiceGetFilter = {
username: string;
Expand Down
3 changes: 2 additions & 1 deletion src/functions/user/services/schedule/get-by-location.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import mongoose from "mongoose";
import { ILocationDocument, Location } from "~/functions/location";
import { Schedule, ScheduleModel, ScheduleProduct } from "~/functions/schedule";
import { UserServiceGetCustomerId } from "~/functions/user";

import { NotFoundError } from "~/library/handler";
import { StringOrObjectId } from "~/library/zod";
import { UserServiceGetCustomerId } from "../user/get-customer-id";

export type UserScheduleServiceGetByLocationProps = {
username: string;
Expand Down
110 changes: 0 additions & 110 deletions src/functions/user/services/user.spec.ts

This file was deleted.

Loading
Loading