Spiced
Spiced
CCConvex Community
Created by Spiced on 2/17/2024 in #support-community
Trying to create custom function
import { query } from "../_generated/server";
import { customQuery, customCtx } from "convex-helpers/server/customFunctions";

// Use `userQuery` instead of `query` to add this behavior.
const userQuery = customQuery(
query, // The base function we're extending
// Here we're using a `customCtx` helper because our modification
// only modifies the `ctx` argument to the function.
customCtx(async (ctx) => {
// Look up the logged in user
const identity = await ctx.auth.getUserIdentity();
if (!identity) throw new Error("Unauthorized");
// Pass in a user to use in evaluating rules,
// which validate data access at access / write time.
const db = wrapDatabaseReader({ identity }, ctx.db, rules);
// This new ctx will be applied to the function's.
// The user is a new field, the db replaces ctx.db
return { identity, db };
}),
);
import { query } from "../_generated/server";
import { customQuery, customCtx } from "convex-helpers/server/customFunctions";

// Use `userQuery` instead of `query` to add this behavior.
const userQuery = customQuery(
query, // The base function we're extending
// Here we're using a `customCtx` helper because our modification
// only modifies the `ctx` argument to the function.
customCtx(async (ctx) => {
// Look up the logged in user
const identity = await ctx.auth.getUserIdentity();
if (!identity) throw new Error("Unauthorized");
// Pass in a user to use in evaluating rules,
// which validate data access at access / write time.
const db = wrapDatabaseReader({ identity }, ctx.db, rules);
// This new ctx will be applied to the function's.
// The user is a new field, the db replaces ctx.db
return { identity, db };
}),
);
In this case the wrapDatabaseReader and rules are not being found. Any suggestions ?
2 replies
CCConvex Community
Created by Spiced on 2/16/2024 in #support-community
Custom FilterIf Function
creating a custom filter if funciton
82 replies
CCConvex Community
Created by Spiced on 2/13/2024 in #support-community
Contains query on a collection
I want to have a contains query in a collection.
30 replies
CCConvex Community
Created by Spiced on 2/11/2024 in #support-community
How can i access a one to many relationship.
export const getByIdInfo = query({
args: {
diagramId: v.optional(v.id("diagrams")),
},
handler: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity();

if (!args.diagramId) {
return; // No diagramId provided
}

const document = await ctx.db.get(args.diagramId);

if (!document) {
throw new Error("Document not found or unauthorized access");
}

if (!identity || document.userId !== identity.subject) {
throw new Error("Unauthorized access");
}

return { ...document }; // Return the document information
},
});
export const getByIdInfo = query({
args: {
diagramId: v.optional(v.id("diagrams")),
},
handler: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity();

if (!args.diagramId) {
return; // No diagramId provided
}

const document = await ctx.db.get(args.diagramId);

if (!document) {
throw new Error("Document not found or unauthorized access");
}

if (!identity || document.userId !== identity.subject) {
throw new Error("Unauthorized access");
}

return { ...document }; // Return the document information
},
});
this is my api, the diagram table has a databaseTypeId, which in turn has a seperate relationship with a table called databasetypes. How can i access it through this relationship and pull the name of the id?
3 replies