Coffee11C
Convex Community2y ago
3 replies
Coffee11

Promise {} is not a supported Convex type in paginated query with join

Working
export const getPropertyListings = query({
  args: {
    listingTypeId: v.id("listing_types"),
    properTypeId: v.id("property_types"),
    paginationOpts: paginationOptsValidator,
  },
  handler: async (ctx, args) => {
    const identity = await ctx.auth.getUserIdentity();

    if (identity === null) {
      throw new Error("Not authenticated");
    }

    const results = await ctx.db
      .query("property_listings")
      .filter((q) => q.eq(q.field("listingType"), args.listingTypeId))
      .filter((q) => q.eq(q.field("propertyType"), args.properTypeId))
      .order("desc")
      .paginate(args.paginationOpts);

    return {
      ...results,
      page: results.page.map((propertyListing) => ({
        ...propertyListing,
      })),
    };
  },
});


Not working
export const getPropertyListings = query({
  args: {
    listingTypeId: v.id("listing_types"),
    properTypeId: v.id("property_types"),
    paginationOpts: paginationOptsValidator,
  },
  handler: async (ctx, args) => {
    const identity = await ctx.auth.getUserIdentity();

    if (identity === null) {
      throw new Error("Not authenticated");
    }

    const results = await ctx.db
      .query("property_listings")
      .filter((q) => q.eq(q.field("listingType"), args.listingTypeId))
      .filter((q) => q.eq(q.field("propertyType"), args.properTypeId))
      .order("desc")
      .paginate(args.paginationOpts);

    return {
      ...results,
      page: results.page.map(async (propertyListing) => ({
        ...propertyListing,
        listingType: await ctx.db.get(propertyListing.listingType),
        propertyType: await ctx.db.get(propertyListing.propertyType),
      })),
    };
  },
});
Was this page helpful?