IamtheFuture
IamtheFuture
CCConvex Community
Created by IamtheFuture on 9/6/2024 in #support-community
Batch Patch Error
why is this throwing error
export const updateFeaturedProducts = mutation({
args: {
products: v.array(v.id("products")),
},
handler: async (ctx, args) => {
await checkIfAdmin(ctx);

// Filter out any undefined values
const validProducts = args.products.filter((id) => id !== undefined);

return Promise.all(
validProducts.map(async (id) => {
console.log(id);
await ctx.db.patch(id, { isFeatured: false });
}),
);,
);
},
});
export const updateFeaturedProducts = mutation({
args: {
products: v.array(v.id("products")),
},
handler: async (ctx, args) => {
await checkIfAdmin(ctx);

// Filter out any undefined values
const validProducts = args.products.filter((id) => id !== undefined);

return Promise.all(
validProducts.map(async (id) => {
console.log(id);
await ctx.db.patch(id, { isFeatured: false });
}),
);,
);
},
});
error: [CONVEX M(products:updateFeaturedProducts)] [Request ID: 583339ec3107f9e8] Server Error Uncaught Error: undefined is not a valid Convex value (present at path [0] in original object ["undefined"]). To learn about Convex's supported types, see https://docs.convex.dev/using/types. at convexToJsonInternal (../../node_modules/convex/src/values/value.ts:287:6)
3 replies
CCConvex Community
Created by IamtheFuture on 9/1/2024 in #support-community
Query Speed Up
please how do I optimise this query, I feel like am not doing it the right way
export const list = query({
args: {},
handler: async (ctx) => {
await getUserId(ctx);

const users = await ctx.db.query("customers").collect();

const usersWithDownline = await Promise.all(
users.map(async (user) => {
const userDetail = await ctx.db.get(user.userId);
const downline = await ctx.db
.query("downlines")
.withIndex("customer", (q) => q.eq("leader", user._id))
.collect();

const downlineWithFollower = await Promise.all(
downline.map(async (dl) => {
const follower = await ctx.db.get(dl.follower);
const followerDetails = await ctx.db.get(follower!.userId);
return {
...dl,
followers: {
userId: followerDetails!._id,
id: follower!._id,
email: followerDetails!.email,
firstName: follower!.firstName,
lastName: follower!.lastName,
},
};
}),
);
const upline = await ctx.db.get(user.upline ?? "");
const uplineDetails = await ctx.db.get(upline!.userId);

const products =
user.products?.map(async (productId: Id<"products">) => {
return await ctx.db.get(productId);
}) ?? [];

return {
...user,
user: userDetail,
productsList: await Promise.all(products),
downline: downlineWithFollower,
upline: upline
? {
id: upline._id,
email: uplineDetails!.email,
name: uplineDetails!.name,
firstName: upline.firstName,
lastName: upline.lastName,
}
: null,
};
}),
);
return usersWithDownline;
},
});
export const list = query({
args: {},
handler: async (ctx) => {
await getUserId(ctx);

const users = await ctx.db.query("customers").collect();

const usersWithDownline = await Promise.all(
users.map(async (user) => {
const userDetail = await ctx.db.get(user.userId);
const downline = await ctx.db
.query("downlines")
.withIndex("customer", (q) => q.eq("leader", user._id))
.collect();

const downlineWithFollower = await Promise.all(
downline.map(async (dl) => {
const follower = await ctx.db.get(dl.follower);
const followerDetails = await ctx.db.get(follower!.userId);
return {
...dl,
followers: {
userId: followerDetails!._id,
id: follower!._id,
email: followerDetails!.email,
firstName: follower!.firstName,
lastName: follower!.lastName,
},
};
}),
);
const upline = await ctx.db.get(user.upline ?? "");
const uplineDetails = await ctx.db.get(upline!.userId);

const products =
user.products?.map(async (productId: Id<"products">) => {
return await ctx.db.get(productId);
}) ?? [];

return {
...user,
user: userDetail,
productsList: await Promise.all(products),
downline: downlineWithFollower,
upline: upline
? {
id: upline._id,
email: uplineDetails!.email,
name: uplineDetails!.name,
firstName: upline.firstName,
lastName: upline.lastName,
}
: null,
};
}),
);
return usersWithDownline;
},
});
7 replies
CCConvex Community
Created by IamtheFuture on 8/28/2024 in #support-community
Nextjs Api auth header from external app
Hi everyone, I have a situation I want to call some nextjs api endpoint from my react navtive app, but I don’t want to make the nextjs api endpoint open, I want it authenticated(like passing auth headers to the api call from my mobile app), please how do I do this kind of authentication with convex-auth since convex-lucia-auth is no longer mentained anymore. Thanks
11 replies