Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>Error</title>
- </head>
- <body>
- <pre>Cannot POST /users/</pre>
- </body>
- </html>
- const mongoose = require("mongoose");
- const userSchema = new mongoose.Schema({
- _id: String,
- username: { type: String, minlength: 5, maxlength: 50, required: true },
- mail: {
- type: String,
- minlength: 5,
- maxlength: 255,
- required: true,
- unique: true
- },
- password: { type: String, minlength: 5, required: true }
- });
- /* Create the model from the schema. */
- const User = mongoose.model("User", userSchema);
- module.exports = User;
- const checkAuth = require('../../middlewares/check-auth.js');
- const handlers = require('./handlers');
- const validators = require('./validators');
- module.exports = router => {
- router.get('/users', checkAuth, validators.find, handlers.find);
- router.post('/users', validators.create, handlers.create);
- router.get('/users/:id', checkAuth, validators.find, handlers.findById);
- router.put('/users/:id', checkAuth, validators.update, handlers.update);
- router.delete(
- '/users/:id',
- checkAuth,
- validators.deletion,
- handlers.deletion,
- );
- return router;
- };
- const User = require('mongoose').model('User');
- const bcrypt = require('bcrypt');
- const jwt = require('jsonwebtoken');
- const find = (req, res) => {
- ...
- };
- const findById = (req, res) => {
- ...
- };
- const generateToken = tokenData => {
- ...
- };
- const create = (req, res) => {
- ...
- };
- const update = (req, res) => {
- ...
- };
- const deletion = (req, res) => {
- ...
- };
- module.exports = {
- find,
- findById,
- create,
- update,
- deletion,
- };
- const { celebrate, Joi } = require('celebrate');
- const find = celebrate({
- ...
- });
- const findOne = celebrate({
- ...
- });
- const create = celebrate({
- ...
- });
- const update = celebrate({ ... });
- const deletion = celebrate({ ... });
- module.exports = {
- find,
- findOne,
- create,
- update,
- deletion,
- };
Add Comment
Please, Sign In to add comment