Last active
March 25, 2021 22:21
-
-
Save shaykav/1efcced329cc854feb2bdb29f5c724fc to your computer and use it in GitHub Desktop.
Handler for disconnect event type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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