Skip to content

Instantly share code, notes, and snippets.

@shaykav
Last active March 25, 2021 22:21
Show Gist options
  • Save shaykav/1efcced329cc854feb2bdb29f5c724fc to your computer and use it in GitHub Desktop.
Save shaykav/1efcced329cc854feb2bdb29f5c724fc to your computer and use it in GitHub Desktop.
Handler for disconnect event type
if (eventType === 'DISCONNECT') {
// Get all subscribers
const subscriptions = mapper.query(Subscription, {
connectionId: equals(connectionId)
});
// Remove subscriptions
for await (const subscription of subscriptions) {
const sub = Object.assign(new Subscription(), {
id: `${connectionId}|${subscription.subscription.id}`
});
await mapper.delete(sub);
}
// Remove connection
const connection = Object.assign(new Connection(), { id: connectionId });
await mapper.delete(connection);
return {
statusCode: 200,
body: ''
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment