UNPKG

event-driven

Version:

makes building event-driven-architecture easy

27 lines (26 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createBatchError = exports.BatchError = exports.createBatch = exports.Batch = void 0; const mongoose_1 = require("mongoose"); const BatchSchema = new mongoose_1.Schema({}, { strict: false }); exports.Batch = mongoose_1.model('Batch', BatchSchema); const createBatch = (data) => { const batch = new exports.Batch(Object.assign(Object.assign({}, data), { createdAt: new Date() })); return { batch, catchError: exports.createBatchError(batch._id), }; }; exports.createBatch = createBatch; const BatchErrorSchema = new mongoose_1.Schema({}, { timestamps: true, strict: false }); exports.BatchError = mongoose_1.model('BatchError', BatchErrorSchema); const createBatchError = (batchId) => (error) => { new exports.BatchError({ batchId, message: error.message ? JSON.stringify(error.message) : undefined, stack: error.stack ? JSON.stringify(error.stack) : undefined, isConfirmed: false, }).save(); return; }; exports.createBatchError = createBatchError;