-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get all users endpoint #52
Merged
anjula-sack
merged 11 commits into
sef-global:main
from
Shrenik0321:get-all-users-endpoint
Aug 20, 2023
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fd3ab92
Get all users endpoint
Shrenik0321 be88998
Merge branch 'main' of https://github.com/Shrenik0321/scholarx-backen…
Shrenik0321 38ddb1f
Merge branch 'main' into get-all-users-endpoint
YoshithaRathnayake 0c23030
Merge branch 'main' into get-all-users-endpoint
Shrenik0321 7640d98
Folder structure fix
Shrenik0321 50d0837
Merge branch 'main' of https://github.com/Shrenik0321/scholarx-backen…
Shrenik0321 932e287
Issue fixes
Shrenik0321 2301af2
Merge branch 'get-all-users-endpoint' of https://github.com/Shrenik03…
Shrenik0321 990c846
Unit Test updates
Shrenik0321 17bf386
Testing for Admin role
Shrenik0321 833f565
Issue fixes for Admin role
Shrenik0321 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { Request, Response } from 'express' | ||
import { getAllUsers } from '../services/admin.service' | ||
|
||
export const getAllUsersHandler = async ( | ||
req: Request, | ||
res: Response | ||
): Promise<void> => { | ||
try { | ||
const users = await getAllUsers(req) | ||
if (users && users.length != 0) { | ||
res.status(404).json({ message: 'No users available' }) | ||
} | ||
|
||
res.status(200).json(users) | ||
} catch (err) { | ||
console.error('Error executing query', err) | ||
res.status(500).json({ error: err }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { Express } from 'express' | ||
import supertest from 'supertest' | ||
|
||
let server: Express | ||
let accessToken: string | ||
|
||
describe('Get all users route', () => { | ||
it('should return a 401 when a valid access token is not provided', async () => { | ||
await supertest(server).get('/api/admin/users').expect(401) | ||
}) | ||
|
||
it('should return a 200 with all users from the DB', async () => { | ||
const response = await supertest(server) | ||
.get('/api/me/profile') | ||
.set('Authorization', `Bearer ${accessToken}`) | ||
.expect(200) | ||
|
||
const userProfiles = response.body | ||
|
||
userProfiles.forEach((userProfile: Object) => { | ||
expect(userProfile).toHaveProperty('created_at') | ||
expect(userProfile).toHaveProperty('updated_at') | ||
expect(userProfile).toHaveProperty('primary_email') | ||
expect(userProfile).toHaveProperty('contact_email') | ||
expect(userProfile).toHaveProperty('first_name') | ||
expect(userProfile).toHaveProperty('last_name') | ||
expect(userProfile).toHaveProperty('image_url') | ||
expect(userProfile).toHaveProperty('linkedin_url') | ||
expect(userProfile).toHaveProperty('type') | ||
expect(userProfile).toHaveProperty('uuid') | ||
expect(userProfile).not.toHaveProperty('password') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import express from 'express' | ||
import { getAllUsersHandler } from '../../controllers/admin.controller' | ||
import { requireAuth } from '../../controllers/auth.controller' | ||
|
||
const adminRouter = express.Router() | ||
|
||
adminRouter.get('/users', requireAuth, getAllUsersHandler) | ||
|
||
export default adminRouter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,11 @@ | ||||||||||
import type { Request } from 'express' | ||||||||||
import { dataSource } from '../configs/dbConfig' | ||||||||||
import Profile from '../entities/profile.entity' | ||||||||||
|
||||||||||
export const getAllUsers = async ( | ||||||||||
req: Request | ||||||||||
): Promise<Profile[] | undefined> => { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
const profileRepository = dataSource.getRepository(Profile) | ||||||||||
const allUsers = await profileRepository.find() | ||||||||||
return allUsers as Profile[] | ||||||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.