Skip to content

Commit

Permalink
docs: added JSDoc on routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kan-A-Pesh committed Oct 30, 2024
1 parent 4fe5ae4 commit 7ec63b3
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions routes/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const body = z.object({
password: z.string()
});

/**
* Handles the login route.
*/
export default async function Route_Auth_Login(req: Request, res: Response, next: NextFunction) {
const bodyPayload = body.safeParse(req.body);

Expand Down
4 changes: 4 additions & 0 deletions routes/auth/me-qr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import Status from "@/models/status";
import { Request, Response, NextFunction } from "express";
import qr from "qr-base64";

/**
* Generate a QR code with the user's profile URL.
* Returns the base64 encoded QR code.
*/
export default async function Route_Auth_MeQr(req: Request, res: Response, next: NextFunction) {
if (!req.user) {
return Status.send(req, next, {
Expand Down
3 changes: 3 additions & 0 deletions routes/auth/me.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Status from "@/models/status";
import { Request, Response, NextFunction } from "express";

/**
* Returns the authenticated user's UUID
*/
export default async function Route_Auth_Me(req: Request, res: Response, next: NextFunction) {
if (!req.user) {
return Status.send(req, next, {
Expand Down
10 changes: 10 additions & 0 deletions routes/auth/send-mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ const body = z.object({
email: z.string()
});

/**
* Send an email to the specified email address
* to create a user.
*
* The email address must end with @edu.devinci.fr
* and must not be used by an existing user.
*
* Returns the URL of the creation page if the
* request is from an admin (X-ADMIN-KEY header).
*/
export default async function Route_Auth_Sendmail(req: Request, res: Response, next: NextFunction) {
const bodyPayload = body.safeParse(req.body);

Expand Down
3 changes: 3 additions & 0 deletions routes/clubs/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const params = z.object({
id: znumber()
});

/**
* Get a club by id
*/
export default async function Route_Clubs_Get(req: Request, res: Response, next: NextFunction) {
const payload = params.safeParse(req.params);
if (!payload.success) {
Expand Down
4 changes: 4 additions & 0 deletions routes/clubs/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import ClubController from "@/controllers/clubs";
import Status from "@/models/status";
import { NextFunction, Request, Response } from "express";

/**
* Handles the route for listing all clubs.
* Sends a response with a status of 200 and the list of all clubs.
*/
export default async function Route_Clubs_List(req: Request, res: Response, next: NextFunction) {
return Status.send(req, next, {
status: 200,
Expand Down
5 changes: 5 additions & 0 deletions routes/daily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import ClubController from "@/controllers/clubs";
import Status from "@/models/status";
import { NextFunction, Request, Response } from "express";

/**
* Handles the /daily route.
* Retrieves the daily club information.
* Sends a response with a status of 200 and the daily club information.
*/
export default async function Route_Daily_Read(req: Request, res: Response, next: NextFunction) {
const club = await ClubController.getDailyClub();

Expand Down
4 changes: 4 additions & 0 deletions routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Status from "@/models/status";
import { NextFunction, Request, Response } from "express";

/**
* Handles the / route.
* Sends a response with a status of 204 and no data.
*/
export default function Route_Index_Read(req: Request, res: Response, next: NextFunction) {
return Status.send(req, next, {
status: 204
Expand Down
4 changes: 4 additions & 0 deletions routes/users/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const body = z.object({
token: z.string()
});

/**
* Handles the create user route.
* Creates a new user and returns it.
*/
export default async function Route_Users_Create(req: Request, res: Response, next: NextFunction) {
const bodyPayload = body.safeParse(req.body);

Expand Down
8 changes: 8 additions & 0 deletions routes/users/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ const params = z.object({
id: string()
});

/**
* Handles the GET /users/:id route.
* Retrieves the user with the given id
* and sends a response with a status of 200 and the user data.
*
* If the id is invalid, sends a response with a status of 400 and an error message.
* If the user does not exist, sends a response with a status of 404 and an error message.
*/
export default async function Route_Users_Get(req: Request, res: Response, next: NextFunction) {
const payload = params.safeParse(req.params);
if (!payload.success) {
Expand Down
5 changes: 5 additions & 0 deletions routes/users/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const body = z.object({
avatarUrl: z.string().optional()
});

/**
* Handles the PUT /users/:id route.
* Updates the user with the given id based on the provided data.
* Sends a response with a status of 200 and the updated user data.
*/
export default async function Route_Users_Update(req: Request, res: Response, next: NextFunction) {
const paramsPayload = params.safeParse(req.params);
const bodyPayload = body.safeParse(req.body);
Expand Down

0 comments on commit 7ec63b3

Please sign in to comment.