Nishil Faldu
Nishil Faldu
CCConvex Community
Created by Nishil Faldu on 2/8/2025 in #support-community
Combination of .paginate and getPage question
const following = await ctx.db
.query('follows')
.withIndex('uniqueRelationship', (q) => q.eq('followerType', 'user')
.eq('followerId', ctx.user._id))
.paginate(paginationOpts);

if (following.page.length === 0) {
return {
page: [],
isDone: true,
continueCursor: undefined
};
}

const discussions = [];
for (const follow of following.page) {
const { page: discussionsPage } = await getPage(ctx,
{
table: 'discussions',
index: 'byUserOrgUniversity',
startIndexKey: [follow.followeeId],
endIndexKey: [follow.followeeId],
absoluteMaxRows: 10
});

discussions.push(...discussionsPage);
}
const following = await ctx.db
.query('follows')
.withIndex('uniqueRelationship', (q) => q.eq('followerType', 'user')
.eq('followerId', ctx.user._id))
.paginate(paginationOpts);

if (following.page.length === 0) {
return {
page: [],
isDone: true,
continueCursor: undefined
};
}

const discussions = [];
for (const follow of following.page) {
const { page: discussionsPage } = await getPage(ctx,
{
table: 'discussions',
index: 'byUserOrgUniversity',
startIndexKey: [follow.followeeId],
endIndexKey: [follow.followeeId],
absoluteMaxRows: 10
});

discussions.push(...discussionsPage);
}
I have this piece of code where in I want to return discussion posts from a users' following - but I would want to return all pages of posts from a particular user and then move on to the next user i am following...how can that be done? I tried to read the blog and docs too, but I could not wrap my head around to actually doing it
3 replies
CCConvex Community
Created by Nishil Faldu on 2/1/2025 in #support-community
Table Aggregrate Component Question
likes: defineTable({
userId: v.id('users'),
parentId: v.union(
v.id('posts'),
v.id('discussions'),
v.id('events'),
v.id('comments')
),
parentType: v.union(
v.literal('posts'),
v.literal('discussions'),
v.literal('events'),
v.literal('comments')
),

universityId: v.id('universities'),
})
.index('byParentIdAndUserId', ['parentId', 'userId'])
.index('byParentId', ['parentId']),
likes: defineTable({
userId: v.id('users'),
parentId: v.union(
v.id('posts'),
v.id('discussions'),
v.id('events'),
v.id('comments')
),
parentType: v.union(
v.literal('posts'),
v.literal('discussions'),
v.literal('events'),
v.literal('comments')
),

universityId: v.id('universities'),
})
.index('byParentIdAndUserId', ['parentId', 'userId'])
.index('byParentId', ['parentId']),
How would I generally write the TableAggregrate component for this? I am very confused and I can't seem to understand or figure it out. My goal is to count number of likes from an input of university id
16 replies
CCConvex Community
Created by Nishil Faldu on 1/30/2025 in #support-community
Lets say there are a lot of apps...
Lets assume that there are 5 apps with their individual databases on Convex. Now lets say later in the future I realize that I want to suggested recommendations on one app based on the data in other apps - would that be possible with convex? (5 apps would have 5 databases as I think it would be scalable for each of those individual services/apps). Also is it possible to share auth data amongst all 5 apps?
19 replies
CCConvex Community
Created by Nishil Faldu on 7/13/2024 in #support-community
.order vs manual sorting using _creationTime
so I am getting the expected results using manual sorting using _creationTime and not using .order("desc")? any clue why?
2 replies
CCConvex Community
Created by Nishil Faldu on 4/1/2024 in #support-community
Lost Typings on the client side (Next + Convex Project)
No description
17 replies
CCConvex Community
Created by Nishil Faldu on 3/20/2024 in #support-community
Action, Internal, Query and Mutation
export const storeStripeCustomerId = action({
args: {},
handler: async ctx => {
const stripe = new Stripe(
process.env.STRIPE_SECRET_KEY! ?? "",
{
apiVersion: "2023-10-16",
typescript: true,
}
);

const user = await ctx.runQuery(internal.users.getUserInternalQuery);
if (!user) {
throw new Error("User not found");
}
console.log("bla bla bla run now");
console.log(user, "user");

if(!user.stripeId) {
const customer = await stripe.customers.create({
email: user.email,
name: user.firstName + " " + user.lastName,
});

console.log("let me create one");

// await ctx.db.patch(user._id, {
// stripeId: customer.id,
// });
const stripeId : string
= await ctx.runMutation(internal.users.storeStripeId, { userId: user._id, stripeId: customer.id });

return stripeId;
}

return user.stripeId;
},
});
export const storeStripeCustomerId = action({
args: {},
handler: async ctx => {
const stripe = new Stripe(
process.env.STRIPE_SECRET_KEY! ?? "",
{
apiVersion: "2023-10-16",
typescript: true,
}
);

const user = await ctx.runQuery(internal.users.getUserInternalQuery);
if (!user) {
throw new Error("User not found");
}
console.log("bla bla bla run now");
console.log(user, "user");

if(!user.stripeId) {
const customer = await stripe.customers.create({
email: user.email,
name: user.firstName + " " + user.lastName,
});

console.log("let me create one");

// await ctx.db.patch(user._id, {
// stripeId: customer.id,
// });
const stripeId : string
= await ctx.runMutation(internal.users.storeStripeId, { userId: user._id, stripeId: customer.id });

return stripeId;
}

return user.stripeId;
},
});
the hook (for some reason), given below runs twice and in the process it generates 2 stripe customers which should ideally be impossible considering I check for if(!user.stripeId) this which surprisingly is true both the times which means stripeId is "". Surprisingly when I check the logs on convex dashboard, the log statement runMutation prints first and before the log statement of storeStripeCustomerId. Would really appreciate someone's help here as I am very confused!
4 replies