beermanB
Convex Community16mo ago
237 replies
beerman

struggling with mutation

I'm trying to infer a type from my schema in order to type locationData which I will pass to the mutation but I keep getting the following error:
src/convex/addCompleteProperty.ts|7 col 23-62 error| Type 'TableDefinition<VObject<{ district?: string | undefined; city?: string | undefined; area?: string | undefined; postal_code?: string | undefined; nearest_landmark?: string | undefined; latitude?: number | undefined; longitude?: number | undefined; country: string; province: string; address: string; }, { ...; }, "requ...' does not satisfy the constraint 'Validator<any, OptionalProperty, any>'.

import { mutation } from './_generated/server';
import schema from './schema';
import { Infer } from 'convex/values';

type Location = Infer<typeof schema.tables.property_locations>;

export default mutation(
    async ({ db }, { propertyData, locationData, features, amenities, views }) => {
        // Insert or find the location
        const location = await db
            .query('property_locations')
            .withIndex('by_province', (q) => q.eq('province', locationData.province))
            .first();
}))
...


Here's the relevant section of my schema
export default defineSchema({
    property_locations: defineTable({
        country: v.string(),
        province: v.string(),
        district: v.optional(v.string()),
        city: v.optional(v.string()),
        area: v.optional(v.string()),
        postal_code: v.optional(v.string()),
        address: v.string(),
        nearest_landmark: v.optional(v.string()),
        latitude: v.optional(v.number()),
        longitude: v.optional(v.number())
    })
        .index('by_province', ['province'])
        .index('by_district', ['district'])
        .index('by_city', ['city'])
        .index('by_city_area', ['city', 'area'])
        .index('by_country', ['country'])
});


Where did I go wrong?
Was this page helpful?