@grouparoo/core
Version:
The Grouparoo Core
46 lines (45 loc) • 1.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExportSendBatches = void 0;
const Destination_1 = require("../../models/Destination");
const Export_1 = require("../../models/Export");
const sequelize_1 = require("sequelize");
const Option_1 = require("../../models/Option");
const Mapping_1 = require("../../models/Mapping");
const clsTask_1 = require("../../classes/tasks/clsTask");
const apiData_1 = require("../../modules/apiData");
class ExportSendBatches extends clsTask_1.CLSTask {
constructor() {
super(...arguments);
this.name = "export:sendBatch";
this.description = "send the batch of exports to the destination";
this.frequency = 0;
this.queue = "exports";
this.inputs = {
destinationId: { required: true },
exportIds: { required: true, formatter: apiData_1.APIData.ensureArray },
};
}
async runWithinTransaction({ destinationId, exportIds, }) {
let _exports = [];
if (exportIds.length === 0)
return;
const destination = await Destination_1.Destination.scope(null).findOne({
where: { id: destinationId },
include: [Option_1.Option, Mapping_1.Mapping],
});
if (!destination)
return;
_exports = await Export_1.Export.findAll({
where: {
destinationId,
state: "pending",
id: { [sequelize_1.Op.in]: exportIds },
},
});
if (_exports.length === 0)
return;
await destination.sendExports(_exports);
}
}
exports.ExportSendBatches = ExportSendBatches;