aboutsummaryrefslogtreecommitdiffstats
path: root/pages/api/settings.js
blob: f0d8e06518f39d5bc3814ba172a545e26ab5b0a4 (plain) (blame)
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
import dbConnect from 'configs/dbConnect'
import withSession from 'hocs/withSession'
import User from 'models/User'

export default withSession(async (req, res) => {
  await dbConnect()

  switch (req.method) {
    case 'POST':
      try {
        if (req.body.theme && req.body.language) {
          const user = await User.saveSettings(req.body)
          req.session.set('user', user)
          await req.session.save()
          res.status(200).json(user)
        }
      } catch (error) {
        console.log(error)
        res.status(400).send()
      }
      break
    default:
      res.status(400).send()
      break
  }
})