mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-22 04:31:15 +10:00
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import aclManager from "~/server/internal/acls";
|
|
import prisma from "~/server/internal/db/database";
|
|
|
|
/**
|
|
* Fetch a company and its associations
|
|
* @param id Company ID
|
|
*/
|
|
export default defineEventHandler(async (h3) => {
|
|
const allowed = await aclManager.allowSystemACL(h3, ["company:read"]);
|
|
if (!allowed) throw createError({ statusCode: 403 });
|
|
|
|
const id = getRouterParam(h3, "id")!;
|
|
|
|
const company = await prisma.company.findUnique({
|
|
where: { id },
|
|
include: {
|
|
published: {
|
|
select: {
|
|
id: true,
|
|
},
|
|
},
|
|
developed: {
|
|
select: {
|
|
id: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
if (!company)
|
|
throw createError({ statusCode: 404, statusMessage: "Company not found" });
|
|
const games = await prisma.game.findMany({
|
|
where: {
|
|
OR: [
|
|
{
|
|
developers: {
|
|
some: {
|
|
id: company.id,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
publishers: {
|
|
some: {
|
|
id: company.id,
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
distinct: ["id"],
|
|
});
|
|
const companyFlatten = {
|
|
...company,
|
|
developed: company.developed.map((e) => e.id),
|
|
published: company.published.map((e) => e.id),
|
|
};
|
|
return { company: companyFlatten, games };
|
|
});
|