Skip to content

Conversation

@oldmonad
Copy link
Owner

@oldmonad oldmonad commented Jan 23, 2019

What does this PR do?

This PR makes sure the user does not submit an inappropriate input

Description of Task to be completed?

Added validation checks using validatorjs to validate input and check for appropriate inputs to make sure they are fit to be consumed by the controller

How should this be manually tested?

  • Clone the repo and run npm install to install dependencies.
  • Download and install postgresql from this link
  • Setup postgreql using this guide
  • run npm migrate to create the tables
  • run npm start:dev to start server
  • check the server/test/testData folder route for the input formats and proceed to testing with postman
  • alternatively run npm run test to test the endpoints

What are the relevant pivotal tracker stories?

  • #163415664

@oldmonad oldmonad merged commit 906f76c into develop Jan 24, 2019
Copy link

@Veraclins Veraclins left a comment

Choose a reason for hiding this comment

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

Great job @dbytecoderc, I particularly love how to try to abstract some repetitive operations into methods, that is cool. I left a few comments for you. Go through them and make necessary adjustments. Cheers!

// app.use('api/v1/comments', commentRoutes);
app.use('/api/v1', routes);

app.use((req, res, next) => {

Choose a reason for hiding this comment

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

Make this the catch-all route. You can use a wild-card. This does not map to any route at the moment.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I fixed this already you would see it in the next PR, i created an index folder in the route file and routed all the endpoints to that file and exported to the app file from there

// });
async createComment(req, res) {
const comment = req.body;
const checkquestion = await QuestionModel.getcommentById(comment.commentId);

Choose a reason for hiding this comment

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

If you are just creating a comment, (from the method name) how can the comment already exist in the DB? Also while will you call it checkquestion when you are getting a comment?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Actually i was just brain storming when i did that, that piece of code is not yet functional, however at the time of writing this reply i have already fixed that,

// id,
// } = req.params;
// const meetup = await MeetupModels.retrieveSingleMeetup(id);
// },

Choose a reason for hiding this comment

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

If this code is no longer being used, remove it.

topic VARCHAR(255) NOT NULL,
location TEXT NOT NULL,
date VARCHAR(50) NOT NULL,
happeningon VARCHAR(50) NOT NULL,

Choose a reason for hiding this comment

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

Either use camelCase or snake_case for variable name. Essentially snake_case only for db fields and camelCase everywhere else

import Comments from '../controller/comments';

// router.post('/auth/signup', Admin.createnewAdmin);
router.post('/auth/signup', Comments.createComment);

Choose a reason for hiding this comment

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

Do you think it is appropriate to map signup route to createComment?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I have actually cleaned this up at the moment of posting this comment

router.use('/auth', userRoutes);
router.use('/meetups', meetupRoutes);
router.use('/questions', questionsRoute);

Choose a reason for hiding this comment

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

How is the comment route used when it is not mapped here?

Copy link
Owner Author

Choose a reason for hiding this comment

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

The comment route is not actually functional here i was just doing some code scribbling i was supposed to remove the code for the comments

router.post('/', Auth.verifyToken, Auth.adminAuth, meetupValidation.validCreateMeetup, meetupValidation.checkDate, meetupController.createMeetup);
router.get('/upcoming/', Auth.verifyToken, meetupController.getUpcomingMeetups);
router.get('/:meetupId', Auth.verifyToken, validate(validations.getMeetup), meetupController.getUpcomingMeetups);
router.get('/:id', Auth.verifyToken, meetupController.getSingleMeetup);

Choose a reason for hiding this comment

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

Since Auth.verifyToken is applied to all the routes here, why not move it to where this route file is mapped in the index.js file to avoid repetition?

Copy link
Owner Author

Choose a reason for hiding this comment

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

OK, would do that

/* eslint-disable eol-last */
const convertName = name => (name.charAt(0).toUpperCase() + name.slice(1)).trim();

export default convertName; No newline at end of file

Choose a reason for hiding this comment

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

This file name and method name should correlate. Make up on your mind what this does and name them accordingly

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ok, noted

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.

3 participants