mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-14 22:52:15 +02:00
fix(zero):scope core workspace queries
This commit is contained in:
parent
90c3dc98ca
commit
737d63f3dc
3 changed files with 33 additions and 14 deletions
|
|
@ -1,21 +1,31 @@
|
|||
import { defineQuery } from "@rocicorp/zero";
|
||||
import { z } from "zod";
|
||||
import { zql } from "../schema/index";
|
||||
import { constrainToAllowedSpaces } from "./authz";
|
||||
|
||||
export const messageQueries = {
|
||||
byThread: defineQuery(z.object({ threadId: z.number() }), ({ args: { threadId } }) =>
|
||||
zql.new_chat_messages.where("threadId", threadId).orderBy("createdAt", "asc")
|
||||
byThread: defineQuery(z.object({ threadId: z.number() }), ({ args: { threadId }, ctx }) =>
|
||||
zql.new_chat_messages
|
||||
.where("threadId", threadId)
|
||||
.whereExists("thread", (q) => constrainToAllowedSpaces(q, ctx))
|
||||
.orderBy("createdAt", "asc")
|
||||
),
|
||||
};
|
||||
|
||||
export const commentQueries = {
|
||||
byThread: defineQuery(z.object({ threadId: z.number() }), ({ args: { threadId } }) =>
|
||||
zql.chat_comments.where("threadId", threadId).orderBy("createdAt", "asc")
|
||||
byThread: defineQuery(z.object({ threadId: z.number() }), ({ args: { threadId }, ctx }) =>
|
||||
zql.chat_comments
|
||||
.where("threadId", threadId)
|
||||
.whereExists("thread", (q) => constrainToAllowedSpaces(q, ctx))
|
||||
.orderBy("createdAt", "asc")
|
||||
),
|
||||
};
|
||||
|
||||
export const chatSessionQueries = {
|
||||
byThread: defineQuery(z.object({ threadId: z.number() }), ({ args: { threadId } }) =>
|
||||
zql.chat_session_state.where("threadId", threadId).one()
|
||||
byThread: defineQuery(z.object({ threadId: z.number() }), ({ args: { threadId }, ctx }) =>
|
||||
zql.chat_session_state
|
||||
.where("threadId", threadId)
|
||||
.whereExists("thread", (q) => constrainToAllowedSpaces(q, ctx))
|
||||
.one()
|
||||
),
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue