Skip to content

Instantly share code, notes, and snippets.

@mcnkbr
Last active March 30, 2021 21:59
Show Gist options
  • Save mcnkbr/86d0cb06247e2962ac4496e9470460a7 to your computer and use it in GitHub Desktop.
Save mcnkbr/86d0cb06247e2962ac4496e9470460a7 to your computer and use it in GitHub Desktop.
services/data.js
const data = {
users: [
{
id: 1,
name: 'user 1',
status: 'approved'
},
{
id: 2,
task: 'user 2',
status: 'pending'
},
{
id: 3,
task: 'user 3',
status: 'approved'
},
{
id: 4,
task: 'user 4',
status: 'approved'
}
]
};
module.exports = {
getUsers: function() {
return data.users;
},
addUser: function(user) {
user.id = data.users.length + 1;
data.users.push(user);
return {
message: "user added",
tasks: data.users.length
}
},
deleteUser: function(id) {
data.users = data.users.filter(user => user.id != id)
return {
message: "user deleted",
tasks: data.users.length
}
},
editUser: function(user) {
data.users = data.users.map(usr => {
if (usr.id === user.id) usr = user;
return usr;
});
return {
message: "user edited",
tasks: data.users.length
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment