-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
110 lines (99 loc) · 2.89 KB
/
routes.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
const express = require('express')
const router = express.Router()
const Account = require('./account')
router.post('/mi', async (req, res, next) => {
const { userId, DOB, address, aiad, aidd, city, dd, eci, ecn, name, state, zipcode, sex, phone, pfpUrl } = req.body
try {
const updatedUser = await Account.findOneAndUpdate({ userId: userId }, { DOB, address, aiad: aiad, aidd, city, dd, eci, ecn, name, state, zipcode, sex, phone, pfpUrl })
if (!updatedUser) {
next(new Error('Error: Failed to change account info.'))
} else {
res.send('Account info successfully changed.')
}
} catch (err) {
console.log(err)
next(err)
}
})
router.post('/mistatus', async (req, res, next) => {
const { userId, status } = req.body
try {
const updatedUser = await Account.findOneAndUpdate({ userId: userId }, { status: status })
if (!updatedUser) {
next(new Error('Error: Failed to change account info.'))
} else {
res.send('Account info successfully changed.')
}
} catch (err) {
console.log(err)
next(err)
}
})
router.get('/acc', async (req, res, next) => {
const { userId } = req.query
try {
const user = await Account.findOne({ userId: userId })
if (!user) {
next(new Error('Error: Failed to get accounts.'))
} else {
res.json(user)
}
} catch (err) {
next(err)
}
})
router.get('/accall', async (req, res, next) => {
try {
const users = await Account.find()
if (!users) {
next(new Error('Error: Failed to get accounts.'))
} else {
res.json(users)
}
} catch (err) {
next(err)
}
})
router.post('/trigger', async (req, res, next) => {
try {
const updatedUser = await Account.findOneAndUpdate({ userId: "1" }, { status: "0" })
if (!updatedUser) {
next(new Error('Error: Failed to change account info.'))
} else {
res.send('Account info successfully changed.')
}
} catch (err) {
console.log(err)
next(err)
}
})
router.post('/pfp', async (req, res, next) => {
const { userId, pfp } = req.body
try {
const updatedUser = await Account.findOneAndUpdate({ userId: userId }, { pfp: pfp })
if (!updatedUser) {
next(new Error('Error: Failed to change account info.'))
} else {
console.log("WOW")
console.log(updatedUser)
res.send('Account info successfully changed.')
}
} catch (err) {
console.log(err)
next(err)
}
})
// router.get('/i', async (req, res, next) => {
// const { userId, } = req.params
// try {
// const updatedUser = await User.findOneAndUpdate({ id: userId }, { DOB, address, aiad, aidd, city, dd, eci, ecn, name, sex, state, zipcode })
// if (!updatedUser) {
// next(new Error('Error: Failed to change account info.'))
// } else {
// res.send('Account info successfully changed.')
// }
// } catch (err) {
// next(err)
// }
// })
module.exports = router