-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.ts
More file actions
27 lines (25 loc) · 998 Bytes
/
index.ts
File metadata and controls
27 lines (25 loc) · 998 Bytes
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
import { setSession } from 'utils/setSession'
import * as userService from 'services/userService'
import { parseUpdatePUTRequest, parseUpdateCsvRowCollapsingPUTRequest } from 'utils/validators'
export default async (
req: any,
res: any
): Promise<void> => {
await setSession(req, res, true)
const session = req.session
if (req.method === 'GET') {
const user = await userService.fetchUserProfileFromId(session.userId)
res.status(200).json(user)
}
if (req.method === 'PUT') {
if (req.body.csvRowCollapsing !== undefined) {
const { csvRowCollapsing } = parseUpdateCsvRowCollapsingPUTRequest(req.body)
await userService.updateCsvRowCollapsing(session.userId, csvRowCollapsing)
res.status(200).json({ success: true })
return
}
const preferredCurrencyIdObject = parseUpdatePUTRequest(req.body)
const user = await userService.updatePreferredCurrency(session.userId, preferredCurrencyIdObject.currencyId)
res.status(200).json(user)
}
}