-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethods.js
More file actions
54 lines (34 loc) · 1.04 KB
/
methods.js
File metadata and controls
54 lines (34 loc) · 1.04 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
const db = require('./db/index');
async function get(url, body) {
const dataExists = await db.exists(url);
if (!dataExists) return `Data ${url} is not exists in database`;
return db.get(url);
}
async function post(url, body) {
await db.push(url, body);
return body;
}
async function put(url, body) {
const dataExists = await db.exists(url);
if (!dataExists) return `Data ${url} is not exists in database`;
await db.push(url, body);
return body;
}
async function patch(url, body) {
const dataExists = await db.exists(url);
if (!dataExists) return `Data ${url} is not exists in database`;
const oldData = await db.get(url);
const newData = { ...oldData, ...body};
await db.push(url, newData);
return newData;
}
async function del(url, body) {
const dataExists = await db.exists(url);
if (!dataExists) return `Data ${url} is not exists in database`;
await db.delete(url);
return url;
}
async function options(url, body) {
return null;
}
module.exports = { options, get, post, put, patch, delete: del };