Fix issues in multiple endpoints (#679)
This commit is contained in:
		
							parent
							
								
									e3843f5a0e
								
							
						
					
					
						commit
						13486d9988
					
				
					 4 changed files with 52 additions and 14 deletions
				
			
		|  | @ -34,13 +34,6 @@ export default async function handler(req, res) { | |||
|           email: email, | ||||
|         }, | ||||
|       ], | ||||
|       AND: [ | ||||
|         { | ||||
|           emailVerified: { | ||||
|             not: null, | ||||
|           }, | ||||
|         }, | ||||
|       ], | ||||
|     }, | ||||
|   }); | ||||
| 
 | ||||
|  |  | |||
|  | @ -37,6 +37,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) | |||
|           in: memberships.map((membership) => membership.userId), | ||||
|         }, | ||||
|       }, | ||||
|       select: { | ||||
|         id: true, | ||||
|         username: true, | ||||
|         name: true, | ||||
|         email: true, | ||||
|         bio: true, | ||||
|         avatar: true, | ||||
|         timeZone: true, | ||||
|       }, | ||||
|     }); | ||||
| 
 | ||||
|     members = members.map((member) => { | ||||
|  |  | |||
|  | @ -1,6 +1,7 @@ | |||
| import type { NextApiRequest, NextApiResponse } from "next"; | ||||
| import prisma from "@lib/prisma"; | ||||
| import { getSession } from "@lib/auth"; | ||||
| import { pick } from "lodash"; | ||||
| 
 | ||||
| export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||||
|   const session = await getSession({ req: req }); | ||||
|  | @ -34,13 +35,41 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) | |||
|   } | ||||
| 
 | ||||
|   if (req.method === "PATCH") { | ||||
|     const data = req.body.data; | ||||
|     const updatedUser = await prisma.user.update({ | ||||
|       where: { | ||||
|         id: authenticatedUser.id, | ||||
|       }, | ||||
|       data: { | ||||
|         ...data, | ||||
|         ...pick(req.body, [ | ||||
|           "username", | ||||
|           "name", | ||||
|           "avatar", | ||||
|           "timeZone", | ||||
|           "weekStart", | ||||
|           "hideBranding", | ||||
|           "theme", | ||||
|           "completedOnboarding", | ||||
|         ]), | ||||
|         bio: req.body.description, | ||||
|       }, | ||||
|       select: { | ||||
|         id: true, | ||||
|         username: true, | ||||
|         name: true, | ||||
|         email: true, | ||||
|         emailVerified: true, | ||||
|         bio: true, | ||||
|         avatar: true, | ||||
|         timeZone: true, | ||||
|         weekStart: true, | ||||
|         startTime: true, | ||||
|         endTime: true, | ||||
|         bufferTime: true, | ||||
|         hideBranding: true, | ||||
|         theme: true, | ||||
|         createdDate: true, | ||||
|         plan: true, | ||||
|         completedOnboarding: true, | ||||
|       }, | ||||
|     }); | ||||
|     return res.status(200).json({ message: "User Updated", data: updatedUser }); | ||||
|  |  | |||
|  | @ -1,6 +1,7 @@ | |||
| import type { NextApiRequest, NextApiResponse } from "next"; | ||||
| import prisma from "@lib/prisma"; | ||||
| import { getSession } from "@lib/auth"; | ||||
| import { pick } from "lodash"; | ||||
| 
 | ||||
| export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||||
|   const session = await getSession({ req: req }); | ||||
|  | @ -10,17 +11,23 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) | |||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   const description = req.body.description; | ||||
|   delete req.body.description; | ||||
| 
 | ||||
|   try { | ||||
|     await prisma.user.update({ | ||||
|       where: { | ||||
|         id: session.user.id, | ||||
|       }, | ||||
|       data: { | ||||
|         ...req.body, | ||||
|         bio: description, | ||||
|         ...pick(req.body, [ | ||||
|           "username", | ||||
|           "name", | ||||
|           "avatar", | ||||
|           "timeZone", | ||||
|           "weekStart", | ||||
|           "hideBranding", | ||||
|           "theme", | ||||
|           "completedOnboarding", | ||||
|         ]), | ||||
|         bio: req.body.description, | ||||
|       }, | ||||
|     }); | ||||
|   } catch (e) { | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Chris S
						Chris S