This example shows a simple POC for implementing subscriptions using event sourcing.
- The data model
- Create a subscription
- Cancel a subscription
- Save a snapshot for querying
- A test script
*** Aggregates
[
{
"id": "cjyhpzwdr0000nirty2oabq4u",
"createdAt": "2019-07-24T20:48:27.565Z",
"type": "subscription",
"events": [
{
"id": "cjyhpzwe00001nirtywhfuup3",
"createdAt": "2019-07-24T20:48:27.576Z",
"type": "create",
"data": "{\"planId\":\"monthly\",\"startedAt\":\"2019-07-24T20:48:27.456Z\",\"expiresAt\":\"2019-08-23T20:48:27.456Z\"}"
},
{
"id": "cjyhpzwei0003nirto8rbs1ik",
"createdAt": "2019-07-24T20:48:27.594Z",
"type": "cancel",
"data": "{\"cancelledAt\":\"2019-08-03T20:48:27.591Z\"}"
}
]
}
]
*** Latest snapshot
{
id: 'cjyhpzwer0004nirt9dblp5fo',
createdAt: '2019-07-24T20:48:27.603Z',
aggregateId: 'cjyhpzwdr0000nirty2oabq4u',
startedAt: '2019-07-24T20:48:27.456Z',
planId: 'monthly',
cancelledAt: '2019-08-03T20:48:27.591Z',
expiresAt: '2019-08-23T20:48:27.456Z'
}