Merge pull request #30 from calcom/fix-availabilities
commit
a1dcfa59bc
|
@ -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" });
|
||||
|
|
|
@ -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>[];
|
||||
};
|
||||
|
||||
|
|
|
@ -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",
|
||||
});
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue