Fixes some linting + codacy issues
This commit is contained in:
1 parent
5206fb4f88
commit
4d7427ad91
7 files changed
+563
-556
No files matched your search
+18
-13
@@ -1,23 +1,28 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { getSession } from 'next-auth/client';
|
||||
import prisma, {whereAndSelect} from '@lib/prisma';
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getSession } from "next-auth/client";
|
||||
import prisma, { whereAndSelect } from "@lib/prisma";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const session = await getSession({req: req});
|
||||
const session = await getSession({ req: req });
|
||||
|
||||
if (!session) {
|
||||
res.status(401).json({message: "Not authenticated"});
|
||||
return;
|
||||
res.status(401).json({ message: "Not authenticated" });
|
||||
return;
|
||||
}
|
||||
|
||||
// Get user
|
||||
const user = await whereAndSelect(prisma.user.findUnique, {
|
||||
const user = await whereAndSelect(
|
||||
prisma.user.findUnique,
|
||||
{
|
||||
id: session.user.id,
|
||||
},
|
||||
[ "id", "password" ]
|
||||
["id", "password"]
|
||||
);
|
||||
|
||||
if (!user) { res.status(404).json({message: 'User not found'}); return; }
|
||||
if (!user) {
|
||||
res.status(404).json({ message: "User not found" });
|
||||
return;
|
||||
}
|
||||
|
||||
const username = req.body.username;
|
||||
// username is changed: username is optional but it is necessary to be unique, enforce here
|
||||
@@ -25,10 +30,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
const userConflict = await prisma.user.findFirst({
|
||||
where: {
|
||||
username,
|
||||
}
|
||||
},
|
||||
});
|
||||
if (userConflict) {
|
||||
return res.status(409).json({ message: 'Username already taken' });
|
||||
return res.status(409).json({ message: "Username already taken" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +45,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
const hideBranding = req.body.hideBranding;
|
||||
const theme = req.body.theme;
|
||||
|
||||
const updateUser = await prisma.user.update({
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: user.id,
|
||||
},
|
||||
@@ -56,5 +61,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
},
|
||||
});
|
||||
|
||||
return res.status(200).json({message: 'Profile updated successfully'});
|
||||
return res.status(200).json({ message: "Profile updated successfully" });
|
||||
}
|
||||
Reference in new issue
Block a user