Merge pull request #30 from calcom/fix-availabilities

pull/9078/head
Agusti Fernandez 2022-04-04 23:03:10 +02:00 committed by GitHub
commit a1dcfa59bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 37 deletions

View File

@ -17,7 +17,7 @@ export const verifyApiKey: NextMiddleware = async (req, res, next) => {
res.status(401).json({ error: "Your api key is not valid" });
throw new Error("No api key found");
}
if (apiKey.expiresAt && apiKey.userId && dateInPast(apiKey.expiresAt, today)) {
if (apiKey.expiresAt && apiKey.userId && dateInPast(today, apiKey.expiresAt)) {
res.setHeader("Calcom-User-ID", apiKey.userId);
await next();
} else res.status(401).json({ error: "Your api key is not valid" });

View File

@ -70,7 +70,7 @@ export type AttendeesResponse = BaseResponse & {
export type AvailabilityResponse = BaseResponse & {
data?: Partial<Availability>;
};
export type AvailabilitysResponse = BaseResponse & {
export type AvailabilitiesResponse = BaseResponse & {
data?: Partial<Availability>[];
};

View File

@ -1,23 +0,0 @@
import { withValidation } from "next-validations";
import { z } from "zod";
import { _ApiKeyModel as ApiKey } from "@calcom/prisma/zod";
export const schemaApiKeyBaseBodyParams = ApiKey.omit({ id: true, userId: true, createdAt: true }).partial();
const schemaApiKeyRequiredParams = z.object({
email: z.string().email(),
});
export const schemaApiKeyBodyParams = schemaApiKeyBaseBodyParams.merge(schemaApiKeyRequiredParams);
export const schemaApiKeyPublic = ApiKey.omit({
id: true,
userId: true,
});
export const withValidApiKey = withValidation({
schema: schemaApiKeyBodyParams,
type: "Zod",
mode: "body",
});

View File

@ -3,35 +3,35 @@ import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { AvailabilitysResponse } from "@lib/types";
import { AvailabilitiesResponse } from "@lib/types";
import { schemaAvailabilityPublic } from "@lib/validations/availability";
/**
* @swagger
* /api/availabilites:
* /api/availabilities:
* get:
* summary: Get all availabilites
* summary: Get all availabilities
* tags:
* - availabilites
* - availabilities
* responses:
* 200:
* description: OK
* 401:
* description: Authorization information is missing or invalid.
* 404:
* description: No availabilites were found
* description: No availabilities were found
*/
async function allAvailabilitys(_: NextApiRequest, res: NextApiResponse<AvailabilitysResponse>) {
const availabilites = await prisma.availability.findMany();
const data = availabilites.map((availability) => schemaAvailabilityPublic.parse(availability));
async function allAvailabilities(_: NextApiRequest, res: NextApiResponse<AvailabilitiesResponse>) {
const availabilities = await prisma.availability.findMany();
const data = availabilities.map((availability) => schemaAvailabilityPublic.parse(availability));
if (data) res.status(200).json({ data });
else
(error: Error) =>
res.status(404).json({
message: "No Availabilitys were found",
message: "No Availabilities were found",
error,
});
}
export default withMiddleware("HTTP_GET")(allAvailabilitys);
export default withMiddleware("HTTP_GET")(allAvailabilities);

View File

@ -12,7 +12,7 @@ import {
/**
* @swagger
* /api/availabilites/new:
* /api/availabilities/new:
* post:
* summary: Creates a new availability
* requestBody:
@ -23,7 +23,7 @@ import {
* schema:
* $ref: '#/components/schemas/Availability'
* tags:
* - availabilites
* - availabilities
* responses:
* 201:
* description: OK, availability created