Last active
October 10, 2022 02:40
-
-
Save leegilmorecode/2b94804d5601de87f60e050d28bbae72 to your computer and use it in GitHub Desktop.
create-order.ts sample
This file contains hidden or 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
// we get the order details from the event | |
const order: OrderCreated = JSON.parse(body); | |
// we generate an idempotency key | |
const idempotencyKey: string = uuidV5( | |
JSON.stringify(order), | |
namespaces.orders | |
); | |
// create the detail of the event | |
const orderEvent: OrderCreatedEvent = { | |
metadata: { | |
schemaVersion: '2.0.0', | |
idempotencyKey, | |
correlationId, | |
causationId: correlationId, | |
}, | |
data: { | |
...order, | |
}, | |
}; | |
// validate the event against the event schema | |
validate( | |
orderEvent, | |
schema, | |
'OrderCreated', | |
'OrderCreated#/components/schemas/OrderCreated' | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment