diff --git a/apps/api/src/controllers/track.controller.ts b/apps/api/src/controllers/track.controller.ts index 12e38a69..e1e1161d 100644 --- a/apps/api/src/controllers/track.controller.ts +++ b/apps/api/src/controllers/track.controller.ts @@ -343,21 +343,29 @@ async function handleGroup( const { id, type, name, properties = {} } = payload; const profileId = payload.profileId ?? context.deviceId; - await Promise.all([ + const promises: Promise[] = []; + promises.push( groupBuffer.add({ id, projectId: context.projectId, type, name, properties, - }), - upsertProfile({ - id: profileId, - projectId: context.projectId, - isExternal: !!(payload.profileId ?? context.identity?.profileId), - groups: [id], - }), - ]); + }) + ); + + if (profileId) { + promises.push( + upsertProfile({ + id: String(profileId), + projectId: context.projectId, + isExternal: !!(payload.profileId ?? context.identity?.profileId), + groups: [id], + }) + ); + } + + await Promise.all(promises); } export async function handler(