-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
84 lines (75 loc) · 1.79 KB
/
app.js
File metadata and controls
84 lines (75 loc) · 1.79 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const express = require('express');
const app = express();
function user(id,name,username,password,gender,email)
{
this.id = id;
this.name = name;
this.username = username;
this.password = password;
this.gender = gender;
this.email = email;
}
let users = [
{
id: 1,
name: 'Chlp'
},
{
id: 2,
name: 'Chlp1'
}
];
let id = 3;
function addUser(id,name,username,password,gender,email) {
let us = new user(id,name,username,password,gender,email);
users.push(us);
}
function userDelete (id) {
for(let i = 0; i < users.length; ++i) {
if (users[i].id == id) {
users.splice(id,1);
return "delete was sucsefull";
}
}
return null;
}
function getUser(id) {
for(let i = 0; i < users.length; ++i) {
if (users[i].id == id) {
return users[i];
}
}
return null;
}
function updateUser(id,name,username,password,gender,email) {
for(let i = 0; i < users.length; ++i)
{
if (users[i].id == id) {
users[id].name = name;
users[id].username = username;
users[id].password = password;
users[id].gender = gender;
users[id].email = email;
return users[id];
}
}
return null;
}
app.get('/api/users/:id', function (req, res) {
let user = getUser(req.params.id);
res.send(user || 'not found');
});
app.put('/api/users/p/:id', function (req, res) {
let us = updateUser(req.params.id,"Hakobyan","hakobyan","pass",1,"Vahe");
res.send(us || 'there are not user in your id');
});
app.delete('/api/users/d/:id', function (req, res) {
let k =userDelete(req.params.id);
res.send(k || "no found");
});
app.post('/api/users/po',function (req,res) {
addUser(id++,"Vahe","vahe92","pass",1,"vahe@mail");
let us = getUser(id-1);
res.send(us);
});
app.listen(3000);