Last active
March 30, 2021 21:59
-
-
Save mcnkbr/86d0cb06247e2962ac4496e9470460a7 to your computer and use it in GitHub Desktop.
services/data.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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