Prince
Prince8mo ago

.paginate() result type returning a single document, not an array of documents

export const getPaginatedReports = query({
args: {
admin: v.optional(v.boolean()),
paginationOpts: paginationOptsValidator,
},
handler: async (ctx, { admin, paginationOpts }) => {
const user = await currentUser(ctx, {})
if (!user) return null

const reports = await ctx.db
.query("reports")
.withIndex("by_user", (q) => q.eq("userId", user?._id))
.filter((q) =>
q.or(
q.eq(q.field("status"), "ready"),
q.eq(q.field("status"), "processing")
)
)
.order("desc")
.paginate(paginationOpts)
const reportToReturn = reports.map((report) => {
const { cost, recordingUrl, ...reportContent } = report
return reportContent
})
},
})
export const getPaginatedReports = query({
args: {
admin: v.optional(v.boolean()),
paginationOpts: paginationOptsValidator,
},
handler: async (ctx, { admin, paginationOpts }) => {
const user = await currentUser(ctx, {})
if (!user) return null

const reports = await ctx.db
.query("reports")
.withIndex("by_user", (q) => q.eq("userId", user?._id))
.filter((q) =>
q.or(
q.eq(q.field("status"), "ready"),
q.eq(q.field("status"), "processing")
)
)
.order("desc")
.paginate(paginationOpts)
const reportToReturn = reports.map((report) => {
const { cost, recordingUrl, ...reportContent } = report
return reportContent
})
},
})
Any ideas? Thanks in advance
No description
4 Replies
Prince
PrinceOP8mo ago
the error on .map():
No description
ballingt
ballingt8mo ago
Try reports.page
Prince
PrinceOP8mo ago
ah, I am an idiot thank you skimmed the docs but it is very clearly explained there
ballingt
ballingt8mo ago
we might be able to make that type display better, it's annoying it says PaginationResult<...> instead of {page: ..., ...}

Did you find this page helpful?