From 3ef240e6b0f99a2a30ed9cba41245a3aca6112c6 Mon Sep 17 00:00:00 2001 From: kj1352 Date: Wed, 13 Oct 2021 12:22:45 +0530 Subject: [PATCH] removed unwanted functions from user-profile --- src/user-profile/routes.ts | 66 ++------------------------------------ 1 file changed, 2 insertions(+), 64 deletions(-) diff --git a/src/user-profile/routes.ts b/src/user-profile/routes.ts index 9269b51..35eb022 100644 --- a/src/user-profile/routes.ts +++ b/src/user-profile/routes.ts @@ -1,75 +1,13 @@ import express from 'express'; -import passport, { use } from 'passport'; -import { getDatabaseClient, DB_NAME } from '../db-utils'; +import passport from 'passport'; import { IUser } from '../../models/user'; export const userProfileRoutes = express.Router(); export const jwtAuthentication = passport.authenticate('jwt', { session: false }); -userProfileRoutes.get('/all-applicants/', jwtAuthentication, async (request, response) => { - const userCollection = getDatabaseClient().db(DB_NAME).collection('users'); - - const user: IUser = (request.user as any); - - if (user.userType === 'ADMIN') { - const allUsers = await userCollection.find({ - userType: 'APPLICANT' - }).toArray(); - - for (let i = 0; i < allUsers.length; i += 1) { - delete allUsers[i].password; - delete allUsers[i].otp; - } - - response.json(allUsers); - } else { - response.status(401); - response.send('Lol, you new to the platform?'); - } - - return; -}); - userProfileRoutes.get('/profile/', jwtAuthentication, async (request, response) => { const user: IUser = (request.user as any); - - response.json({ - id: user._id, - name: user.name, - email: user.email, - isVerified: user.isVerified, - userType: user.userType, - skillSet: user.skillSet, - progress: user.progress, - userDocuments: user.userDocuments - }); - - return; -}); - -userProfileRoutes.post('/profile/', jwtAuthentication, async (request, response) => { - const userCollection = getDatabaseClient().db(DB_NAME).collection('users'); - - const user: IUser = (request.user as any); - - try { - await userCollection.updateOne({ - email: user.email - }, { - $set: { - skillSet: request.body.skillSet || user.skillSet, - progress: request.body.progress || user.progress, - userDocuments: request.body.userDocuments || user.userDocuments, - } - }); - - response.send("Updated"); - } catch(e) { - console.log(e); - response.status(500); - response.send("Weird, could not find the user even though your were authenticated..."); - } - + response.json(user); return; }); \ No newline at end of file