sdy

update editProfile

1 type Mutation { 1 type Mutation {
2 editProfile( 2 editProfile(
3 + email: String!
3 name: String 4 name: String
4 - email: String
5 bio: String 5 bio: String
6 avatarUrl: String 6 avatarUrl: String
7 + phoneNum: String
7 ): User! 8 ): User!
8 } 9 }
......
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 };
......