Coffee11
Coffee117mo ago

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,
})),
};
},
});
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),
})),
};
},
});
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),
})),
};
},
});
3 Replies
Coffee11
Coffee11OP7mo ago
Problem solved
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);

const updatedPage = await Promise.all(
results.page.map(async (propertyListing) => ({
...propertyListing,
listingType: (await ctx.db.get(propertyListing.listingType))?.name,
propertyType: (await ctx.db.get(propertyListing.propertyType))?.name,
}))
);

return {
...results,
page: updatedPage,
};
},
});
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);

const updatedPage = await Promise.all(
results.page.map(async (propertyListing) => ({
...propertyListing,
listingType: (await ctx.db.get(propertyListing.listingType))?.name,
propertyType: (await ctx.db.get(propertyListing.propertyType))?.name,
}))
);

return {
...results,
page: updatedPage,
};
},
});
erquhart
erquhart7mo ago
Are you saying the code you pasted is working? Can you share the code that isn't? This error means you have a promise nested in your query return value.
Coffee11
Coffee11OP7mo ago
Already solved thank you my friend

Did you find this page helpful?