2026-06-10 18:44:35 +02:00
|
|
|
import { defineQuery } from "@rocicorp/zero";
|
|
|
|
|
import { z } from "zod";
|
|
|
|
|
import { zql } from "../schema/index";
|
2026-06-23 13:01:21 +05:30
|
|
|
import { canReadSpace, constrainToAllowedSpaces, denySpace } from "./authz";
|
2026-06-10 18:44:35 +02:00
|
|
|
|
|
|
|
|
export const podcastQueries = {
|
2026-06-25 04:31:22 +05:30
|
|
|
bySpace: defineQuery(
|
|
|
|
|
z.object({ searchSpaceId: z.number() }),
|
|
|
|
|
({ args: { searchSpaceId }, ctx }) => {
|
|
|
|
|
const query = zql.podcasts.where("searchSpaceId", searchSpaceId);
|
|
|
|
|
if (!canReadSpace(ctx, searchSpaceId)) return denySpace(query).orderBy("createdAt", "desc");
|
|
|
|
|
return constrainToAllowedSpaces(query, ctx).orderBy("createdAt", "desc");
|
|
|
|
|
}
|
|
|
|
|
),
|
2026-06-23 13:01:21 +05:30
|
|
|
byId: defineQuery(z.object({ podcastId: z.number() }), ({ args: { podcastId }, ctx }) =>
|
|
|
|
|
constrainToAllowedSpaces(zql.podcasts.where("id", podcastId), ctx).one()
|
2026-06-10 18:44:35 +02:00
|
|
|
),
|
|
|
|
|
};
|