-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
129 lines (111 loc) · 3.54 KB
/
api.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
var express = require("express");
const sequelize = require("./server/connection");
const DataType = require('sequelize');
var usermaster = require("./server/models/usermaster");
var rolemaster = require("./server/models/rolemaster");
var applicationmaster = require("./server/models/applicationmaster");
var userprofile = require("./server/models/userprofile");
var userapplication = require("./server/models/userapplication");
var userrole = require("./server/models/userrole");
var bodyParser = require('body-parser');
const path = require('path');
const http = require('http');
var app = express();
//accept body post
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false}));
//cors
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
//error handling
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
//path publish
app.use(express.static(path.join(__dirname, 'dist')));
//prefix api
let apipref = "/api";
//route function
app.get(apipref+"/usermaster",function(req,res){
usermaster(sequelize, DataType).findAll({where: req.query})
.then(usermaster => {
res.json(usermaster);
}).catch(function (err) {
console.log(err);
res.status(500);
res.json({ message: err.message });
});
});
app.post(apipref+"/login",function(req,res){
var username = req.body.username;
var password = req.body.password;
sequelize.query('CALL sp_Login (:ParamUsername, :ParamPassword)',
{replacements: { ParamUsername: username, ParamPassword: password }})
.then(v=>res.json(v))
.catch(function (err) {
console.log(err);
res.status(500);
res.json({ message: err.message });
});
});
app.get(apipref+"/rolemaster",function(req,res){
rolemaster(sequelize, DataType).findAll({where: req.query})
.then(rolemaster => {
res.json(rolemaster);
}).catch(function (err) {
console.log(err);
res.status(500);
res.json({ message: err.message });
});
});
app.get(apipref+"/applicationmaster",function(req,res){
applicationmaster(sequelize, DataType).findAll({where: req.query})
.then(applicationmaster => {
res.json(applicationmaster);
}).catch(function (err) {
console.log(err);
res.status(500);
res.json({ message: err.message });
});
});
app.get(apipref+"/userprofile",function(req,res){
userprofile(sequelize, DataType).findAll({where: req.query})
.then(userprofile => {
res.json(userprofile);
}).catch(function (err) {
console.log(err);
res.status(500);
res.json({ message: err.message });
});
});
app.get(apipref+"/userapplication",function(req,res){
userapplication(sequelize, DataType).findAll({where: req.query})
.then(userapplication => {
res.json(userapplication);
}).catch(function (err) {
console.log(err);
res.status(500);
res.json({ message: err.message });
});
});
app.get(apipref+"/userrole",function(req,res){
userrole(sequelize, DataType).findAll({where: req.query})
.then(userrole => {
res.json(userrole);
}).catch(function (err) {
console.log(err);
res.status(500);
res.json({ message: err.message });
});
});
const port = process.env.PORT || '3000';
app.set('port', port);
const server = http.createServer(app);
server.listen(port, () => console.log(`Running on localhost:${port}`));