Skip to content

Instantly share code, notes, and snippets.

@leegilmorecode
Last active October 10, 2022 02:40
Show Gist options
  • Save leegilmorecode/2b94804d5601de87f60e050d28bbae72 to your computer and use it in GitHub Desktop.
Save leegilmorecode/2b94804d5601de87f60e050d28bbae72 to your computer and use it in GitHub Desktop.
create-order.ts sample
// 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