forked from OfficeDev/Microsoft-Teams-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
95 lines (82 loc) · 2.29 KB
/
server.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
const express = require('express');
const bodyparser = require('body-parser');
const path = require('path');
const app = express();
const fs = require("fs");
let multer = require('multer');
let upload = multer({ storage: multer.memoryStorage(),
limits: { fieldSize: 25 * 1024 * 1024 }});
let productDetailsList = {
"productDetails": [{
"productId": "01SD001",
"productName": "Laptop",
"image": null,
"status": null,
},
{
"productId": "01DU890",
"productName": "Desktop",
"image": null,
"status": null,
},
{
"productId": "01PM998",
"productName": "Mobile",
"image": null,
"status": null,
}]
};
app.use(express.static(__dirname + '/Styles'));
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'ejs');
app.set('views', __dirname);
app.use(express.json());
app.use("/Images", express.static(path.resolve(__dirname, 'Images')));
app.get('/tab', function (req, res) {
res.render('./views/tab');
});
app.get('/productDetails', function (req, res) {
var productId = req.url.split('=')[1];
var productDetails = {
"productId": null,
"productName": null,
"image": null,
"status": null
}
var currentData = productDetailsList["productDetails"];
currentData.find((product) => {
if (product.productId == productId) {
productDetails = product;
}
});
res.render('./views/productDetail', { productDetails: JSON.stringify(productDetails) });
});
app.get('/scanProduct', function (req, res) {
res.render('./views/scanProduct');
});
app.get('/viewProductDetail', function (req, res) {
res.render('./views/viewProductDetail');
});
app.post('/save', upload.single('data'), function(req, res){
var data = req.body.data
var result = JSON.parse(data);
var productDetail = {
"productId": result.productId,
"productName": result.productName,
"image": result.image,
"status": result.status
};
var currentData = productDetailsList["productDetails"];
let updateindex;
currentData.map((product, index) => {
if (product.productId == productDetail.productId) {
updateindex = index;
}
})
currentData[updateindex] = productDetail;
productDetailsList["productDetails"] = currentData;
res.send();
});
app.listen(3978, function () {
console.log('app listening on port 3978!');
});