-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
93 lines (77 loc) · 2.36 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
require("dotenv").config();
const express = require("express");
const app = express();
const cors = require("cors");
const connection = require("./connection");
const taskRoute = require('./routes/taskRoute');
const addToCartRoute = require('./routes/addToCartRoute');
const purchase = require('./routes/purchase');
const productRoutes = require('./routes/productRoutes');
const path = require('path');
const graph = require('./controllers/graph');
const erp = require('./routes/erpRoutes');
const { graphqlHTTP } = require('express-graphql');
const mongoose = require('mongoose');
const graphqlSchema = require('./controllers/graphqlSchema');
const Purchase=require('./models/Purchase');
// Connect to the database (assuming your connection module exports a function)
// connection();
// middlewares
app.use(cors());
app.use(express.json());
app.use(express.static('uploads')); // To serve images statically
// Multer config
// Other routes
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('Something broke!');
});
app.use("/hob1/checkout", purchase);
app.use("/api", taskRoute);
app.use("/product/cart", addToCartRoute);
app.use("/bar", graph);
app.use('/api/products', productRoutes);
app.use("/marzun/cart/", addToCartRoute);
//console.log(__dirname);
app.use('/erp', erp);
app.use('/pdfs/', express.static(path.join(__dirname, 'public', 'pdfs')));
app.use('/graphql1', graphqlHTTP(req => {
const startTime = Date.now();
return {
schema: graphqlSchema,
graphiql: true,
extensions({ document, variables, operationName, result }) {
return { runTime: Date.now() - startTime };
},
formatError: error => {
console.error(error);
return {
message: error.message,
locations: error.locations,
stack: error.stack,
path: error.path
};
}
};
}));
app.post('/okk/:tran_id', async(req,res)=>{
const result = await Purchase.updateOne(
{transactionId: req.params.tran_id},
{
$set:{
paymentStatus:"true",
},
}
);
console.log('jii');
if(result.modifiedCount>=0){
res.redirect(
`localhost:3006`
);
};
})
// Start the server
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Listening on port ${port}...`);
});