Implement posthog
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import { get } from "radash";
|
||||
import { createActivityContent } from "~~/server/utils/create-content";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await validateHookdeck(event);
|
||||
|
||||
const posthog = event.context.posthog;
|
||||
|
||||
const body = await readBody(event);
|
||||
const db = useDrizzle();
|
||||
|
||||
@@ -40,11 +43,33 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
await strava!(`activities/${body.object_id}`, {
|
||||
method: "PUT",
|
||||
body: stravaRequestBody,
|
||||
body: {
|
||||
name: stravaRequestBody.name,
|
||||
description: stravaRequestBody.description,
|
||||
},
|
||||
}).catch((error) => {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
message: `Strava API: ${error.message}`,
|
||||
});
|
||||
});
|
||||
|
||||
posthog.identify({
|
||||
distinctId: String(user.id),
|
||||
properties: {
|
||||
name: user.name,
|
||||
country: user.country,
|
||||
},
|
||||
});
|
||||
|
||||
posthog.capture({
|
||||
distinctId: String(user.id),
|
||||
event: "content generated",
|
||||
properties: {
|
||||
activity: currentActivity.id,
|
||||
activityType: get(currentActivity, "sport_type", "unknown"),
|
||||
highlight: stravaRequestBody.meta.highlight,
|
||||
tone: stravaRequestBody.meta.tone,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,8 @@ import { eq } from "drizzle-orm";
|
||||
export default defineEventHandler(async (event) => {
|
||||
await validateHookdeck(event);
|
||||
|
||||
const posthog = event.context.posthog;
|
||||
|
||||
const body = await readBody(event);
|
||||
const db = useDrizzle();
|
||||
|
||||
@@ -11,9 +13,29 @@ export default defineEventHandler(async (event) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const user = await db.query.users.findFirst({
|
||||
where: (f, o) => o.eq(f.id, get(body, "object_id")),
|
||||
with: {
|
||||
preferences: true,
|
||||
},
|
||||
});
|
||||
|
||||
posthog.identify({
|
||||
distinctId: String(user!.id),
|
||||
properties: {
|
||||
name: user!.name,
|
||||
country: user!.country,
|
||||
},
|
||||
});
|
||||
|
||||
await db
|
||||
.delete(tables.users)
|
||||
.where(eq(tables.users.id, get(body, "object_id")));
|
||||
|
||||
posthog.capture({
|
||||
distinctId: get(body, "object_id"),
|
||||
event: "user deleted",
|
||||
});
|
||||
|
||||
sendNoContent(event);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user