-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
49 lines (43 loc) · 1.16 KB
/
db.js
File metadata and controls
49 lines (43 loc) · 1.16 KB
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
const mssql = require("mssql");
const dbProdConfig = {
user: "Tr@ck",
password: "W4@tM@tt3r5",
server: "127.0.0.1",
database: "taymor",
port: "3306"
};
// const dbDevConfig = {
// user: "adminAPI",
// password: "test",
// server: "devtest.c6icfldz2ex8.us-east-2.rds.amazonaws.com",
// database: "GPS",
// options: {
// encrypt: true,
// port: "1433"
// }
// };
// export const cpool = new mssql.connect(dbProdConfig)
// export const cpool = new mssql.connect(dbDevConfig)
export const cpool = process.env.NODE_ENV == 'dev' ? new mysql.connect(dbDevConfig) : new mysql.connect(dbProdConfig)
export async function token(authCode, token) {
const result = await cpool
.then(pool => {
return pool
.request()
.input("authCode", mysql.VarChar(50), authCode)
.input("token", mysql.VarChar(50), token)
.query("exec gps.dbo.v3_Token_verify @authCode, @token");
})
.then(result => {
if (result.recordsets[0][0].resultCode == 1) {
return result.recordsets[0][0].token
}
else {
return null
}
})
.catch(err => {
console.log(err);
});
return result
}