hyperzone
hyperzone
CCConvex Community
Created by hyperzone on 4/7/2024 in #support-community
Deleting an image when deleting an item
Say I have this part in the schema(using ents):
items: defineEnt({
name: v.string(),
description: v.string(),
image: v.id("_storage"),
})
items: defineEnt({
name: v.string(),
description: v.string(),
image: v.id("_storage"),
})
do I have to delete the image "manually" using
ctx.storage.delete(storageId);
ctx.storage.delete(storageId);
or is there a way to make it happen automatically when an item gets deleted?
2 replies
CCConvex Community
Created by hyperzone on 3/28/2024 in #support-community
'remove' in convex-ents patch not working
I'm reposting this from my old thread that didn't get any replies: Creating many to many ents works (using add inside a patch), but remove doesn't work on both sides:
const category = await ctx
.table("categories")
.getX(categoryId); // Id<"categories">

await category.patch({
items: {
remove: items, // Id<"items">[]
},
});
const category = await ctx
.table("categories")
.getX(categoryId); // Id<"categories">

await category.patch({
items: {
remove: items, // Id<"items">[]
},
});
the other side also doesn't work which is - getX each item and remove [category_.id] in a patch call this is the relevant part of the schema:
categories: defineEnt({
name: v.any(),
description: v.any(),
})
.field("isEnabled", v.boolean(), { default: true })
.edge("menu")
.edges("items"),
items: defineEnt({
name: v.any(),
description: v.any(),
price: v.float64(),
isEnabled: v.boolean(),
})
// item can be in multiple menus and categories
.edges("categories")
.edges("menus")
.edge("businesse"),
categories: defineEnt({
name: v.any(),
description: v.any(),
})
.field("isEnabled", v.boolean(), { default: true })
.edge("menu")
.edges("items"),
items: defineEnt({
name: v.any(),
description: v.any(),
price: v.float64(),
isEnabled: v.boolean(),
})
// item can be in multiple menus and categories
.edges("categories")
.edges("menus")
.edge("businesse"),
I'm not getting errors or anything, it just executes the mutation but the relevant categories_to_items document doesn't get deleted
10 replies
CCConvex Community
Created by hyperzone on 3/10/2024 in #support-community
delete many in convex-ents
I'm trying to delete multiple ents by IDs but for some reason there is no .delete on Ents returned from getMany unlike an Ent returned from .get. What is the best way to delete using an array of ids?
11 replies
CCConvex Community
Created by hyperzone on 3/6/2024 in #support-community
using zCustomMutation with convex-ents
How can I create a zMutation I can use from a mutation with a customCtx? I'm using this from the saas-starter:
export const mutation = customMutation(
baseMutation,
customCtx(async (baseCtx) => {
return await mutationCtx(baseCtx);
})
);

async function mutationCtx(baseCtx: BaseMutationCtx) {
const ctx = {
...baseCtx,
db: undefined,
table: entsTableFactory(baseCtx, entDefinitions),
};
const identity = await ctx.auth.getUserIdentity();
const viewer =
identity === null
? null
: await ctx.table("users").get("clerkUserId", identity.subject);
// .get("tokenIdentifier", identity.tokenIdentifier);
const viewerX = () => {
if (viewer === null) {
throw new Error("Expected authenticated viewer");
}
return viewer;
};
return { ...ctx, viewer, viewerX };
}
export const mutation = customMutation(
baseMutation,
customCtx(async (baseCtx) => {
return await mutationCtx(baseCtx);
})
);

async function mutationCtx(baseCtx: BaseMutationCtx) {
const ctx = {
...baseCtx,
db: undefined,
table: entsTableFactory(baseCtx, entDefinitions),
};
const identity = await ctx.auth.getUserIdentity();
const viewer =
identity === null
? null
: await ctx.table("users").get("clerkUserId", identity.subject);
// .get("tokenIdentifier", identity.tokenIdentifier);
const viewerX = () => {
if (viewer === null) {
throw new Error("Expected authenticated viewer");
}
return viewer;
};
return { ...ctx, viewer, viewerX };
}
I don't know if it's correct but I'm trying to export this:
export const zMutation = zCustomMutation(mutation, NoOp);
export const zMutation = zCustomMutation(mutation, NoOp);
but I'm getting a gigantic TS error and I'm pretty sure it's because it expects the db property on the context
9 replies
CCConvex Community
Created by hyperzone on 3/1/2024 in #support-community
Linking teams with Clerk organizations
I've looked at the saas-starter https://github.com/xixixao/saas-starter, and I'm looking to do something similiar and I was wondering, should I create a Clerk organization for each team? Instead of handling the invites by myself like in the example I could use their org features one of them being the invites and etc Are there downsides to this approach?
10 replies
CCConvex Community
Created by hyperzone on 2/27/2024 in #support-community
Using clerk sdk inside a mutation
I might be doing this wrong so if so I hope someone corrects me I'm trying to create a clerk organization inside a mutation because I also create a document with additional fields I need to be linked to the organization. I attempt to do that using the clerkClient from @clerk/clerk-sdk-node but I get Node errors when importing 'dotenv/config' at the top of the file. What is the correct way to do that?
7 replies
CCConvex Community
Created by hyperzone on 2/24/2024 in #support-community
i18n database schema
Hi everyone! I'm working on a project where users can create items (like 'hammer' and 'screwdriver) and provide translations for these items in multiple languages (English, German, French etc). When a user selects their preferred site language, the item should be displayed in that language. I'm trying to figure out the best way to structure my Convex schema to achieve this multi-language thing. Could anyone share insights or examples on how to implement a schema that stores translations in this way? Any guidance or references to similar implementations in Convex would be really helpful!
2 replies