User routes

pull/1/head
sundowndev 2018-11-14 18:15:42 +01:00
parent 80a57fc721
commit 15fee6c83d
7 changed files with 27 additions and 82 deletions

View File

@ -1,11 +0,0 @@
const mongoose = require('mongoose');
module.exports = (req, res) => {
const UserModel = mongoose.model('User');
const users = UserModel.find()
.lean()
.exec()
.then(() => {
res.status(200).json(users);
});
};

View File

@ -1,12 +0,0 @@
const Joi = require('joi');
// const jwt = require('jsonwebtoken');
// const bcrypt = require('bcrypt-nodejs');
const schema = Joi.object().keys({
firstname: Joi.string().alphanum().min(2),
lastname: Joi.string().alphanum().min(2),
username: Joi.string().alphanum().min(3).max(30)
.required(),
password: Joi.string().regex(/^[a-zA-Z0-9]{3,30}$/),
access_token: [Joi.string(), Joi.number()],
}).with('username').without('password', 'access_token');

View File

@ -0,0 +1,5 @@
module.exports = (req, res) => {
const user = {};
res.status(200).json({ user });
};

View File

@ -1,38 +1,12 @@
const user = require('express').Router(); const user = require('express').Router();
const all = require('./all');
const profile = require('./profile'); const profile = require('./profile');
const single = require('./single'); const update = require('./update');
// const create = require('./create'); const remove = require('./delete');
// const update = require('./update'); // const notes = require('./notes');
// const remove = require('./delete');
/** /**
* @api {get} /user Request all Users information * @api {get} /user/me Get user information
* @apiName GetUsers
* @apiGroup User
*
* @apiParam {Number} id Users unique ID.
*
* @apiSuccess {Array} Array User objects.
*/
user.get('/', all);
/**
* @api {get} /user/:id Request User information
* @apiName GetUser
* @apiGroup User
*
* @apiParam {Number} id Users unique ID.
*
* @apiSuccess {String} firstname Firstname of the User.
* @apiSuccess {String} lastname Lastname of the User.
* @apiSuccess {String} username Username of the User.
*/
user.get('/:userId', single);
/**
* @api {get} /user/me Request current account information
* @apiName GetUser * @apiName GetUser
* @apiGroup User * @apiGroup User
* *
@ -43,39 +17,28 @@ user.get('/:userId', single);
user.get('/me', profile); user.get('/me', profile);
/** /**
* @api {put} /user/me Update current account information * @api {put} /user/me Update account information
* @apiName UpdateUser * @apiName UpdateUser
* @apiGroup User * @apiGroup User
* *
* @apiParam {String} firstname Firstname of the User. * @apiSuccess {Object} user User object.
* @apiParam {String} lastname Lastname of the User. */
* @apiParam {String} username Username of the User. user.put('/me', update);
*/
user.put('/me', profile);
/** /**
* @api {delete} /user/me Delete current account * @api {delete} /user/me Delete account
* @apiName DeleteUser * @apiName DeleteUser
* @apiGroup User * @apiGroup User
*
* @apiParam {String} firstname Firstname of the User.
* @apiParam {String} lastname Lastname of the User.
* @apiParam {String} username Username of the User.
*/ */
user.delete('/me', profile); user.delete('/me', remove);
/** /**
* @api {get} /user/me/notes Get notes created by this account * @api {get} /user/me/notes Get all notes
* @apiName GetNotes * @apiName GetNotesByUserId
* @apiGroup User,Note * @apiGroup User notes
* *
* @apiSuccess {string} title Title of the note. * @apiSuccess {Array} Array Notes of the user.
* @apiSuccess {string} text Text of the note.
*/ */
user.get('/me/notes', profile); user.get('/me/notes', profile);
// user.post('/', create)
// user.put('/:userId', update)
// user.delete('/:userId', remove)
module.exports = user; module.exports = user;

0
app/routes/user/notes.js Normal file
View File

View File

@ -1,5 +0,0 @@
module.exports = (req, res) => {
const user = req.model;
res.status(200).json({ user });
};

View File

@ -0,0 +1,5 @@
module.exports = (req, res) => {
const user = {};
res.status(200).json({ user });
};