mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-24 05:31:36 +10:00
partial: new documentation additions (company admin)
This commit is contained in:
@ -9,61 +9,67 @@ const GamePost = type({
|
||||
id: "string",
|
||||
}).configure(throwingArktype);
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["company:update"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
/**
|
||||
* Add a new game association to this company
|
||||
* @param id Company ID
|
||||
*/
|
||||
export default defineEventHandler<{ body: typeof GamePost.infer }>(
|
||||
async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["company:update"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const companyId = getRouterParam(h3, "id")!;
|
||||
const companyId = getRouterParam(h3, "id")!;
|
||||
|
||||
const body = await readDropValidatedBody(h3, GamePost);
|
||||
const body = await readDropValidatedBody(h3, GamePost);
|
||||
|
||||
if (!body.published && !body.developed)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Must be related (either developed or published).",
|
||||
if (!body.published && !body.developed)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Must be related (either developed or published).",
|
||||
});
|
||||
|
||||
const publisherConnect = body.published
|
||||
? {
|
||||
publishers: {
|
||||
connect: {
|
||||
id: companyId,
|
||||
},
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const developerConnect = body.developed
|
||||
? {
|
||||
developers: {
|
||||
connect: {
|
||||
id: companyId,
|
||||
},
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const game = await prisma.game.update({
|
||||
where: {
|
||||
id: body.id,
|
||||
},
|
||||
data: {
|
||||
...publisherConnect,
|
||||
...developerConnect,
|
||||
},
|
||||
include: {
|
||||
publishers: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
developers: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const publisherConnect = body.published
|
||||
? {
|
||||
publishers: {
|
||||
connect: {
|
||||
id: companyId,
|
||||
},
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const developerConnect = body.developed
|
||||
? {
|
||||
developers: {
|
||||
connect: {
|
||||
id: companyId,
|
||||
},
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const game = await prisma.game.update({
|
||||
where: {
|
||||
id: body.id,
|
||||
},
|
||||
data: {
|
||||
...publisherConnect,
|
||||
...developerConnect,
|
||||
},
|
||||
include: {
|
||||
publishers: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
developers: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return game;
|
||||
});
|
||||
return game;
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user