-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfake_database.js
More file actions
52 lines (49 loc) · 1.23 KB
/
fake_database.js
File metadata and controls
52 lines (49 loc) · 1.23 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
exports.fakeDB = function (request) {
console.log(request);
var { source, target } = request;
// Objects DB
var db = {
humanObj: {
100: {
name: "Luke Skywalker",
appearsIn: ["JEDI", "NEWHOPE", "EMPIRE"],
starships: [{ name: "Millenium Falcon", length: 150.0 }],
},
200: {
name: "R2-D2",
appearsIn: ["JEDI", "NEWHOPE"],
starships: [
{ name: "Millenium Falcon", length: 150.0 },
{ name: "Imperial Cruiser", length: 450.0 },
],
},
300: {
name: "C-3PO",
appearsIn: ["JEDI", "NEWHOPE", "EMPIRE"],
starships: [{ name: "Millenium Falcon", length: 150.0 }],
},
},
starships: {
millenium: {
name: "Millenium Falcon",
length: 150.0,
},
imperialDestroyer: {
name: "Imperial Cruiser",
length: 450.0,
},
jediDestroyer: {
name: "Jedi Cruiser",
length: 350.0,
},
},
};
var delay = Math.round(Math.random() + 500);
return new Promise(function (res, rej) {
setTimeout(function () {
let result = db[source][target];
if (result) res(result);
else rej(new Error("Not Found"));
}, delay);
});
};