-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrips.js
120 lines (88 loc) · 2.73 KB
/
trips.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
const express = require ('express');
const router = express.Router();
//create a trip
router.get('/create',(req, res) => {
/* const data = {
bus_id : req.body.bus_id,
origin : req.body.origin,
destination : req.body.destination,
trip_date : req.body.trip_date,
//fare : req.body.fare,
//status : req.body.active,}*/
const pg = require('pg');
const connectionString = process.env.DATABASE_URL || 'postgres://localhost:5432/wayfarer_db';
const client = new pg.Client(connectionString);
client.connect()
//.then(() => console.log("connection to database successful"))
.catch((err) => {
console.log(`database err: ${err}`)
})
const query = ("insert into trip values ($1, $2, $3,$4,$5,$6,$7)", [9, '545', 'Lagos', 'Enugu', "2019-02-12", '5000','Active', ])
.catch((err) =>{
console.log(`failed: ${err}` );
})
.then(() => client.query(' select * from trip'))
//client.query(query,(error,results) => {
.then((results) => console.table(results.rows));
res.status(200).send({
status :'ok ',
data : result.rows,
});
});
// view all trips
router.get('/',(req, res) =>{
res.status(200).send({
status : 'success',
message : 'seeing all trips',
data :{
/* booking_id: 4657,
user_id:65,
trip_id:76,
bus_id:857,
trip_date:24/05/2019,
seat_number: 75,
first_name: hyacinth,
last_name:afam,
email:westwizo,*/
}
//username : req.params.signupId
}) ;
});
//to get a trip
router.get('/:tripId',(req, res) => {
res.status(200).send({
status : 'success',
message : 'delete successful',
bookingId : req.params.bookingId
});
//username : req.params.signupId
});
//to update trip
router.put('/:tripId',(req, res) =>{
res.status(200).send({
status : 'success',
message : 'trip update successful',
data :{
/* booking_id: 4657,
user_id:65,
trip_id:76,
bus_id:857,
trip_date:24/05/2019,
seat_number: 75,
first_name: hyacinth,
last_name:afam,
email:westwizo,*/
}
//username : req.params.signupId
}) ;
});
//to delete booking
router.delete('/:tripId',(req, res) => {
res.status(200).send({
status : 'success',
message : 'trip delete successful',
tripId : req.params.tripId
});
//username : req.params.signupId
});
module.exports = router;