This commit is contained in:
Carl-Gerhard Lindesvärd
2026-03-11 21:27:41 +01:00
parent e6d0b6544b
commit fa78e63bc8
12 changed files with 178 additions and 108 deletions

View File

@@ -14,6 +14,7 @@ import {
} from '@openpanel/queue';
import { getRedisCache } from '@openpanel/redis';
import {
type IAssignGroupPayload,
type IDecrementPayload,
type IGroupPayload,
type IIdentifyPayload,
@@ -341,31 +342,29 @@ async function handleGroup(
context: TrackContext
): Promise<void> {
const { id, type, name, properties = {} } = payload;
await groupBuffer.add({
id,
projectId: context.projectId,
type,
name,
properties,
});
}
async function handleAssignGroup(
payload: IAssignGroupPayload,
context: TrackContext
): Promise<void> {
const profileId = payload.profileId ?? context.deviceId;
const promises: Promise<unknown>[] = [];
promises.push(
groupBuffer.add({
id,
projectId: context.projectId,
type,
name,
properties,
})
);
if (profileId) {
promises.push(
upsertProfile({
id: String(profileId),
projectId: context.projectId,
isExternal: !!(payload.profileId ?? context.identity?.profileId),
groups: [id],
})
);
if (!profileId) {
return;
}
await Promise.all(promises);
await upsertProfile({
id: String(profileId),
projectId: context.projectId,
isExternal: !!payload.profileId,
groups: payload.groupIds,
});
}
export async function handler(
@@ -419,6 +418,9 @@ export async function handler(
case 'group':
await handleGroup(validatedBody.payload, context);
break;
case 'assign_group':
await handleAssignGroup(validatedBody.payload, context);
break;
default:
return reply.status(400).send({
status: 400,