-
Notifications
You must be signed in to change notification settings - Fork 0
/
deleteUser.js
68 lines (55 loc) · 1.3 KB
/
deleteUser.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var express = require('express')
// instantiating the Router middle. essentially middleware composition
var router = express.Router()
var formatedDate = require('date-format');
// set matched user to false.
let match = false;
// would be set with the match object.
let matchObject = "";
// array user information objects
// array user information objects
let users = [
{
id : 1,
name : "mikko",
age : 20,
height: "80cm",
profession: "trader"
},
{
id : 2,
name : "jenni",
age : 25,
height: "80cm",
profession: "Accountant"
}
]
// Displays the time the request was made
// This would be executed first.
// Passes the execution phase to the next handle
let rquestDate = function requestDate(req, res, next) {
console.log('You viewed the page at ' + formatedDate('hh:mm', new Date() ) + ' on ' + formatedDate('dd.MM.yy', new Date() ));
next();
}
var checker = function (id){
users.map(function(user){
if(id == user.id){
delete user;
match = true;
}
})
}
// Handler on the
router.get('/:id', rquestDate , function (req, res) {
checker(req.params.id);
if(match){
console.log("user is found! ...");
res.json({Content: "user is successfully deleted ..."});
match = false;
}
else {
console.log("user not found! ...");
res.send("user not found! ...")
}
})
module.exports = router