Showing
2 changed files
with
28 additions
and
3 deletions
1 | -import { prisma } from "../../../utils"; | 1 | +import { isAuthenticated, prisma } from "../../../utils"; |
2 | 2 | ||
3 | export default { | 3 | export default { |
4 | Mutation: { | 4 | Mutation: { |
5 | - editProfile: async (_, args, { request }) => {}, | 5 | + editProfile: async (_, args, { request }) => { |
6 | + isAuthenticated(request); | ||
7 | + const { name, email, avatarUrl, bio, phoneNum } = args; | ||
8 | + const user = await prisma.user.findOne({ | ||
9 | + where: { | ||
10 | + email, | ||
11 | + }, | ||
12 | + }); | ||
13 | + if (user) { | ||
14 | + const updateUser = await prisma.user.update({ | ||
15 | + where: { | ||
16 | + email, | ||
17 | + }, | ||
18 | + data: { | ||
19 | + name, | ||
20 | + bio, | ||
21 | + avatarUrl, | ||
22 | + phoneNum, | ||
23 | + }, | ||
24 | + }); | ||
25 | + return updateUser; | ||
26 | + } else { | ||
27 | + throw new Error("There is no such a user"); | ||
28 | + } | ||
29 | + }, | ||
6 | }, | 30 | }, |
7 | }; | 31 | }; | ... | ... |
-
Please register or login to post a comment