Files
calendar/pages/api/users/_post.ts
T
f02cfc9990 Swagger definition general fixes (#237)
This PR addresses definition errors currently residing within our
swagger doc.
 
~DISCLAIMER: There is still an error for our DELETE booking call, as
open API standard doesn't expect the DELETE call to contain a request
body, but we are requiring it in the way it currently works. Perhaps we
should move those to Query Parameters instead. Thoughts @zomars @emrysal
?~

It was taken care of by @leog and the docs are now updated as per the
endpoint

<img width="247" alt="image"
src="https://user-images.githubusercontent.com/52925846/217799706-21b7c21d-696b-4e20-a682-c8a949694b61.png">
<img width="629" alt="image"
src="https://user-images.githubusercontent.com/52925846/217799842-c903c23a-0b0d-4208-a3e9-01a682eeff97.png">

---------

Co-authored-by: Leo Giovanetti <hello@leog.me>
Co-authored-by: Omar López <zomars@me.com>
2023-02-13 12:52:11 +00:00

94 lines
3.4 KiB
TypeScript

import type { NextApiRequest } from "next";
import { HttpError } from "@calcom/lib/http-error";
import { defaultResponder } from "@calcom/lib/server";
import { schemaUserCreateBodyParams } from "~/lib/validations/user";
/**
* @swagger
* /users:
* post:
* operationId: addUser
* summary: Creates a new user
* parameters:
* - in: query
* name: apiKey
* required: true
* schema:
* type: string
* description: Your API key
* requestBody:
* description: Create a new user
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - email
* - username
* properties:
* email:
* type: string
* format: email
* description: Email that belongs to the user being edited
* username:
* type: string
* description: Username for the user being created
* brandColor:
* description: The new user's brand color
* type: string
* darkBrandColor:
* description: The new user's brand color for dark mode
* type: string
* weekStart:
* description: Start of the week. Acceptable values are one of [SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY]
* type: string
* timeZone:
* description: The new user's time zone. Eg- 'EUROPE/PARIS'
* type: string
* theme:
* description: Default theme for the new user. Acceptable values are one of [DARK, LIGHT]
* type: string
* timeFormat:
* description: The new user's time format. Acceptable values are one of [TWELVE, TWENTY_FOUR]
* type: string
* locale:
* description: The new user's locale. Acceptable values are one of [EN, FR, IT, RU, ES, DE, PT, RO, NL, PT_BR, ES_419, KO, JA, PL, AR, IW, ZH_CH, ZH_TW, CS, SR, SV, VI]
* type: string
* examples:
* user:
* summary: An example of USER
* value:
* email: 'email@example.com'
* username: 'johndoe'
* weekStart: 'MONDAY'
* brandColor: '#555555'
* darkBrandColor: '#111111'
* timeZone: 'EUROPE/PARIS'
* theme: 'LIGHT'
* timeFormat: 'TWELVE'
* locale: 'FR'
* tags:
* - users
* responses:
* 201:
* description: OK, user created
* 400:
* description: Bad request. user body is invalid.
* 401:
* description: Authorization information is missing or invalid.
*/
async function postHandler(req: NextApiRequest) {
const { prisma, isAdmin } = req;
// If user is not ADMIN, return unauthorized.
if (!isAdmin) throw new HttpError({ statusCode: 401, message: "You are not authorized" });
const data = await schemaUserCreateBodyParams.parseAsync(req.body);
const user = await prisma.user.create({ data });
req.statusCode = 201;
return { user };
}
export default defaultResponder(postHandler);