UNPKG

lml-main

Version:

This is now a mono repository published into many standalone packages.

59 lines 2.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const redux_observable_1 = require("redux-observable"); const actions_1 = require("../../couriers/actions"); const selectors_1 = require("../../couriers/selectors"); const actions_2 = require("../../frequencies/actions"); const selectors_2 = require("../../frequencies/selectors"); const cosmo_redux_api_1 = require("@lml/cosmo-redux-api"); /** * Reload all couriers... * * - when courier status is changed * - when courier vehicles are changed * - when selected frequencies are changed * - when a courier is moved between frequencies * * Please note that frequencies has its own epic called handle-frequencies-change * which also triggers the loadAllCouriers actions when the frequencies are changed * * @param action$ * @param store */ exports.reloadCouriersByStatus = (action$, store) => action$.ofType(actions_2.SET_SELECTED_FREQUENCIES, actions_2.SET_SELECTED_FREQUENCY_TYPE, actions_2.SET_SELECTED_FREQUENCY_IS_ACTIVE, actions_2.SET_FREQUENCIES_DATA, actions_1.TOGGLE_COURIER_VEHICLE, actions_1.SET_COURIER_STATUS, cosmo_redux_api_1.POST_COURIER_ACTION.SUCCESS, actions_1.RELOAD_COURIERS) .map(action => { const state = store.getState(); const statuses = selectors_1.getFilteredCourierStatus(state); const vehicles = selectors_1.getFilteredCourierVehicles(state); const labels = selectors_2.getSelectedFrequencyLabels(state); if (!statuses || !statuses.length) { return actions_1.fetchCouriersByStatusNoop('Courier status is required'); } if (!labels || !labels.length) { return actions_1.fetchCouriersByStatusNoop('Labels are required'); } if (!vehicles || !vehicles.length) { return actions_1.fetchCouriersByStatusNoop('Vehicles are required'); } return cosmo_redux_api_1.fetchCouriersByStatus(statuses, vehicles, labels); }); /** * Reload a particular courier... * * - when a job is allocated to the courier * * @param action$ * @param store */ exports.reloadCourierOnAllocation = (action$, store) => action$.ofType(cosmo_redux_api_1.POST_ALLOCATION.SUCCESS) .delay(2000) .mergeMap(action => [ cosmo_redux_api_1.fetchCourierById(action.args.courierRefId), // the status of the job will have changed // remember that job status is not stored in the main JobModel // for courierJobs it is stored in the JobStatusModel[] // which is inside the couriers state cosmo_redux_api_1.fetchCourierJobs(action.args.courierRefId), ]); exports.reloadCouriersEpics = redux_observable_1.combineEpics(exports.reloadCouriersByStatus, exports.reloadCourierOnAllocation); //# sourceMappingURL=reload-couriers.js.map