Fix issues in multiple endpoints (#679)

pull/682/head
Chris S 2021-09-17 07:25:48 -04:00 committed by GitHub
parent e3843f5a0e
commit 13486d9988
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 14 deletions

View File

@ -34,13 +34,6 @@ export default async function handler(req, res) {
email: email, email: email,
}, },
], ],
AND: [
{
emailVerified: {
not: null,
},
},
],
}, },
}); });

View File

@ -37,6 +37,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
in: memberships.map((membership) => membership.userId), 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) => { members = members.map((member) => {

View File

@ -1,6 +1,7 @@
import type { NextApiRequest, NextApiResponse } from "next"; import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@lib/prisma"; import prisma from "@lib/prisma";
import { getSession } from "@lib/auth"; import { getSession } from "@lib/auth";
import { pick } from "lodash";
export default async function handler(req: NextApiRequest, res: NextApiResponse) { export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const session = await getSession({ req: req }); const session = await getSession({ req: req });
@ -34,13 +35,41 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
} }
if (req.method === "PATCH") { if (req.method === "PATCH") {
const data = req.body.data;
const updatedUser = await prisma.user.update({ const updatedUser = await prisma.user.update({
where: { where: {
id: authenticatedUser.id, id: authenticatedUser.id,
}, },
data: { 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 }); return res.status(200).json({ message: "User Updated", data: updatedUser });

View File

@ -1,6 +1,7 @@
import type { NextApiRequest, NextApiResponse } from "next"; import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@lib/prisma"; import prisma from "@lib/prisma";
import { getSession } from "@lib/auth"; import { getSession } from "@lib/auth";
import { pick } from "lodash";
export default async function handler(req: NextApiRequest, res: NextApiResponse) { export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const session = await getSession({ req: req }); const session = await getSession({ req: req });
@ -10,17 +11,23 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
return; return;
} }
const description = req.body.description;
delete req.body.description;
try { try {
await prisma.user.update({ await prisma.user.update({
where: { where: {
id: session.user.id, id: session.user.id,
}, },
data: { data: {
...req.body, ...pick(req.body, [
bio: description, "username",
"name",
"avatar",
"timeZone",
"weekStart",
"hideBranding",
"theme",
"completedOnboarding",
]),
bio: req.body.description,
}, },
}); });
} catch (e) { } catch (e) {