-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandler.js
37 lines (31 loc) · 1.21 KB
/
handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const User = require("./server/models/user").User;
const utils = require("./server/helper/utils");
const cols = ["_id", "firstName", "lastName"];
const _ = require("lodash");
module.exports.create = async (event, context) => {
console.log("In Create Function !!!");
var user = utils.addId(JSON.parse(event.body));
user = new User(user);
return user.save()
.then((createdUser) => utils.successResponse(createdUser))
.catch((error) => utils.errorResponse(error));
};
module.exports.list = async (event, context) => {
console.log("In List Function !!!");
return User.getAll()
.then((users) => utils.successResponse(users))
.catch((error) => utils.errorResponse(error));
};
module.exports.update = async (event, context) => {
console.log("In Update Function !!!");
var userObj = new User(_.pick(JSON.parse(event.body), cols));
return userObj.save()
.then((updatedObj) => utils.successResponse(updatedObj))
.catch((error) => utils.errorResponse(error));
};
module.exports.delete = async (event, context) => {
console.log("In Delete Function !!!");
return User.deleteById(event.pathParameters._id)
.then((deletedObj) => utils.successResponse(deletedObj))
.catch((error) => utils.errorResponse(error));
};