all repos — caroster @ 14aa569691fa352558026139510056a49df29b07

[Octree] Group carpool to your event https://caroster.io

backend/src/api/event/policies/check-caroster-plus.ts (view raw)

 1import { errors } from "@strapi/utils";
 2
 3export default async (policyContext, _config, { strapi }) => {
 4  const { uuid } = policyContext.args;
 5
 6  const event = await strapi.db
 7    .query("api::event.event")
 8    .findOne({ where: { uuid } });
 9
10  if (!event) throw new errors.NotFoundError(`Event not found`);
11
12  if (event.enabled_modules?.includes("caroster-plus")) {
13    const user = policyContext.state.user;
14    if (!user) throw new errors.ForbiddenError();
15
16    const admins = event.administrators?.split(/, ?/) || [];
17    return [...admins, event.email].includes(user.email);
18  }
19};