Skip to content

Commit

Permalink
Changed mentor schema and added mentor register endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Anurag-Deo committed Jun 10, 2023
1 parent 4fe5c68 commit ca8c295
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 9 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:
- name: Set Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 16.x

- name: Run install
uses: borales/actions-yarn@v4
with:
cmd: install # will run `yarn install` command
cmd: install # will run `yarn install` command

- name: Code linter
uses: borales/actions-yarn@v4
with:
cmd: lint
cmd: lint
4 changes: 0 additions & 4 deletions models/Mentor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ const mentorSchema = new Schema({
required: true,
unique: true,
},
projectLinks: {
type: Array,
required: true,
},
willReview: {
type: Boolean,
required: true,
Expand Down
81 changes: 80 additions & 1 deletion src/routes/register.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/* eslint-disable */
const express = require('express')
const Student = require('../../models/Student')
// import Mentor = require('../../models/Mentor')
const Mentor = require('../../models/Mentor')
const router = express.Router()
import { body, validationResult } from 'express-validator'

// @route POST /api/register/student
// @desc Register student
// @access Public
// @body firstname, lastname, email, instituteEmail, phoneno, organization, githubProfile, otherProfile, firstTime
// @return JSON object
router.post(
'/student',
body('firstname').isLength({ min: 1 }).withMessage('Name is required'),
Expand Down Expand Up @@ -74,4 +79,78 @@ router.post(
}
)

// @route POST /api/register/mentor
// @desc Register mentor
// @access Public
// @body firstname, lastname, email, phoneno, organization, githubProfile, otherProfile, firstTime, willReview, projectLinks
// @return JSON object
router.post(
'/mentor',
body('firstname').isLength({ min: 1 }).withMessage('Name is required'),
body('lastname').isLength({ min: 1 }).withMessage('Email is required'),
body('email').isLength({ min: 1 }).withMessage('Email is required'),
body('phoneno').isLength({ min: 1 }).withMessage('Phone Number is required'),
body('organization').isLength({ min: 1 }).withMessage('Organization is required'),
body('githubProfile').isLength({ min: 1 }).withMessage('Github Profile is required'),
body('otherProfile').isLength({ min: 1 }).withMessage('Other Profile is required'),
body('firstTime').isLength({ min: 1 }).withMessage('First Time is required'),
body('willReview').isLength({ min: 1 }).withMessage('Will Review is required'),
async (
req: {
body: {
firstname: any
lastname: any
email: any
phoneno: any
organization: any
githubProfile: any
otherProfile: any
firstTime: any
willReview: any
}
},
res: {
status: (arg0: number) => {
(): any
new (): any
json: { (arg0: { error?: any; message?: any }): void; new (): any }
}
}
) => {
const errors = validationResult(req)
if (!errors.isEmpty()) {
return res.status(400).json({ error: errors.array() })
}

try {
const {
firstname,
lastname,
email,
phoneno,
organization,
githubProfile,
otherProfile,
firstTime,
willReview,
} = req.body
let user = new Mentor({
firstname,
lastname,
email,
phoneno,
organization,
githubProfile,
otherProfile,
firstTime,
willReview,
})
await user.save()
res.status(200).json({ message: 'User created successfully' })
} catch (err: any) {
res.status(500).json({ error: err.message })
}
}
)

module.exports = router

0 comments on commit ca8c295

Please sign in to comment.