diff --git a/biome.json b/biome.json index a599672..82c7743 100644 --- a/biome.json +++ b/biome.json @@ -28,6 +28,6 @@ "formatter": { "indentStyle": "tab", "indentWidth": 2, - "lineWidth": 64 + "lineWidth": 80 } -} +} \ No newline at end of file diff --git a/src/controllers/auth.controller.ts b/src/controllers/auth.controller.ts index 00854bd..739eb81 100644 --- a/src/controllers/auth.controller.ts +++ b/src/controllers/auth.controller.ts @@ -22,10 +22,7 @@ const logger = new Logger({ * - error: "exist" if the user already exists * - Otherwise, the registered user data */ -async function registerUser( - req: Request, - res: Response, -): Promise { +async function registerUser(req: Request, res: Response): Promise { const body = req.body; if (!body) { logger.warn(`Invalid input data (${req.ip})`); @@ -59,8 +56,7 @@ async function registerUser( lastName: `${body.lastName}`, }; - const RegisterServiceResult = - await UserService.register(sanitizeData); + const RegisterServiceResult = await UserService.register(sanitizeData); if (RegisterServiceResult.error === "gdprNotApproved") { logger.warn(`GDPR not approved (${req.ip})`); @@ -79,10 +75,7 @@ async function registerUser( // SUCCESS logger.info(`User registered successfully (${req.ip})`); - return res - .type("application/json") - .status(201) - .json(RegisterServiceResult); + return res.type("application/json").status(201).json(RegisterServiceResult); } /** @@ -93,10 +86,7 @@ async function registerUser( * * @return {Promise} A promise that resolves when the user is logged in or rejects with an error. */ -async function loginUser( - req: Request, - res: Response, -): Promise { +async function loginUser(req: Request, res: Response): Promise { const body = req.body; if (!body) { res.type("application/json").status(400).json({ @@ -131,10 +121,7 @@ async function loginUser( message: "Invalid password.", }); } - res - .type("application/json") - .status(200) - .json(LoginServiceResult); + res.type("application/json").status(200).json(LoginServiceResult); } async function getAllUsers(req: Request, res: Response) { @@ -170,10 +157,7 @@ async function getAllUsers(req: Request, res: Response) { error: "Internal server error", }); } - return res - .type("application/json") - .status(200) - .json(AllUserResponse); + return res.type("application/json").status(200).json(AllUserResponse); } async function getUser(req: Request, res: Response) { @@ -267,14 +251,11 @@ async function editUser(req: Request, res: Response) { //TODO Interface const modifiedData = {}; //@ts-ignore - if (body.firstName) - modifiedData.firstName = `${body.firstName}`; + if (body.firstName) modifiedData.firstName = `${body.firstName}`; //@ts-ignore - if (body.lastName) - modifiedData.lastName = `${body.lastName}`; + if (body.lastName) modifiedData.lastName = `${body.lastName}`; //@ts-ignore - if (body.displayName) - modifiedData.displayName = `${body.displayName}`; + if (body.displayName) modifiedData.displayName = `${body.displayName}`; //TODO Case handled with hashing by the service. //if (body.password) modifiedData.password = `${body.password}`; @@ -290,31 +271,21 @@ async function editUser(req: Request, res: Response) { }); } if (EditUserServiceResult.error !== "none") { - logger.error( - `Error occurred during user edit (${req.ip})`, - ); + logger.error(`Error occurred during user edit (${req.ip})`); return res.type("application/json").status(500).json({ error: "Internal server error", }); } - return res - .type("application/json") - .status(200) - .json(EditUserServiceResult); + return res.type("application/json").status(200).json(EditUserServiceResult); } //Not itself or - logger.warn( - `Unauthorized access attempt, not self or admin (${req.ip})`, - ); + logger.warn(`Unauthorized access attempt, not self or admin (${req.ip})`); return res.type("application/json").status(403).json({ error: "Unauthorized", }); } -async function deleteUser( - req: Request, - res: Response, -): Promise { +async function deleteUser(req: Request, res: Response): Promise { const authHeader = req.headers.authorization; const bearerToken = authHeader?.split(" ")[1]; if (!bearerToken) { @@ -340,13 +311,9 @@ async function deleteUser( }); } if (sourceUser.is_admin || sourceUser.id === payload.sub) { - const deleteUserServiceResult = await UserService.delete( - `${targetUserId}`, - ); + const deleteUserServiceResult = await UserService.delete(`${targetUserId}`); if (!deleteUserServiceResult) { - logger.error( - `Error occurred during user delete (${req.ip})`, - ); + logger.error(`Error occurred during user delete (${req.ip})`); return res.type("application/json").status(500).json({ error: "Internal server error", }); diff --git a/src/controllers/brand.controller.ts b/src/controllers/brand.controller.ts index 4199401..1d4828e 100644 --- a/src/controllers/brand.controller.ts +++ b/src/controllers/brand.controller.ts @@ -17,14 +17,9 @@ const logger = new Logger({ * * @returns A Promise that resolves to the response object with a status code and a JSON message indicating the success or failure of brand creation. */ -async function createBrand( - req: Request, - res: Response, -): Promise { +async function createBrand(req: Request, res: Response): Promise { const body: IDbBrand = req.body; - const doesExist = await BrandService.getBySlug( - `${body.slug_name}`, - ); + const doesExist = await BrandService.getBySlug(`${body.slug_name}`); if (doesExist) { logger.error("Brand already exists"); return res.status(400).json({ @@ -42,9 +37,7 @@ async function createBrand( error: "Failed to create brand", }); } - logger.info( - `Brand created successfully ! (${body.slug_name})`, - ); + logger.info(`Brand created successfully ! (${body.slug_name})`); return res.status(201).json({ message: "Brand created successfully", }); @@ -57,10 +50,7 @@ async function createBrand( * @param {Response} res - The HTTP response object. * @return {Promise} A promise that resolves with the HTTP response. */ -async function updateBrand( - req: Request, - res: Response, -): Promise { +async function updateBrand(req: Request, res: Response): Promise { const body: IDbBrand = req.body; const brandSlug = req.params["brandSlug"]; if (!brandSlug) { @@ -100,10 +90,7 @@ async function updateBrand( * @param {Response} res - The response object to send the result. * @returns {Promise} - A promise that resolves to the response with the retrieved brand. */ -async function getBySlugBrand( - req: Request, - res: Response, -): Promise { +async function getBySlugBrand(req: Request, res: Response): Promise { const brandSlug = req.params["brandSlug"]; if (!brandSlug) { logger.error("Brand slug is missing"); @@ -129,10 +116,7 @@ async function getBySlugBrand( * @param {Response} res - The response object. * @returns {Promise} - A promise with the response object. */ -async function getAllBrand( - _req: Request, - res: Response, -): Promise { +async function getAllBrand(_req: Request, res: Response): Promise { const brands = await BrandService.getAll(); if (!brands) { logger.error("Failed to retrieve brands"); @@ -156,10 +140,7 @@ async function getAllBrand( * @param {Response} res - The response object. * @returns {Promise} - The response object indicating the success or failure of the delete operation. */ -async function deleteBrand( - req: Request, - res: Response, -): Promise { +async function deleteBrand(req: Request, res: Response): Promise { const brandSlug = req.params["brandSlug"]; if (!brandSlug) { logger.error("Brand slug is missing"); diff --git a/src/controllers/category.controller.ts b/src/controllers/category.controller.ts index 159428d..5d18a37 100644 --- a/src/controllers/category.controller.ts +++ b/src/controllers/category.controller.ts @@ -15,14 +15,9 @@ const logger = new Logger({ * @param {Response} res - The response object to send back to the client. * @returns {Promise} The response object indicating the outcome of the category creation. */ -async function createCategory( - req: Request, - res: Response, -): Promise { +async function createCategory(req: Request, res: Response): Promise { const body: IDbCategory = req.body; - const doesExist = await CategoryService.getBySlug( - `${body.slug_name}`, - ); + const doesExist = await CategoryService.getBySlug(`${body.slug_name}`); if (doesExist) { logger.error("Category already exists"); return res.status(400).json({ @@ -39,9 +34,7 @@ async function createCategory( error: "Failed to create category", }); } - logger.info( - `Category created successfully ! (${body.slug_name})`, - ); + logger.info(`Category created successfully ! (${body.slug_name})`); return res.status(201).json({ message: "Category created successfully", }); @@ -55,10 +48,7 @@ async function createCategory( * * @return {Promise} - A promise that will be resolved with the result of the update operation. */ -async function updateCategory( - req: Request, - res: Response, -): Promise { +async function updateCategory(req: Request, res: Response): Promise { const body: IDbCategory = req.body; const categoryId = req.params["categorySlug"]; if (!categoryId) { @@ -67,9 +57,7 @@ async function updateCategory( error: "Category slug is missing", }); } - const doesExist = await CategoryService.getById( - `${categoryId}`, - ); + const doesExist = await CategoryService.getById(`${categoryId}`); if (!doesExist || !doesExist.id) { logger.error("Category not found"); return res.status(404).json({ @@ -100,10 +88,7 @@ async function updateCategory( * @param {Response} res - The response object to send the result. * @returns {Promise} A Promise that resolves to the response object. */ -async function deleteCategory( - req: Request, - res: Response, -): Promise { +async function deleteCategory(req: Request, res: Response): Promise { const categorySlug = req.params["categorySlug"]; if (!categorySlug) { logger.error("Category slug is missing"); @@ -111,27 +96,21 @@ async function deleteCategory( error: "Category slug is missing", }); } - const doesExist = await CategoryService.getBySlug( - `${categorySlug}`, - ); + const doesExist = await CategoryService.getBySlug(`${categorySlug}`); if (!doesExist || !doesExist.id) { logger.error("Category not found"); return res.status(404).json({ error: "Category not found", }); } - const deleteResult = await CategoryService.delete( - `${doesExist.id}`, - ); + const deleteResult = await CategoryService.delete(`${doesExist.id}`); if (!deleteResult) { logger.error("Failed to delete category"); return res.status(500).json({ error: "Failed to delete category", }); } - logger.info( - `Category deleted successfully! (${categorySlug})`, - ); + logger.info(`Category deleted successfully! (${categorySlug})`); return res.status(200).json({ message: "Category deleted successfully", }); @@ -144,10 +123,7 @@ async function deleteCategory( * @param {Response} res - The response object. * @return {Promise} - A promise that resolves to the response object. */ -async function getAllCategory( - _req: Request, - res: Response, -): Promise { +async function getAllCategory(_req: Request, res: Response): Promise { const categories = await CategoryService.getAll(); if (!categories) { logger.error("Failed to get categories"); @@ -186,18 +162,14 @@ async function getBySlugCategory( error: "Category slug is missing", }); } - const category = await CategoryService.getBySlug( - `${categorySlug}`, - ); + const category = await CategoryService.getBySlug(`${categorySlug}`); if (!category || !category.id) { logger.error("Category not found"); return res.status(404).json({ error: "Category not found", }); } - logger.info( - `Category retrieved successfully! (${categorySlug})`, - ); + logger.info(`Category retrieved successfully! (${categorySlug})`); return res.status(200).json({ id: category.id, display_name: category.display_name, diff --git a/src/controllers/model.controller.ts b/src/controllers/model.controller.ts index 1d6e7ba..94ead48 100644 --- a/src/controllers/model.controller.ts +++ b/src/controllers/model.controller.ts @@ -9,14 +9,9 @@ const logger = new Logger({ name: "ModelController", }); -async function createModel( - req: Request, - res: Response, -): Promise { +async function createModel(req: Request, res: Response): Promise { const body: IDbModel = req.body; - const doesExist = await CategoryService.getBySlug( - `${body.slug_name}`, - ); + const doesExist = await CategoryService.getBySlug(`${body.slug_name}`); if (doesExist) { logger.error("Category already exists"); return res.status(400).json({ @@ -38,22 +33,15 @@ async function createModel( error: "Failed to create category", }); } - logger.info( - `Category created successfully ! (${body.slug_name})`, - ); + logger.info(`Category created successfully ! (${body.slug_name})`); return res.status(201).json({ message: "Category created successfully", }); } -async function updateModel( - req: Request, - res: Response, -): Promise { +async function updateModel(req: Request, res: Response): Promise { const body: IDbModel = req.body; - const doesExist = await ModelService.getBySlug( - `${body.slug_name}`, - ); + const doesExist = await ModelService.getBySlug(`${body.slug_name}`); if (!doesExist) { logger.error("Model does not exist"); return res.status(404).json({ @@ -76,9 +64,7 @@ async function updateModel( error: "Failed to update model", }); } - logger.info( - `Model updated successfully! (${body.slug_name})`, - ); + logger.info(`Model updated successfully! (${body.slug_name})`); return res.status(200).json({ message: "Model updated successfully", }); @@ -99,10 +85,7 @@ async function getAllModel(res: Response): Promise { }); } -async function getModelBySlug( - req: Request, - res: Response, -): Promise { +async function getModelBySlug(req: Request, res: Response): Promise { const slug = req.params["modelSlug"]; if (!slug) { logger.error("Invalid slug"); @@ -122,10 +105,7 @@ async function getModelBySlug( }); } -async function deleteModel( - req: Request, - res: Response, -): Promise { +async function deleteModel(req: Request, res: Response): Promise { const modelSlug = req.params["modelSlug"]; if (!modelSlug) { logger.error("Invalid model slug"); @@ -141,9 +121,7 @@ async function deleteModel( error: "Failed to delete model", }); } - logger.info( - `Model deleted successfully! (SLUG: ${modelSlug})`, - ); + logger.info(`Model deleted successfully! (SLUG: ${modelSlug})`); return res.status(200).json({ message: "Model deleted successfully", }); diff --git a/src/routes/auth/authRouter.ts b/src/routes/auth/authRouter.ts index 65d6480..f700a44 100644 --- a/src/routes/auth/authRouter.ts +++ b/src/routes/auth/authRouter.ts @@ -10,25 +10,16 @@ AuthRouter.route("/register").post(AuthController.register); // PATCH //TODO - To test -AuthRouter.route("/me").patch( - UserGuard, - AuthController.editUser, -); +AuthRouter.route("/me").patch(UserGuard, AuthController.editUser); // GET AuthRouter.route("/me").get(UserGuard, AuthController.getSelf); // DELETE -AuthRouter.route("/me").delete( - UserGuard, - AuthController.deleteSelf, -); +AuthRouter.route("/me").delete(UserGuard, AuthController.deleteSelf); // GET -AuthRouter.route("/all").get( - AdminGuard, - AuthController.getAllUsers, -); +AuthRouter.route("/all").get(AdminGuard, AuthController.getAllUsers); // GET AuthRouter.route("/user/:targetId") diff --git a/src/routes/catalog/catalogRouter.ts b/src/routes/catalog/catalogRouter.ts index accbd83..ce69b0b 100644 --- a/src/routes/catalog/catalogRouter.ts +++ b/src/routes/catalog/catalogRouter.ts @@ -9,10 +9,7 @@ const CatalogRouter: Router = express.Router(); //-- MODELS >> -CatalogRouter.route("/model/new").get( - AdminGuard, - ModelController.create, -); +CatalogRouter.route("/model/new").get(AdminGuard, ModelController.create); CatalogRouter.route("/model/all").get(ModelController.getAll); @@ -23,14 +20,9 @@ CatalogRouter.route("/model/:modelSlug") //-- CATEGORY >> -CatalogRouter.route("/category/new").get( - AdminGuard, - CategoryController.create, -); +CatalogRouter.route("/category/new").get(AdminGuard, CategoryController.create); -CatalogRouter.route("/category/all").get( - CategoryController.getAll, -); +CatalogRouter.route("/category/all").get(CategoryController.getAll); CatalogRouter.route("/category/:categorySlug") .get(UserGuard, CategoryController.getBySlug) @@ -39,10 +31,7 @@ CatalogRouter.route("/category/:categorySlug") //-- BRAND >> -CatalogRouter.route("/brand/new").post( - AdminGuard, - BrandController.create, -); +CatalogRouter.route("/brand/new").post(AdminGuard, BrandController.create); CatalogRouter.route("/brand/all").get(BrandController.getAll); CatalogRouter.route("/brand/:brandSlug") .get(UserGuard, BrandController.getBySlug) diff --git a/src/services/brand.service.ts b/src/services/brand.service.ts index 49c9ee9..e3f1a7d 100644 --- a/src/services/brand.service.ts +++ b/src/services/brand.service.ts @@ -27,19 +27,14 @@ async function createBrand(data: IDbBrand): Promise { }; } const brandId = uuidv4(); - const createdBrand = await MysqlService.Brand.insert( - DbHandler, - { - id: brandId, - slug_name: `${data.slug_name}`, - display_name: `${data.display_name}`, - image_blob: data.image_blob, - }, - ); + const createdBrand = await MysqlService.Brand.insert(DbHandler, { + id: brandId, + slug_name: `${data.slug_name}`, + display_name: `${data.display_name}`, + image_blob: data.image_blob, + }); if (createdBrand) { - logger.info( - `Brand created successfully (${data.slug_name})`, - ); + logger.info(`Brand created successfully (${data.slug_name})`); return { success: true, brand: createdBrand, @@ -71,19 +66,14 @@ async function updateBrand(data: IDbBrand): Promise { logger.error(`Brand already exists (${data.slug_name})`); return false; } - const updatedBrand = await MysqlService.Brand.update( - DbHandler, - { - id: data.id, - slug_name: `${data.slug_name}`, - display_name: `${data.display_name}`, - image_blob: data.image_blob, - }, - ); + const updatedBrand = await MysqlService.Brand.update(DbHandler, { + id: data.id, + slug_name: `${data.slug_name}`, + display_name: `${data.display_name}`, + image_blob: data.image_blob, + }); if (updatedBrand) { - logger.info( - `Brand updated successfully (${data.slug_name})`, - ); + logger.info(`Brand updated successfully (${data.slug_name})`); return true; } logger.error(`Failed to update brand (${data.slug_name})`); @@ -100,9 +90,7 @@ async function getAllBrand(): Promise | false> { logger.error("Failed to retrieve brands"); return false; } - logger.info( - `Retrieved all brands successfully (${brands.length})`, - ); + logger.info(`Retrieved all brands successfully (${brands.length})`); return brands; } @@ -112,24 +100,17 @@ async function getAllBrand(): Promise | false> { * @param {string} brandSlug - The slug of the brand. * @returns {Promise} - A promise that resolves to the retrieved brand object or false if the brand is not found. */ -async function getBySlugBrand( - brandSlug: string, -): Promise { +async function getBySlugBrand(brandSlug: string): Promise { if (!brandSlug) { logger.error("Brand slug is missing"); return false; } - const brand = await MysqlService.Brand.getBySlug( - DbHandler, - brandSlug, - ); + const brand = await MysqlService.Brand.getBySlug(DbHandler, brandSlug); if (!brand) { logger.error(`Brand not found (${brandSlug})`); return false; } - logger.info( - `Retrieved brand by slug successfully (${brandSlug})`, - ); + logger.info(`Retrieved brand by slug successfully (${brandSlug})`); return brand; } @@ -140,9 +121,7 @@ async function getBySlugBrand( * * @returns {Promise} A promise that resolves to the retrieved brand object, or false if the brand is not found or the ID is invalid. */ -async function getByIdBrand( - brandId: string, -): Promise { +async function getByIdBrand(brandId: string): Promise { if (!brandId) { logger.error("Brand ID is missing"); return false; @@ -151,17 +130,12 @@ async function getByIdBrand( logger.error("Invalid brand ID"); return false; } - const brand = await MysqlService.Brand.getById( - DbHandler, - brandId, - ); + const brand = await MysqlService.Brand.getById(DbHandler, brandId); if (!brand) { logger.error(`Brand not found (${brandId})`); return false; } - logger.info( - `Retrieved brand by ID successfully (${brandId})`, - ); + logger.info(`Retrieved brand by ID successfully (${brandId})`); return brand; } @@ -185,10 +159,7 @@ async function deleteBrand(brandId: string): Promise { return false; } //TODO verify if as models linked - const deletedBrand = await MysqlService.Brand.delete( - DbHandler, - brandId, - ); + const deletedBrand = await MysqlService.Brand.delete(DbHandler, brandId); if (!deletedBrand) { logger.error(`Failed to delete brand (${brandId})`); return false; diff --git a/src/services/category.service.ts b/src/services/category.service.ts index 48b4af6..a80029c 100644 --- a/src/services/category.service.ts +++ b/src/services/category.service.ts @@ -15,12 +15,8 @@ const logger = new Logger({ * @returns {Promise} A promise that resolves with the created category. * If an error occurs, the promise will reject with the error. */ -async function createCategory( - data: IDbCategory, -): Promise { - logger.info( - `Creating a new category... (${data.display_name})`, - ); +async function createCategory(data: IDbCategory): Promise { + logger.info(`Creating a new category... (${data.display_name})`); try { await MysqlService.Category.insert(DbHandler, { id: uuidv4(), @@ -69,9 +65,7 @@ async function updateCategory(data: IDbCategory) { * * @returns {Promise> | null} Promise that resolves to an array of IDbCategory objects or null if an error occurred. */ -async function getAll(): Promise -> | null> { +async function getAll(): Promise> | null> { try { logger.info("Getting all categories..."); return await MysqlService.Category.getAll(DbHandler); @@ -87,15 +81,10 @@ async function getAll(): Promise} - A promise that resolves to the category object or null if not found */ -async function getBySlug( - slug: string, -): Promise { +async function getBySlug(slug: string): Promise { try { logger.info(`Getting category by slug... (${slug})`); - return await MysqlService.Category.getBySlug( - DbHandler, - slug, - ); + return await MysqlService.Category.getBySlug(DbHandler, slug); } catch (error) { logger.error(`Error getting category by slug: ${error}`); return null; @@ -108,9 +97,7 @@ async function getBySlug( * @param {string} id - The id of the category to retrieve. * @returns {Promise} - A Promise that resolves with the retrieved category object or null if not found. */ -async function getById( - id: string, -): Promise { +async function getById(id: string): Promise { try { logger.info(`Getting category by id... (${id})`); return await MysqlService.Category.getById(DbHandler, id); diff --git a/src/services/credential.service.ts b/src/services/credential.service.ts index cf678a9..bcab534 100644 --- a/src/services/credential.service.ts +++ b/src/services/credential.service.ts @@ -9,10 +9,7 @@ export async function getHashFromPassword(password: string) { } //ToTest -export async function comparePassword( - password: string, - hash: string, -) { +export async function comparePassword(password: string, hash: string) { return await Argon2id.verify(hash, password, { secret: Buffer.from(`${process.env["HASH_SECRET"]}`), algorithm: 2, diff --git a/src/services/jwt.service.ts b/src/services/jwt.service.ts index 91a0f0d..a7db961 100644 --- a/src/services/jwt.service.ts +++ b/src/services/jwt.service.ts @@ -61,9 +61,7 @@ async function JwtSignService( .setIssuer(`${process.env["JWT_SECRET"]} - Mathis HERRIOT`) .setAudience(audience) .setExpirationTime(expTime) - .sign( - new TextEncoder().encode(`${process.env["JWT_SECRET"]}`), - ); + .sign(new TextEncoder().encode(`${process.env["JWT_SECRET"]}`)); } const JwtService = { diff --git a/src/services/model.service.ts b/src/services/model.service.ts index e643b9d..bee21cb 100644 --- a/src/services/model.service.ts +++ b/src/services/model.service.ts @@ -72,18 +72,13 @@ async function updateModel(data: IDbModel): Promise { * @param {string} modelSlug - The slug of the model to be deleted. * @return {Promise} - A promise that resolves to true if the deletion is successful, else false. */ -async function deleteModel( - modelSlug: string, -): Promise { +async function deleteModel(modelSlug: string): Promise { if (!modelSlug) { logger.error("Model slug is missing"); return false; } logger.info(`Deleting model with ID: ${modelSlug}`); - const doesExist = await MysqlService.Model.getBySlug( - DbHandler, - modelSlug, - ); + const doesExist = await MysqlService.Model.getBySlug(DbHandler, modelSlug); if (!doesExist || !doesExist.id) { logger.warn(`Model with slug ${modelSlug} not found`); return false; @@ -104,15 +99,10 @@ async function deleteModel( * @param {string} modelSlug - The slug of the model to be fetched. * @return {Promise} - A promise that resolves to the model if found, else null. */ -async function getBySlugModel( - modelSlug: string, -): Promise { +async function getBySlugModel(modelSlug: string): Promise { logger.info(`Fetching model with slug: ${modelSlug}`); try { - const model = await MysqlService.Model.getBySlug( - DbHandler, - modelSlug, - ); + const model = await MysqlService.Model.getBySlug(DbHandler, modelSlug); if (!model) { logger.warn(`Model with slug ${modelSlug} not found`); return null; diff --git a/src/validators/AdminGuard.ts b/src/validators/AdminGuard.ts index 1a88c60..6e5b84d 100644 --- a/src/validators/AdminGuard.ts +++ b/src/validators/AdminGuard.ts @@ -13,14 +13,9 @@ const UNAUTHORIZED = 401; const FORBIDDEN = 403; const UNAUTH_MESSAGE = "Missing Authorization Header"; const INVALID_TOKEN_MESSAGE = "Invalid or expired token."; -const PERMISSON_NOT_VALID = - "You are missing the required permission."; +const PERMISSON_NOT_VALID = "You are missing the required permission."; -async function AdminGuard( - req: Request, - res: Response, - next: NextFunction, -) { +async function AdminGuard(req: Request, res: Response, next: NextFunction) { const authHeader = req.headers.authorization; if (!authHeader) { logger.warn(`Invalid header (${req.ip})`); @@ -40,11 +35,10 @@ async function AdminGuard( if (token) { // @ts-ignore - const isSourceAdmin = - await MysqlService.User.getAdminStateForId( - DbHandler, - token.sub, - ); + const isSourceAdmin = await MysqlService.User.getAdminStateForId( + DbHandler, + token.sub, + ); if (isSourceAdmin === true) next(); return res.status(FORBIDDEN).json({ message: PERMISSON_NOT_VALID, diff --git a/src/validators/UserGuard.ts b/src/validators/UserGuard.ts index e7312ac..1e96e13 100644 --- a/src/validators/UserGuard.ts +++ b/src/validators/UserGuard.ts @@ -14,11 +14,7 @@ const UNAUTH_MESSAGE = "Missing Authorization Header"; const INVALID_TOKEN_MESSAGE = "Invalid or expired token."; const USER_NOT_EXIST = "You dont exist anymore"; -async function UserGuard( - req: Request, - res: Response, - next: NextFunction, -) { +async function UserGuard(req: Request, res: Response, next: NextFunction) { const authHeader = req.headers.authorization; if (!authHeader) { return res.status(UNAUTHORIZED).json({ @@ -44,10 +40,7 @@ async function UserGuard( message: USER_NOT_EXIST, }); } - const user = await MySqlService.User.getById( - DbHandler, - userId, - ); + const user = await MySqlService.User.getById(DbHandler, userId); if (user) { logger.info(`An user do a request. (${user?.username})`); next();