Add missing integrations.info endpoint (#6474)

This commit is contained in:
Tom Moor
2024-02-01 20:18:55 -08:00
committed by GitHub
parent aecefc2c01
commit 490a1b6009
2 changed files with 30 additions and 1 deletions

View File

@@ -7,7 +7,7 @@ import validate from "@server/middlewares/validate";
import { Event, IntegrationAuthentication } from "@server/models";
import Integration from "@server/models/Integration";
import { authorize } from "@server/policies";
import { presentIntegration } from "@server/presenters";
import { presentIntegration, presentPolicies } from "@server/presenters";
import { APIContext } from "@server/types";
import pagination from "../middlewares/pagination";
import * as T from "./schema";
@@ -72,6 +72,26 @@ router.post(
}
);
router.post(
"integrations.info",
auth(),
validate(T.IntegrationsInfoSchema),
async (ctx: APIContext<T.IntegrationsInfoReq>) => {
const { id } = ctx.input.body;
const { user } = ctx.state.auth;
const integration = await Integration.findByPk(id, {
rejectOnEmpty: true,
});
authorize(user, "read", integration);
ctx.body = {
data: presentIntegration(integration),
policies: presentPolicies(user, [integration]),
};
}
);
router.post(
"integrations.update",
auth({ admin: true }),

View File

@@ -81,6 +81,15 @@ export const IntegrationsUpdateSchema = BaseSchema.extend({
export type IntegrationsUpdateReq = z.infer<typeof IntegrationsUpdateSchema>;
export const IntegrationsInfoSchema = BaseSchema.extend({
body: z.object({
/** Id of integration to find */
id: z.string().uuid(),
}),
});
export type IntegrationsInfoReq = z.infer<typeof IntegrationsInfoSchema>;
export const IntegrationsDeleteSchema = BaseSchema.extend({
body: z.object({
/** Id of integration to be deleted */