Skip to content
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
merged 11 commits into from
Aug 20, 2023

Conversation

Shrenik0321
Copy link
Contributor

Purpose

The purpose of this PR is to fix #34

Goals

Approach

Screenshots

Checklist

  • This PR doesn't commit any keys, passwords, tokens, usernames, or other secrets.
  • I have read and understood the development best practices guidelines ( http://bit.ly/sef-best-practices )
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

Related PRs

Test environment

Learning

Copy link
Member

@anjula-sack anjula-sack left a 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


const userProfiles = response.body

userProfiles.forEach((userProfile: Object) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
userProfiles.forEach((userProfile: Object) => {
userProfiles.forEach((userProfile: Partial<Profile>) => {

res: Response
): Promise<any> => {
try {
const users = await getAllUsers(req)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment on lines 5 to 7
export const getAllUsers = async (
req: Request
): Promise<Profile[] | undefined> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const getAllUsers = async (
req: Request
): Promise<Profile[] | undefined> => {
export const getAllUsers = async ( ): Promise<Profile[] | undefined> => {

Comment on lines 10 to 20
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
)
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right. understood

Comment on lines 32 to 41
const adminUser = {
email: `test${randomStringAdmin}@gmail.com`,
password: 'admin123',
type: 'admin'
}

await supertest(server)
.post('/api/auth/register')
.send(adminUser)
.expect(201)
Copy link
Member

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

Copy link
Member

@anjula-sack anjula-sack Aug 20, 2023

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)

Copy link
Member

@anjula-sack anjula-sack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! @Shrenik0321

@anjula-sack anjula-sack merged commit de332e3 into sef-global:main Aug 20, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Get all admins/users endpoint (Admins)
3 participants