generated from jhackett1/railsy-nextjs-prisma-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (48 loc) · 1.15 KB
/
index.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
import prisma from "../../../lib/prisma"
import { verifySession, errorHandler } from "../../../lib/middleware"
import { settingsSchema } from "../../../lib/validators"
const handler = async (req, res, session) => {
// throw "example error"
if (req.method === "POST") {
const {
teamId,
useSignature,
signature,
outOfHoursAutoreply,
outOfHoursMessage,
messageTemplates,
} = JSON.parse(req.body)
await settingsSchema.validate({
useSignature,
signature,
outOfHoursAutoreply,
outOfHoursMessage,
messageTemplates,
})
await Promise.all([
prisma.user.update({
where: {
id: session.user.id,
},
data: {
useSignature,
signature,
},
}),
prisma.team.update({
where: {
id: Number(teamId),
},
data: {
outOfHoursAutoreply,
outOfHoursMessage,
messageTemplates,
},
}),
]).then(results => res.json(results))
} else {
const team = await prisma.team.findFirst()
res.json(team)
}
}
export default errorHandler(verifySession(handler))