Skip to content
Permalink
be9e1e5875
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
49 lines (39 sloc) 1.14 KB
const Router = require('koa-router');
const bodyParser = require('koa-bodyparser');
const model = require('../models/users');
const schema = require('../schemas/user.schema.js');
const validator = require('../controllers/validation');
const router = Router({prefix: '/api/v1/users'});
router.get('/', getAllUsers);
router.get('/asd', updatePassword);
router.post('/', bodyParser(), validator.makeKoaValidator(schema), createUser);
router.del('/:id([0-9]{1,})', deleteUser);
async function getAllUsers(ctx) {
let users = await model.getAll();
console.log(users)
if (users.length) {
ctx.body = users;
}
}
async function createUser(ctx) {
const body = ctx.request.body;
console.log(body)
let result = await model.add(body);
if (result) {
ctx.status = 201;
ctx.body = {ID: result.ID}
}
}
async function deleteUser(ctx) {
// TODO delete an existing article
let id = ctx.params.id;
let data = await model.deleteUser(id)
ctx.body = data;
}
async function updatePassword(ctx) {
// TODO delete an existing article
//let id = ctx.params.id;
let data = await model.updatePassword()
ctx.body = data;
}
module.exports = router;