From dd13539d57fd89467f7ccda42ecc7996eb4cd750 Mon Sep 17 00:00:00 2001 From: Aydan Pirani Date: Sun, 26 May 2024 00:46:33 -0700 Subject: [PATCH] linting --- src/config.ts | 10 ++-- src/services/auth/auth-utils.ts | 2 +- .../mail/templates/templates-subrouter.ts | 50 +++++++++++++------ 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/config.ts b/src/config.ts index 3998878..e968b3a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -28,12 +28,12 @@ export const Config = { // AUTH_CALLBACK_URI_BASE: "http://localhost:3000/auth/callback/", AUTH_CALLBACK_URI_BASE: "https://api.reflectionsprojections.org/auth/callback/", - + AUTH_ADMIN_WHITELIST: new Set([ - "apirani2@illinois.edu", // Aydan Pirani (Dev) - "divyack2@illinois.edu", // Divya Koya (Dev) - "ritikav2@illinois.edu", // Ritika Vithani (Director) - "ojaswee2@illinois.edu", // Ojaswee Chaudhary (Director) + "apirani2@illinois.edu", // Aydan Pirani (Dev) + "divyack2@illinois.edu", // Divya Koya (Dev) + "ritikav2@illinois.edu", // Ritika Vithani (Director) + "ojaswee2@illinois.edu", // Ojaswee Chaudhary (Director) ]), JWT_SIGNING_SECRET: getEnv("JWT_SIGNING_SECRET"), diff --git a/src/services/auth/auth-utils.ts b/src/services/auth/auth-utils.ts index c71c322..31df201 100644 --- a/src/services/auth/auth-utils.ts +++ b/src/services/auth/auth-utils.ts @@ -17,7 +17,7 @@ export function createGoogleStrategy(device: string) { const userId = `user${profile.id}`; const name = profile.displayName; const email = profile._json.email; - + let roles = []; if (Config.AUTH_ADMIN_WHITELIST.has(email ?? "")) { diff --git a/src/services/mail/templates/templates-subrouter.ts b/src/services/mail/templates/templates-subrouter.ts index 1ff7e72..6333076 100644 --- a/src/services/mail/templates/templates-subrouter.ts +++ b/src/services/mail/templates/templates-subrouter.ts @@ -4,11 +4,8 @@ import { Role } from "../../auth/auth-models"; import { Database } from "../../../database"; import { StatusCodes } from "http-status-codes"; import { TemplateValidator } from "./templates-schema"; -import { z } from "zod"; import { Config } from "../../../config"; -type TemplateData = z.infer; - const templatesSubRouter = Router(); templatesSubRouter.get( @@ -27,10 +24,18 @@ templatesSubRouter.post( async (req, res) => { try { let templateData = TemplateValidator.parse(req.body); - let substitutions = templateData.content.matchAll(Config.MAIL_TEMPLATE_REGEX) - const subVars = Array.from(substitutions, substitutions => substitutions[1]); + let substitutions = templateData.content.matchAll( + Config.MAIL_TEMPLATE_REGEX + ); + const subVars = Array.from( + substitutions, + (substitutions) => substitutions[1] + ); - await Database.TEMPLATES.create({...templateData, substitutions: subVars}); + await Database.TEMPLATES.create({ + ...templateData, + substitutions: subVars, + }); return res.sendStatus(StatusCodes.CREATED); } catch (error) { return res.status(StatusCodes.BAD_REQUEST).send(error); @@ -44,13 +49,23 @@ templatesSubRouter.put( async (req, res) => { try { let templateData = TemplateValidator.parse(req.body); - let substitutions = templateData.content.matchAll(Config.MAIL_TEMPLATE_REGEX) - const subVars = Array.from(substitutions, substitutions => substitutions[1]); + let substitutions = templateData.content.matchAll( + Config.MAIL_TEMPLATE_REGEX + ); + const subVars = Array.from( + substitutions, + (substitutions) => substitutions[1] + ); + + const updateResult = await Database.TEMPLATES.findOneAndUpdate( + { templateId: templateData.templateId }, + { ...templateData, substitutions: subVars } + ); - const updateResult = await Database.TEMPLATES.findOneAndUpdate({templateId: templateData.templateId}, {...templateData, substitutions: subVars}); - if (!updateResult) { - return res.status(StatusCodes.NOT_FOUND).send({error: "NoSuchId"}); + return res + .status(StatusCodes.NOT_FOUND) + .send({ error: "NoSuchId" }); } return res.sendStatus(StatusCodes.OK); @@ -65,9 +80,13 @@ templatesSubRouter.get( RoleChecker([Role.Values.STAFF]), async (req, res) => { const templateId = req.params.TEMPLATEID; - const templateInfo = await Database.TEMPLATES.findOne({templateId: templateId}); + const templateInfo = await Database.TEMPLATES.findOne({ + templateId: templateId, + }); if (!templateInfo) { - return res.status(StatusCodes.NOT_FOUND).send({error: "NoSuchId"}); + return res + .status(StatusCodes.NOT_FOUND) + .send({ error: "NoSuchId" }); } return res.status(StatusCodes.OK).json(templateInfo?.toObject()); } @@ -79,9 +98,10 @@ templatesSubRouter.delete( async (req, res) => { try { const templateId = req.params.TEMPLATEID; - await Database.TEMPLATES.findOneAndDelete({templateId: templateId}); + await Database.TEMPLATES.findOneAndDelete({ + templateId: templateId, + }); return res.sendStatus(StatusCodes.NO_CONTENT); - } catch (error) { return res.status(StatusCodes.BAD_REQUEST).send(error); }