Skip to content

Open source personal finance application

fix(convex): validate color and currency fields in wallet/category mutations

Ilya Komichevf9443228ab41
diff --git a/convex/categories.ts b/convex/categories.ts
index 79e533d8..668c77f8 100644
--- a/convex/categories.ts
+++ b/convex/categories.ts
@@ -82,6 +82,8 @@ async function updateCategoryCore(
throw new Error('Icon is required')
if (args.name !== undefined && !args.name.trim())
throw new Error('Name is required')
+ if (args.color !== undefined && !args.color.trim())
+ throw new Error('Color is required')
const category = await getOwnEntity(ctx, id, userId)
@@ -127,6 +129,8 @@ export const create = mutation({
throw new Error('Icon is required')
if (!args.name.trim())
throw new Error('Name is required')
+ if (!args.color.trim())
+ throw new Error('Color is required')
const parentId = args.parentId ?? 0
diff --git a/convex/wallets.ts b/convex/wallets.ts
index 3c1d9de3..25b912a4 100644
--- a/convex/wallets.ts
+++ b/convex/wallets.ts
@@ -35,6 +35,10 @@ export const create = mutation({
const user = await requireAuthUser(ctx)
if (!args.name.trim())
throw new Error('Name is required')
+ if (!args.color.trim())
+ throw new Error('Color is required')
+ if (!args.currency.trim())
+ throw new Error('Currency is required')
return await ctx.db.insert('wallets', {
...args,
isArchived: args.isArchived ?? false,
@@ -64,6 +68,10 @@ export const update = mutation({
const user = await requireAuthUser(ctx)
if (args.name !== undefined && !args.name.trim())
throw new Error('Name is required')
+ if (args.color !== undefined && !args.color.trim())
+ throw new Error('Color is required')
+ if (args.currency !== undefined && !args.currency.trim())
+ throw new Error('Currency is required')
await getOwnEntity(ctx, id, user._id)
await ctx.db.patch(id, { ...args, updatedAt: Date.now() })
},