gwilliamnn
gwilliamnn
CCConvex Community
Created by gwilliamnn on 8/10/2023 in #support-community
indexSearch with "match"
Yes.
8 replies
CCConvex Community
Created by gwilliamnn on 8/10/2023 in #support-community
indexSearch with "match"
how make this external soluction?
8 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Seed data with relations
like, I can't find this on documentation...
15 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Seed data with relations
internalMutation in general
15 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Seed data with relations
I'm kinda confuse with this new ways to do
15 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Seed data with relations
Nice! Could you tell me more example when I should use the internalMutation or actions?
15 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Understanding the pricing
GOTCHA
11 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Bug after change function
WORK SMOOTH NOW
21 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Bug after change function
Sorrry ... miss file, I had 2 routes for webhook,
21 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Bug after change function
FOUND THE ERROR..
21 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Bug after change function
:=)
21 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Bug after change function
SORRY!
21 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Bug after change function
profiles.ts
import { query, mutation } from "./_generated/server"
import { v } from "convex/values"

export const getAll = query({
args: {},
handler: async (ctx) => {
return await ctx.db.query("profiles").collect()
},
})

export const getByUserId = query({
args: {
userId: v.string(),
},
handler: async (ctx, { userId }) => {
return await ctx.db
.query("profiles")
.withIndex("byUserId", (q) => q.eq("userId", userId))
.first()
},
})

export const create = mutation({
args: {
userId: v.string(),
name: v.string(),
email: v.string(),
avatarUrl: v.optional(v.string()),
},
handler: async (ctx, { userId, name, email, avatarUrl }) => {
return await ctx.db.insert("profiles", {
userId,
name,
email,
avatarUrl,
})
},
})

export const update = mutation({
args: {
userId: v.string(),
name: v.string(),
email: v.string(),
avatarUrl: v.optional(v.string()),
},
handler: async (ctx, { userId, name, email, avatarUrl }) => {
const profiles = await ctx.db
.query("profiles")
.withIndex("byUserId", (q) => q.eq("userId", userId))
.first()

if (!profiles) {
return await ctx.db.insert("profiles", {
userId,
name,
email,
avatarUrl,
})
}

return await ctx.db.patch(profiles._id, {
userId,
name,
email,
avatarUrl,
})
},
})

export const remove = mutation({
args: {
userId: v.string(),
},
handler: async (ctx, { userId }) => {
const profiles = await ctx.db
.query("profiles")
.withIndex("byUserId", (q) => q.eq("userId", userId))
.first()

if (!profiles) {
return
}

return await ctx.db.delete(profiles._id)
},
})
import { query, mutation } from "./_generated/server"
import { v } from "convex/values"

export const getAll = query({
args: {},
handler: async (ctx) => {
return await ctx.db.query("profiles").collect()
},
})

export const getByUserId = query({
args: {
userId: v.string(),
},
handler: async (ctx, { userId }) => {
return await ctx.db
.query("profiles")
.withIndex("byUserId", (q) => q.eq("userId", userId))
.first()
},
})

export const create = mutation({
args: {
userId: v.string(),
name: v.string(),
email: v.string(),
avatarUrl: v.optional(v.string()),
},
handler: async (ctx, { userId, name, email, avatarUrl }) => {
return await ctx.db.insert("profiles", {
userId,
name,
email,
avatarUrl,
})
},
})

export const update = mutation({
args: {
userId: v.string(),
name: v.string(),
email: v.string(),
avatarUrl: v.optional(v.string()),
},
handler: async (ctx, { userId, name, email, avatarUrl }) => {
const profiles = await ctx.db
.query("profiles")
.withIndex("byUserId", (q) => q.eq("userId", userId))
.first()

if (!profiles) {
return await ctx.db.insert("profiles", {
userId,
name,
email,
avatarUrl,
})
}

return await ctx.db.patch(profiles._id, {
userId,
name,
email,
avatarUrl,
})
},
})

export const remove = mutation({
args: {
userId: v.string(),
},
handler: async (ctx, { userId }) => {
const profiles = await ctx.db
.query("profiles")
.withIndex("byUserId", (q) => q.eq("userId", userId))
.first()

if (!profiles) {
return
}

return await ctx.db.delete(profiles._id)
},
})
21 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Bug after change function
route.ts
import { NextResponse } from "next/server"
import type { WebhookEvent } from "@clerk/clerk-sdk-node"
import { ConvexHttpClient } from "convex/browser"
import { api } from "@convex/_generated/api"

const client = new ConvexHttpClient(process.env.CONVEX_URL!)

export async function POST(req: Request) {
const body = (await req.json()) as WebhookEvent
console.log(body)
try {
if (body.type === "user.created") {
const name =
(body.data.first_name ? body.data.first_name : "No") +
" " +
(body.data.last_name ? body.data.last_name : "Name")

const user = await client.query(api.profiles.getByUserId, { userId: body.data.id })
if (!user) {
await client.mutation(api.profiles.create, {
userId: body.data.id,
name,
email: body.data.email_addresses[0].email_address,
avatarUrl: body.data.profile_image_url,
})

console.log("Profile created")
}
}

if (body.type === "user.updated") {
const name =
(body.data.first_name ? body.data.first_name : "No") +
" " +
(body.data.last_name ? body.data.last_name : "Name")

console.log(name)

await client.mutation(api.profiles.update, {
userId: body.data.id,
name,
email: body.data.email_addresses[0].email_address,
avatarUrl: body.data.profile_image_url,
})

console.log("Profile updated")
}

if (body.type === "user.deleted") {
const user = await client.query(api.profiles.getByUserId, {
userId: body.data.id as string,
})
if (user) {
await client.mutation(api.profiles.remove, { userId: body.data.id as string })
} else {
console.log("Profile deleted not found profiles")
}
}

if (body.type === "session.created") {
// Check if session user_id already has a profiles, if not create one
const user = await client.query(api.profiles.getByUserId, {
userId: body.data.user_id,
})

console.log(user)
if (!user) {
console.log("data", body.data, "\n body.object", body.object)
console.log("Profile not found")
}
}

return NextResponse.json({ status: "ok" })
} catch (e) {
console.log(e)
return NextResponse.json({ status: "error" })
}
}
import { NextResponse } from "next/server"
import type { WebhookEvent } from "@clerk/clerk-sdk-node"
import { ConvexHttpClient } from "convex/browser"
import { api } from "@convex/_generated/api"

const client = new ConvexHttpClient(process.env.CONVEX_URL!)

export async function POST(req: Request) {
const body = (await req.json()) as WebhookEvent
console.log(body)
try {
if (body.type === "user.created") {
const name =
(body.data.first_name ? body.data.first_name : "No") +
" " +
(body.data.last_name ? body.data.last_name : "Name")

const user = await client.query(api.profiles.getByUserId, { userId: body.data.id })
if (!user) {
await client.mutation(api.profiles.create, {
userId: body.data.id,
name,
email: body.data.email_addresses[0].email_address,
avatarUrl: body.data.profile_image_url,
})

console.log("Profile created")
}
}

if (body.type === "user.updated") {
const name =
(body.data.first_name ? body.data.first_name : "No") +
" " +
(body.data.last_name ? body.data.last_name : "Name")

console.log(name)

await client.mutation(api.profiles.update, {
userId: body.data.id,
name,
email: body.data.email_addresses[0].email_address,
avatarUrl: body.data.profile_image_url,
})

console.log("Profile updated")
}

if (body.type === "user.deleted") {
const user = await client.query(api.profiles.getByUserId, {
userId: body.data.id as string,
})
if (user) {
await client.mutation(api.profiles.remove, { userId: body.data.id as string })
} else {
console.log("Profile deleted not found profiles")
}
}

if (body.type === "session.created") {
// Check if session user_id already has a profiles, if not create one
const user = await client.query(api.profiles.getByUserId, {
userId: body.data.user_id,
})

console.log(user)
if (!user) {
console.log("data", body.data, "\n body.object", body.object)
console.log("Profile not found")
}
}

return NextResponse.json({ status: "ok" })
} catch (e) {
console.log(e)
return NextResponse.json({ status: "error" })
}
}
21 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Bug after change function
No description
21 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Bug after change function
just sec
21 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Bug after change function
yes
21 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Bug after change function
No description
21 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Bug after change function
no, the dev is working fine, the error happens when I make a query for update the profile
21 replies
CCConvex Community
Created by gwilliamnn on 8/7/2023 in #support-community
Bug after change function
i think this is kinda a cache...
21 replies