forked from snyk-labs/nodejs-goof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.js
More file actions
45 lines (33 loc) · 1.13 KB
/
users.js
File metadata and controls
45 lines (33 loc) · 1.13 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
var express = require('express')
var typeorm = require("typeorm");
var router = express.Router()
module.exports = router
router.get('/', async (req, res, next) => {
const mongoConnection = typeorm.getConnection('mysql')
const repo = mongoConnection.getRepository("Users")
// hard-coded getting account id of 1
// as a rpelacement to getting this from the session and such
// (just imagine that we implemented auth, etc)
const results = await repo.find({ id: 1 })
// Log Object's where property for debug reasons:
console.log('The Object.where property is set to: ', {}.where)
console.log(results)
return res.json(results)
})
router.post('/', async (req, res, next) => {
try {
const mongoConnection = typeorm.getConnection('mysql')
const repo = mongoConnection.getRepository("Users")
const user = {}
user.name = req.body.name
user.address = req.body.address
user.role = req.body.role
const savedRecord = await repo.save(user)
console.log("Post has been saved: ", savedRecord)
return res.sendStatus(200)
} catch (err) {
console.error(err)
console.log({}.where)
next();
}
})