-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
168 lines (129 loc) · 4.7 KB
/
index.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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
const express = require('express');
require('dotenv').config();
const app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
const client = require('./config/pg-config');
// client.connect()
// .then(() => {
// console.log('Connected to the database');
// // Perform database operations here
// })
// .catch((error) => {
// console.error('Error connecting to the database:', error.message);
// })
// .finally(() => {
// // Optionally close the connection after performing operations
// client.end();
// });
//routing
// user api
app.post('/create_user/', function (req, res) {
var file = require(__dirname + "/src/user/create-user.js");
file.main(req, res, client);
});
app.put('/update_user/', function (req, res) {
var file = require(__dirname + "/src/user/update-user.js");
file.main(req, res, client);
});
app.delete('/delete_user/', function (req, res) {
var file = require(__dirname + "/src/user/delete-user.js");
file.main(req, res, client);
});
app.get('/read_user/:userId', function (req, res) {
var file = require(__dirname + "/src/user/read-user.js");
file.main(req, res, client);
});
app.get('/user_list/', function (req, res) {
var file = require(__dirname + "/src/user/user-list.js");
file.main(req, res, client);
});
// client api
app.post('/create_client/', function (req, res) {
var file = require(__dirname + "/src/client/create-client.js");
file.main(req, res, client);
});
app.put('/update_client/', function (req, res) {
var file = require(__dirname + "/src/client/update-client.js");
file.main(req, res, client);
});
app.delete('/delete_client/', function (req, res) {
var file = require(__dirname + "/src/client/delete-client.js");
file.main(req, res, client);
});
app.get('/read_client/:clientId', function (req, res) {
var file = require(__dirname + "/src/client/read-client.js");
file.main(req, res, client);
});
app.get('/client_list/', function (req, res) {
var file = require(__dirname + "/src/client/client-list.js");
file.main(req, res, client);
});
// distributor api
app.post('/create_distributor/', function (req, res) {
var file = require(__dirname + "/src/distributor/create-distributor.js");
file.main(req, res, client);
});
app.put('/update_distributor/', function (req, res) {
var file = require(__dirname + "/src/distributor/update-distributor.js");
file.main(req, res, client);
});
app.delete('/delete_distributor/', function (req, res) {
var file = require(__dirname + "/src/distributor/delete-distributor.js");
file.main(req, res, client);
});
app.get('/read_distributor/:distributorId', function (req, res) {
var file = require(__dirname + "/src/distributor/read-distributor.js");
file.main(req, res, client);
});
app.get('/distributor_list/', function (req, res) {
var file = require(__dirname + "/src/distributor/distributor-list.js");
file.main(req, res, client);
});
// customer api
app.post('/create_customer/', function (req, res) {
var file = require(__dirname + "/src/customer/create-customer.js");
file.main(req, res, client);
});
app.put('/update_customer/', function (req, res) {
var file = require(__dirname + "/src/customer/update-customer.js");
file.main(req, res, client);
});
app.delete('/delete_customer/', function (req, res) {
var file = require(__dirname + "/src/customer/delete-customer.js");
file.main(req, res, client);
});
app.get('/read_customer/:customerId', function (req, res) {
var file = require(__dirname + "/src/customer/read-customer.js");
file.main(req, res, client);
});
app.get('/customer_list/', function (req, res) {
var file = require(__dirname + "/src/customer/customer-list.js");
file.main(req, res, client);
});
// operator api
app.post('/create_operator/', function (req, res) {
var file = require(__dirname + "/src/operator/create-operator.js");
file.main(req, res, client);
});
app.put('/update_operator/', function (req, res) {
var file = require(__dirname + "/src/operator/update-operator.js");
file.main(req, res, client);
});
app.delete('/delete_operator/', function (req, res) {
var file = require(__dirname + "/src/customer/delete-operator.js");
file.main(req, res, client);
});
app.get('/read_operator/:operatorId', function (req, res) {
var file = require(__dirname + "/src/operator/read-operator.js");
file.main(req, res, client);
});
app.get('/operator_list/', function (req, res) {
var file = require(__dirname + "/src/operator/operator-list.js");
file.main(req, res, client);
});
//server
app.listen(5521, function () {
console.log("SErver is running...");
});