-
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
Get all users endpoint #52
Conversation
…into get-all-users-endpoint
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.
The eslint is failing @Shrenik0321 can you check it? Also can you refer to this directory structure?
controllers
- admin
- user
- mentee
- mentor
- platform
src/routes/admin/admin.route.test.ts
Outdated
|
||
const userProfiles = response.body | ||
|
||
userProfiles.forEach((userProfile: Object) => { |
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.
userProfiles.forEach((userProfile: Object) => { | |
userProfiles.forEach((userProfile: Partial<Profile>) => { |
…into get-all-users-endpoint
…21/scholarx-backend into get-all-users-endpoint
res: Response | ||
): Promise<any> => { | ||
try { | ||
const users = await getAllUsers(req) |
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.
const users = await getAllUsers(req) | |
const users = await getAllUsers() |
You need to check the user type here. user type should be ADMIN otherwise throw 403 unauthorized
src/services/admin.service.ts
Outdated
export const getAllUsers = async ( | ||
req: Request | ||
): Promise<Profile[] | undefined> => { |
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.
export const getAllUsers = async ( | |
req: Request | |
): Promise<Profile[] | undefined> => { | |
export const getAllUsers = async ( ): Promise<Profile[] | undefined> => { |
src/controllers/auth.controller.ts
Outdated
const { email, password, type } = req.body | ||
|
||
if (!email || !password) { | ||
res.status(400).json({ error: 'Email and password are required fields' }) | ||
} | ||
|
||
const { statusCode, message, profile } = await registerUser(email, password) | ||
const { statusCode, message, profile } = await registerUser( | ||
email, | ||
password, | ||
type | ||
) |
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.
You should not update this to send the type. With this anyone can become an admin. @Shrenik0321
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.
Oh right. understood
src/routes/admin/admin.route.test.ts
Outdated
const adminUser = { | ||
email: `test${randomStringAdmin}@gmail.com`, | ||
password: 'admin123', | ||
type: 'admin' | ||
} | ||
|
||
await supertest(server) | ||
.post('/api/auth/register') | ||
.send(adminUser) | ||
.expect(201) |
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.
Use the dataSource to create an admin
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.
const adminUser = {
email: `test${randomStringAdmin}@gmail.com`,
password: 'admin123',
}
const profileRepository = dataSource.getRepository(Profile)
const hashedPassword = await bcrypt.hash(adminUser.password, 10)
const newProfile = profileRepository.create({
primary_email: .adminUser.email,
password: hashedPassword,
contact_email: '',
first_name: '',
last_name: '',
image_url: '',
linkedin_url: '',
type: ProfileTypes.ADMIN
})
await profileRepository.save(newProfile)
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.
Good job! @Shrenik0321
Purpose
The purpose of this PR is to fix #34
Goals
Approach
Screenshots
Checklist
Related PRs
Test environment
Learning