-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
131 lines (90 loc) · 3.13 KB
/
index.js
File metadata and controls
131 lines (90 loc) · 3.13 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const express = require('express');
const app = express();
app.use(express.json());
const mongodb = require('mongodb');
const eduDB = require('./mongoDB/eduDB');
const shopDB = require('./mongoDB/clothDB');
const libraryDB = require('./mongoDB/libraryDB');
const eclectricDB = require('./mongoDB/electricDB');
const vagitableFunc = require('./mongoDB/vagitableDB');
const fishFunc = require('./mongoDB/fishDB');
const meatFunc = require('./mongoDB/meatDB');
const animal_func = require('./mongoDB/animalDB');
const admin_Func = require('./mongoDB/adminDB');
// ################################ Get Data ####################################
app.get("/edu_api", async(req, res)=> {
const eduDbConnection = await eduDB();
const data = await eduDbConnection.find({}).toArray();
console.log(data);
res.send(data)
})
app.get("/cloth_api", async(req, res)=> {
const shopDBConnection = await shopDB();
const data = await shopDBConnection.find({}).toArray();
res.send(data);
})
app.get("/library_api", async(req, res)=> {
const libraryDBConnection = await libraryDB();
const data = await libraryDBConnection.find({}).toArray();
res.send(data);
})
app.get("/electric_item_api", async(req, res)=> {
const electricDBConnection = await eclectricDB();
const data = await electricDBConnection.find({}).toArray();
res.send(data);
})
app.get("/vagitable_api", async(req, res)=> {
const vagitableDBConnection = await vagitableFunc();
const data = await vagitableDBConnection.find({}).toArray();
res.send(data)
})
app.get("/fish_api", async(req, res)=> {
const fishDBConnection = await fishFunc();
const data = fishDBConnection.find({}).toArray();
res.send(data);
})
app.get("/meat_api", async(req, res)=> {
const meatDBConnection = await meatFunc();
const data = meatDBConnection.find({}).toArray();
res.send(data);
})
app.get("/animal_api", async(req, res)=> {
const animalDBConnection = await animal_func();
const data = animalDBConnection.find({}).toArray();
res.send(data);
})
app.get("/admins__api", async(req, res)=> {
const adminDB_Connection = await admin_Func();
const data_admin = await adminDB_Connection.find({}).toArray();
res.send(data_admin);
})
// ############################# post data ###############################
app.post("/edu_data ", async(req, res)=> {
const eduDbConnection = await eduDB();
const data = await eduDbConnection.insert(req.body);
res.send(data);
})
app.post("/admin__data", async(req, res)=> {
const adminDB_Connection = await admin_Func();
const _data_admin = await adminDB_Connection.insertOne(req.body);
res.send(_data_admin);
})
// put data
app.put("/", async(req, res)=> {
const eduDbConnection = await eduDB();
const dataUpdate = eduDbConnection.updateOne(
{name: req.body.name},
{$set:req.body }
)
res.send(dataUpdate);
})
app.put(" ", (req, res) => {
})
app.delete("/:id", async(req, res)=> {
const eduDbConnection = await eduDB();
const data = eduDbConnection.deleteOne({id: new mongodb(req.params.body)})
res.send(data);
})
app.listen(5000, () => {
console.log(`http://localhost:${5000}`)
})