lml-main
Version:
This is now a mono repository published into many standalone packages.
54 lines • 2.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var redux_observable_1 = require("redux-observable");
var lodash_1 = require("lodash");
var cosmoui_1 = require("cosmoui");
var actions_1 = require("../actions");
exports.postAllocationSuccess = function (action$, store) {
return action$.ofType(actions_1.POST_ALLOCATION.SUCCESS, actions_1.POST_REALLOCATION.SUCCESS, actions_1.POST_DEALLOCATION.SUCCESS, actions_1.POST_TAG.SUCCESS, actions_1.POST_UNTAG.SUCCESS)
.mergeMap(function (action) {
var _a = action.result, job = _a.job, courier = _a.courier, type = _a.type;
var allocationLabel = "Job " + exports.getAllocationLabel(action.result.type) + " successfully";
var jobLabel = lodash_1.get(action.args, 'job.label.label', null);
var courierLabel = lodash_1.get(action.args, 'courier.label.label', null);
var setAllocation = actions_1.setAllocationById(action.result);
if (courierLabel && jobLabel && courierLabel !== jobLabel) {
return [
setAllocation,
cosmoui_1.notificationWarning(allocationLabel + ". JobLabel does not match courier."),
];
}
return [
setAllocation,
cosmoui_1.notificationSuccess(allocationLabel),
];
});
};
exports.postAllocationError = function (action$, store) {
return action$.ofType(actions_1.POST_ALLOCATION.ERROR)
.map(function (action) {
if (action.payload.status === 409) {
return cosmoui_1.notificationError('This job has already been allocated.');
}
var msg = lodash_1.get(action, 'error.message');
return cosmoui_1.notificationError("There was a problem creating the job. " + msg + ".");
});
};
exports.getAllocationLabel = function (allocationType) {
switch (allocationType) {
case 'ACTUAL':
return 'allocated';
case 'DEALLOCATION':
return 'deallocated';
case 'REALLOCATION':
return 'reallocated';
case 'TAG':
return 'tagged';
case 'UNTAG':
return 'untagged';
default:
throw new Error("Allocation type " + allocationType + " does not exist");
}
};
exports.postAllocationEpics = redux_observable_1.combineEpics(exports.postAllocationSuccess, exports.postAllocationError);
//# sourceMappingURL=post-allocation.js.map