Fixes integrations api endpoint (#1066)
This commit is contained in:
parent
94f3ae1c64
commit
265b76083a
1 changed files with 25 additions and 21 deletions
|
@ -1,20 +1,25 @@
|
||||||
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
|
||||||
import { getSession } from "@lib/auth";
|
import { getSession } from "@lib/auth";
|
||||||
|
import prisma from "@lib/prisma";
|
||||||
|
|
||||||
import prisma from "../../lib/prisma";
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
if (!["GET", "DELETE"].includes(req.method!)) {
|
||||||
|
return res.status(405).end();
|
||||||
|
}
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
|
||||||
if (req.method === "GET") {
|
|
||||||
// Check that user is authenticated
|
// Check that user is authenticated
|
||||||
const session = await getSession({ req: req });
|
const session = await getSession({ req });
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
res.status(401).json({ message: "You must be logged in to do this" });
|
res.status(401).json({ message: "You must be logged in to do this" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (req.method === "GET") {
|
||||||
const credentials = await prisma.credential.findMany({
|
const credentials = await prisma.credential.findMany({
|
||||||
where: {
|
where: {
|
||||||
userId: session.user.id,
|
userId: session.user?.id,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
type: true,
|
type: true,
|
||||||
|
@ -25,19 +30,18 @@ export default async function handler(req, res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.method == "DELETE") {
|
if (req.method == "DELETE") {
|
||||||
const session = await getSession({ req: req });
|
|
||||||
|
|
||||||
if (!session) {
|
|
||||||
res.status(401).json({ message: "You must be logged in to do this" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const id = req.body.id;
|
const id = req.body.id;
|
||||||
|
|
||||||
await prisma.credential.delete({
|
await prisma.user.update({
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: session?.user?.id,
|
||||||
userId: session.user.id,
|
},
|
||||||
|
data: {
|
||||||
|
credentials: {
|
||||||
|
delete: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue