import { Project } from "../common/types/project";
import { errors } from "@strapi/utils";
const { PolicyError } = errors
export default async (ctx, config, { strapi }) => {
const userId = ctx.state.user?.id;
const { id } = ctx.params;
if (!userId) {
return false
}
const project = await strapi.db.query("api::project.project").findOne({
where: { id },
populate: { user: true },
}) as Project;
if (!project || project.user?.id !== userId) {
throw new PolicyError("You are not the owner of this project")
}
return true;
};