rochel3
rochel3
CCConvex Community
Created by rochel3 on 6/4/2024 in #support-community
Get Price highest to lowest with pagination query
I am currently designing a filter which can take in " sorted by " and apply it to a convex query, there are 4 options, Sorted by Newest (newest to oldest) Oldest (oldest to newest) Price (highest to lowest) Price (lowest to highest) There are also additional filters such as categoryId of the products and min / max prices The paginated query looks like this:
export const getPostList = query({
args: {
paginationOpts: paginationOptsValidator,
categoryId: v.optional(v.id("categories")),
title: v.optional(v.string()),
sortedBy: v.string(),
min: v.optional(v.number()),
max: v.optional(v.number()),
},
handler: async (ctx, args) => {
var res = ctx.db.query("post");

if (args.categoryId) {
var res = res.filter((q) => q.eq(q.field("categoryId"), args.categoryId));
}

if (args.title) {
var res = res.filter((q) => q.eq(q.field("title"), args.title));
}

if (args.min) {
var res = res.filter((q) => q.gte(q.field("pricing"), args.min!));
}

if (args.max) {
var res = res.filter((q) => q.lte(q.field("pricing"), args.max!));
}

if (args.sortedBy === "oldest") {
return await res.order("asc").paginate(args.paginationOpts);
} else if (args.sortedBy === "desc") {
const x = await res.paginate(args.paginationOpts);
const ret = x.page.sort((a, b) => b.pricing - a.pricing);
return x;
} else if (args.sortedBy === "asc") {
const x = await res.paginate(args.paginationOpts);
const ret = x.page.sort((a, b) => a.pricing - b.pricing);
return x;
} else {
return await res.order("desc").paginate(args.paginationOpts);
}
},
});
export const getPostList = query({
args: {
paginationOpts: paginationOptsValidator,
categoryId: v.optional(v.id("categories")),
title: v.optional(v.string()),
sortedBy: v.string(),
min: v.optional(v.number()),
max: v.optional(v.number()),
},
handler: async (ctx, args) => {
var res = ctx.db.query("post");

if (args.categoryId) {
var res = res.filter((q) => q.eq(q.field("categoryId"), args.categoryId));
}

if (args.title) {
var res = res.filter((q) => q.eq(q.field("title"), args.title));
}

if (args.min) {
var res = res.filter((q) => q.gte(q.field("pricing"), args.min!));
}

if (args.max) {
var res = res.filter((q) => q.lte(q.field("pricing"), args.max!));
}

if (args.sortedBy === "oldest") {
return await res.order("asc").paginate(args.paginationOpts);
} else if (args.sortedBy === "desc") {
const x = await res.paginate(args.paginationOpts);
const ret = x.page.sort((a, b) => b.pricing - a.pricing);
return x;
} else if (args.sortedBy === "asc") {
const x = await res.paginate(args.paginationOpts);
const ret = x.page.sort((a, b) => a.pricing - b.pricing);
return x;
} else {
return await res.order("desc").paginate(args.paginationOpts);
}
},
});
"desc" meaning from Price highest to lowest "asc" meaning from Price lowest to highest However this does not provide me with the intended result as it only sorts after the pagination. I have tried using withIndex("by_pricing") but it gives an error saying .withIndex is not a function. Please help! Thanks
17 replies
CCConvex Community
Created by rochel3 on 5/31/2024 in #support-community
pyTelegrambotAPI with convex, cant get image to be sent sometimes
I have a telegram bot that disperses information on seating areas of schools, when queried, it will send an image. I store the images in convex file system and retrieve the images using the following function export const getImg = query({ args: { photoId: v.string() }, handler: async (ctx, { photoId }) => { return await ctx.storage.getUrl(photoId); }, }); However, i would occasionally get the error "A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: wrong file identifier/HTTP URL specified" for some schools and will only be fixed when i reupload the image and replace the fileId of the school record a school record looks like this: mrt_schools: defineTable({ school_name: v.string(), seating_sector: v.string(), }).index("by_school_name", ["school_name"]) where seating_sector is the fileId in storage and school_name is the name of the school How can i prevent this? It doesnt seem to happen on my Nextjs project but only this project It happens to random schools as well, even after testing some schools, it would throw this error on the tested schools that intially sent the image of the seating sector
13 replies
CCConvex Community
Created by rochel3 on 3/20/2024 in #support-community
Convex import causes telegram bot to not work.
pyTelegramApi does not allow me to work. Error given is: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.telegram.org:443 DEBUG:urllib3.connectionpool:https://api.telegram.org:443 "GET /bot6583121108:AAEx-N1Qu7g80kyxGiC-5qgkEG1SsKt87q0/getMe HTTP/1.1" 200 195 DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.telegram.org:443 Everything works if i dont have the from Convex import ConvexClient line :/ but when i include it, it gives this error
15 replies
CCConvex Community
Created by rochel3 on 3/20/2024 in #support-community
Getting specific column results
Hi guys, how do i return a list of objects containing specified columns instead of the whole record itself? Thanks guys!
5 replies