mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-15 01:01:20 +10:00
feat: partial user platform support + statusMessage -> message
This commit is contained in:
@ -15,13 +15,13 @@ export default defineEventHandler(async (h3) => {
|
||||
});
|
||||
|
||||
if (!company)
|
||||
throw createError({ statusCode: 400, statusMessage: "Invalid company id" });
|
||||
throw createError({ statusCode: 400, message: "Invalid company id" });
|
||||
|
||||
const result = await handleFileUpload(h3, {}, ["internal:read"], 1);
|
||||
if (!result)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "File upload required (multipart form)",
|
||||
message: "File upload required (multipart form)",
|
||||
});
|
||||
|
||||
const [ids, , pull, dump] = result;
|
||||
@ -29,7 +29,7 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!id)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Upload at least one file.",
|
||||
message: "Upload at least one file.",
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
@ -20,7 +20,7 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!body.published && !body.developed)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Must be related (either developed or published).",
|
||||
message: "Must be related (either developed or published).",
|
||||
});
|
||||
|
||||
const publisherConnect = body.published
|
||||
|
||||
@ -15,13 +15,13 @@ export default defineEventHandler(async (h3) => {
|
||||
});
|
||||
|
||||
if (!company)
|
||||
throw createError({ statusCode: 400, statusMessage: "Invalid company id" });
|
||||
throw createError({ statusCode: 400, message: "Invalid company id" });
|
||||
|
||||
const result = await handleFileUpload(h3, {}, ["internal:read"], 1);
|
||||
if (!result)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "File upload required (multipart form)",
|
||||
message: "File upload required (multipart form)",
|
||||
});
|
||||
|
||||
const [ids, , pull, dump] = result;
|
||||
@ -29,7 +29,7 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!id)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Upload at least one file.",
|
||||
message: "Upload at least one file.",
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
@ -9,6 +9,6 @@ export default defineEventHandler(async (h3) => {
|
||||
|
||||
const company = await prisma.company.deleteMany({ where: { id } });
|
||||
if (company.count == 0)
|
||||
throw createError({ statusCode: 404, statusMessage: "Company not found" });
|
||||
throw createError({ statusCode: 404, message: "Company not found" });
|
||||
return;
|
||||
});
|
||||
|
||||
@ -23,7 +23,7 @@ export default defineEventHandler(async (h3) => {
|
||||
},
|
||||
});
|
||||
if (!company)
|
||||
throw createError({ statusCode: 404, statusMessage: "Company not found" });
|
||||
throw createError({ statusCode: 404, message: "Company not found" });
|
||||
const games = await prisma.game.findMany({
|
||||
where: {
|
||||
OR: [
|
||||
|
||||
@ -33,7 +33,7 @@ export default defineEventHandler(async (h3) => {
|
||||
});
|
||||
|
||||
if (!game || !game.libraryId)
|
||||
throw createError({ statusCode: 404, statusMessage: "Game ID not found" });
|
||||
throw createError({ statusCode: 404, message: "Game ID not found" });
|
||||
|
||||
const unimportedVersions = await libraryManager.fetchUnimportedGameVersions(
|
||||
game.libraryId,
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
import { ArkErrors, type } from "arktype";
|
||||
import type { Prisma } from "~/prisma/client/client";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import { handleFileUpload } from "~/server/internal/utils/handlefileupload";
|
||||
|
||||
const UpdateMetadata = type({
|
||||
name: "string?",
|
||||
description: "string?",
|
||||
});
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["game:update"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
@ -11,7 +17,7 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!form)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "This endpoint requires multipart form data.",
|
||||
message: "This endpoint requires multipart form data.",
|
||||
});
|
||||
|
||||
const gameId = getRouterParam(h3, "id")!;
|
||||
@ -20,20 +26,20 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!uploadResult)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Failed to upload file",
|
||||
message: "Failed to upload file",
|
||||
});
|
||||
|
||||
const [ids, options, pull, dump] = uploadResult;
|
||||
|
||||
const id = ids.at(0);
|
||||
|
||||
// handleFileUpload reads the rest of the options for us.
|
||||
const name = options.name;
|
||||
const description = options.description;
|
||||
const body = UpdateMetadata(options);
|
||||
if (body instanceof ArkErrors)
|
||||
throw createError({ statusCode: 400, message: body.summary });
|
||||
|
||||
const updateModel: Prisma.GameUpdateInput = {
|
||||
mName: name,
|
||||
mShortDescription: description,
|
||||
...(body.name ? { mName: body.name } : undefined),
|
||||
...(body.description ? { mShortDescription: body.description } : undefined),
|
||||
};
|
||||
|
||||
// handle if user uploaded new icon
|
||||
|
||||
@ -32,11 +32,11 @@ export default defineEventHandler<{
|
||||
});
|
||||
|
||||
if (!game)
|
||||
throw createError({ statusCode: 400, statusMessage: "Invalid game ID" });
|
||||
throw createError({ statusCode: 400, message: "Invalid game ID" });
|
||||
|
||||
const imageIndex = game.mImageLibraryObjectIds.findIndex((e) => e == imageId);
|
||||
if (imageIndex == -1)
|
||||
throw createError({ statusCode: 400, statusMessage: "Image not found" });
|
||||
throw createError({ statusCode: 400, message: "Image not found" });
|
||||
|
||||
game.mImageLibraryObjectIds.splice(imageIndex, 1);
|
||||
await objectHandler.deleteAsSystem(imageId);
|
||||
|
||||
@ -10,14 +10,14 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!form)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "This endpoint requires multipart form data.",
|
||||
message: "This endpoint requires multipart form data.",
|
||||
});
|
||||
|
||||
const uploadResult = await handleFileUpload(h3, {}, ["internal:read"]);
|
||||
if (!uploadResult)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Failed to upload file",
|
||||
message: "Failed to upload file",
|
||||
});
|
||||
|
||||
const [ids, options, pull, dump] = uploadResult;
|
||||
@ -25,21 +25,21 @@ export default defineEventHandler(async (h3) => {
|
||||
dump();
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Did not upload a file",
|
||||
message: "Did not upload a file",
|
||||
});
|
||||
}
|
||||
|
||||
const gameId = options.id;
|
||||
const gameId = options.id as string;
|
||||
if (!gameId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "No game ID attached",
|
||||
message: "No game ID attached",
|
||||
});
|
||||
|
||||
const hasGame = (await prisma.game.count({ where: { id: gameId } })) != 0;
|
||||
if (!hasGame) {
|
||||
dump();
|
||||
throw createError({ statusCode: 400, statusMessage: "Invalid game ID" });
|
||||
throw createError({ statusCode: 400, message: "Invalid game ID" });
|
||||
}
|
||||
|
||||
const result = await prisma.game.update({
|
||||
|
||||
@ -27,14 +27,14 @@ export default defineEventHandler<{ body: typeof ImportGameBody.infer }>(
|
||||
if (!path)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Path missing from body",
|
||||
message: "Path missing from body",
|
||||
});
|
||||
|
||||
const valid = await libraryManager.checkUnimportedGamePath(library, path);
|
||||
if (!valid)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Invalid library or game.",
|
||||
message: "Invalid library or game.",
|
||||
});
|
||||
|
||||
const taskId = metadata
|
||||
@ -44,7 +44,7 @@ export default defineEventHandler<{ body: typeof ImportGameBody.infer }>(
|
||||
if (!taskId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage:
|
||||
message:
|
||||
"Duplicate metadata import. Please chose a different game or metadata provider.",
|
||||
});
|
||||
|
||||
|
||||
@ -8,14 +8,14 @@ export default defineEventHandler(async (h3) => {
|
||||
const query = getQuery(h3);
|
||||
const search = query.q?.toString();
|
||||
if (!search)
|
||||
throw createError({ statusCode: 400, statusMessage: "Invalid search" });
|
||||
throw createError({ statusCode: 400, message: "Invalid search" });
|
||||
|
||||
const results = await metadataHandler.search(search);
|
||||
|
||||
if (results.length == 0)
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: "No metadata provider returned search results.",
|
||||
message: "No metadata provider returned search results.",
|
||||
});
|
||||
|
||||
return results;
|
||||
|
||||
@ -4,6 +4,7 @@ import { handleFileUpload } from "~/server/internal/utils/handlefileupload";
|
||||
import * as jdenticon from "jdenticon";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import libraryManager from "~/server/internal/library";
|
||||
import jsdom from "jsdom";
|
||||
|
||||
export const ImportRedist = type({
|
||||
library: "string",
|
||||
@ -11,6 +12,12 @@ export const ImportRedist = type({
|
||||
|
||||
name: "string",
|
||||
description: "string",
|
||||
|
||||
"platform?": type({
|
||||
name: "string",
|
||||
icon: "string",
|
||||
fileExts: type("string").pipe.try((s) => JSON.parse(s), type("string[]")),
|
||||
}),
|
||||
});
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
@ -18,14 +25,13 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const body = await handleFileUpload(h3, {}, ["internal:read"], 1);
|
||||
if (!body)
|
||||
throw createError({ statusCode: 400, statusMessage: "Body required." });
|
||||
if (!body) throw createError({ statusCode: 400, message: "Body required." });
|
||||
|
||||
const [[id], rawOptions, pull,, add] = body;
|
||||
const [[id], rawOptions, pull, , add] = body;
|
||||
|
||||
const options = ImportRedist(rawOptions);
|
||||
if (options instanceof ArkErrors)
|
||||
throw createError({ statusCode: 400, statusMessage: options.summary });
|
||||
throw createError({ statusCode: 400, message: options.summary });
|
||||
|
||||
const valid = await libraryManager.checkUnimportedGamePath(
|
||||
options.library,
|
||||
@ -34,11 +40,25 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!valid)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Invalid library or game.",
|
||||
message: "Invalid library or game.",
|
||||
});
|
||||
|
||||
const icon = id ?? add(jdenticon.toPng(options.name, 512));
|
||||
|
||||
let svgContent = "";
|
||||
if (options.platform) {
|
||||
const dom = new jsdom.JSDOM(options.platform.icon);
|
||||
const svg = dom.window.document.getElementsByTagName("svg").item(0);
|
||||
if (!svg)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "No SVG in uploaded image.",
|
||||
});
|
||||
svg.removeAttribute("width");
|
||||
svg.removeAttribute("height");
|
||||
svgContent = svg.outerHTML;
|
||||
}
|
||||
|
||||
const redist = await prisma.redist.create({
|
||||
data: {
|
||||
libraryId: options.library,
|
||||
@ -47,6 +67,18 @@ export default defineEventHandler(async (h3) => {
|
||||
mName: options.name,
|
||||
mShortDescription: options.description,
|
||||
mIconObjectId: icon,
|
||||
|
||||
platform: {
|
||||
...(options.platform
|
||||
? {
|
||||
create: {
|
||||
platformName: options.platform.name,
|
||||
iconSvg: svgContent,
|
||||
fileExtensions: options.platform.fileExts,
|
||||
},
|
||||
}
|
||||
: undefined),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!gameId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Missing id in request params",
|
||||
message: "Missing id in request params",
|
||||
});
|
||||
|
||||
const game = await prisma.game.findUnique({
|
||||
@ -19,14 +19,14 @@ export default defineEventHandler(async (h3) => {
|
||||
select: { libraryId: true, libraryPath: true },
|
||||
});
|
||||
if (!game || !game.libraryId)
|
||||
throw createError({ statusCode: 404, statusMessage: "Game not found" });
|
||||
throw createError({ statusCode: 404, message: "Game not found" });
|
||||
|
||||
const unimportedVersions = await libraryManager.fetchUnimportedGameVersions(
|
||||
game.libraryId,
|
||||
game.libraryPath,
|
||||
);
|
||||
if (!unimportedVersions)
|
||||
throw createError({ statusCode: 400, statusMessage: "Invalid game ID" });
|
||||
throw createError({ statusCode: 400, message: "Invalid game ID" });
|
||||
|
||||
return unimportedVersions;
|
||||
});
|
||||
|
||||
@ -5,6 +5,13 @@ import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import libraryManager from "~/server/internal/library";
|
||||
|
||||
export const LaunchCommands = type({
|
||||
name: "string > 0",
|
||||
description: "string = ''",
|
||||
launchCommand: "string > 0",
|
||||
launchArgs: "string = ''",
|
||||
}).array();
|
||||
|
||||
export const ImportVersion = type({
|
||||
id: "string",
|
||||
version: "string",
|
||||
@ -17,12 +24,7 @@ export const ImportVersion = type({
|
||||
delta: "boolean = false",
|
||||
umuId: "string = ''",
|
||||
|
||||
launches: type({
|
||||
name: "string > 0",
|
||||
description: "string = ''",
|
||||
launchCommand: "string > 0",
|
||||
launchArgs: "string = ''",
|
||||
}).array(),
|
||||
launches: LaunchCommands,
|
||||
}).configure(throwingArktype);
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
@ -41,7 +43,7 @@ export default defineEventHandler(async (h3) => {
|
||||
if (validOverlayVersions == 0)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage:
|
||||
message:
|
||||
"Update mode requires a pre-existing version for this platform.",
|
||||
});
|
||||
}
|
||||
@ -50,13 +52,13 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!body.setup)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'Setup required in "setup mode".',
|
||||
message: 'Setup required in "setup mode".',
|
||||
});
|
||||
} else {
|
||||
if (!body.delta && body.launches.length == 0)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage:
|
||||
message:
|
||||
"At least one launch command is required for non-delta versions",
|
||||
});
|
||||
}
|
||||
@ -70,7 +72,7 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!taskId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Invalid options for import",
|
||||
message: "Invalid options for import",
|
||||
});
|
||||
|
||||
return { taskId: taskId };
|
||||
|
||||
@ -11,7 +11,7 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!gameId || !versionName)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Missing id or version in request params",
|
||||
message: "Missing id or version in request params",
|
||||
});
|
||||
|
||||
const preload = await libraryManager.fetchUnimportedVersionInformation(
|
||||
@ -21,7 +21,7 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!preload)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Invalid game or version id/name",
|
||||
message: "Invalid game or version id/name",
|
||||
});
|
||||
|
||||
return preload;
|
||||
|
||||
@ -26,7 +26,7 @@ export default defineEventHandler<{ body: typeof UpdateLibrarySource.infer }>(
|
||||
if (!source)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Library source not found",
|
||||
message: "Library source not found",
|
||||
});
|
||||
|
||||
const constructor = libraryConstructors[source.backend];
|
||||
@ -61,7 +61,7 @@ export default defineEventHandler<{ body: typeof UpdateLibrarySource.infer }>(
|
||||
} catch (e) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: `Failed to create source: ${e}`,
|
||||
message: `Failed to create source: ${e}`,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
@ -29,7 +29,7 @@ export default defineEventHandler<{ body: typeof CreateLibrarySource.infer }>(
|
||||
if (!backend)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Invalid source backend.",
|
||||
message: "Invalid source backend.",
|
||||
});
|
||||
|
||||
const constructor = libraryConstructors[backend];
|
||||
@ -63,7 +63,7 @@ export default defineEventHandler<{ body: typeof CreateLibrarySource.infer }>(
|
||||
} catch (e) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: `Failed to create source: ${e}`,
|
||||
message: `Failed to create source: ${e}`,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
@ -14,13 +14,13 @@ export default defineEventHandler(async (h3) => {
|
||||
const orderBy = query.order as "asc" | "desc";
|
||||
if (orderBy) {
|
||||
if (typeof orderBy !== "string" || !["asc", "desc"].includes(orderBy))
|
||||
throw createError({ statusCode: 400, statusMessage: "Invalid order" });
|
||||
throw createError({ statusCode: 400, message: "Invalid order" });
|
||||
}
|
||||
|
||||
const tags = query.tags as string[] | undefined;
|
||||
if (tags) {
|
||||
if (typeof tags !== "object" || !Array.isArray(tags))
|
||||
throw createError({ statusCode: 400, statusMessage: "Invalid tags" });
|
||||
throw createError({ statusCode: 400, message: "Invalid tags" });
|
||||
}
|
||||
|
||||
const options = {
|
||||
|
||||
@ -19,27 +19,27 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!form)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "This endpoint requires multipart form data.",
|
||||
message: "This endpoint requires multipart form data.",
|
||||
});
|
||||
|
||||
const uploadResult = await handleFileUpload(h3, {}, ["internal:read"], 1);
|
||||
if (!uploadResult)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Failed to upload file",
|
||||
message: "Failed to upload file",
|
||||
});
|
||||
|
||||
const [imageIds, options, pull, _dump] = uploadResult;
|
||||
|
||||
const body = await CreateNews(options);
|
||||
if (body instanceof ArkErrors)
|
||||
throw createError({ statusCode: 400, statusMessage: body.summary });
|
||||
throw createError({ statusCode: 400, message: body.summary });
|
||||
|
||||
const parsedTags = JSON.parse(body.tags);
|
||||
if (typeof parsedTags !== "object" || !Array.isArray(parsedTags))
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Tags must be an array",
|
||||
message: "Tags must be an array",
|
||||
});
|
||||
|
||||
const imageId = imageIds.at(0);
|
||||
|
||||
@ -9,6 +9,6 @@ export default defineEventHandler(async (h3) => {
|
||||
|
||||
const tag = await prisma.gameTag.deleteMany({ where: { id } });
|
||||
if (tag.count == 0)
|
||||
throw createError({ statusCode: 404, statusMessage: "Tag not found" });
|
||||
throw createError({ statusCode: 404, message: "Tag not found" });
|
||||
return;
|
||||
});
|
||||
|
||||
@ -10,7 +10,7 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!allAcls)
|
||||
throw createError({
|
||||
statusCode: 403,
|
||||
statusMessage: "Somehow no ACLs on authenticated request.",
|
||||
message: "Somehow no ACLs on authenticated request.",
|
||||
});
|
||||
|
||||
const runningTasks = (await taskHandler.runningTasks()).map((e) => e.id);
|
||||
|
||||
@ -18,14 +18,14 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!taskGroups[taskGroup])
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Invalid task group.",
|
||||
message: "Invalid task group.",
|
||||
});
|
||||
|
||||
const task = await taskHandler.runTaskGroupByName(taskGroup);
|
||||
if (!task)
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: "Could not start task.",
|
||||
message: "Could not start task.",
|
||||
});
|
||||
return { id: task };
|
||||
});
|
||||
|
||||
@ -10,14 +10,14 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!id)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "No id in router params",
|
||||
message: "No id in router params",
|
||||
});
|
||||
|
||||
const deleted = await prisma.aPIToken.delete({
|
||||
where: { id: id, mode: APITokenMode.System },
|
||||
})!;
|
||||
if (!deleted)
|
||||
throw createError({ statusCode: 404, statusMessage: "Token not found" });
|
||||
throw createError({ statusCode: 404, message: "Token not found" });
|
||||
|
||||
return;
|
||||
});
|
||||
|
||||
@ -22,7 +22,7 @@ export default defineEventHandler(async (h3) => {
|
||||
if (invalidACLs.length > 0)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: `Invalid ACLs: ${invalidACLs.join(", ")}`,
|
||||
message: `Invalid ACLs: ${invalidACLs.join(", ")}`,
|
||||
});
|
||||
|
||||
const token = await prisma.aPIToken.create({
|
||||
|
||||
@ -19,12 +19,12 @@ export default defineEventHandler(async (h3) => {
|
||||
if (userId === "system")
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Cannot interact with system user.",
|
||||
message: "Cannot interact with system user.",
|
||||
});
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user)
|
||||
throw createError({ statusCode: 404, statusMessage: "User not found." });
|
||||
throw createError({ statusCode: 404, message: "User not found." });
|
||||
|
||||
await prisma.user.delete({ where: { id: userId } });
|
||||
return { success: true };
|
||||
|
||||
@ -9,18 +9,18 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!userId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "No userId in route.",
|
||||
message: "No userId in route.",
|
||||
});
|
||||
|
||||
if (userId == "system")
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Cannot fetch system user.",
|
||||
message: "Cannot fetch system user.",
|
||||
});
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user)
|
||||
throw createError({ statusCode: 404, statusMessage: "User not found." });
|
||||
throw createError({ statusCode: 404, message: "User not found." });
|
||||
|
||||
return user;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user