UNPKG

@dwp/govuk-casa

Version:

A framework for building GOVUK Collect-And-Submit-Applications

33 lines 1.65 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const logger_js_1 = __importDefault(require("../../../lib/logger.js")); const utils_js_1 = require("./utils.js"); const log = (0, logger_js_1.default)("lib:internal-plugin:edit-snapshot:pre-steer-hook"); exports.default = (req, res, next) => { if (req.query.editcancel && (0, utils_js_1.snapshotExists)(req)) { log.debug("Edit workflow was actively canceled. Snapshot will be recovered."); (0, utils_js_1.recoverSnapshot)(log, req); return req.session.save(next); } if (!req.casa.editMode && (0, utils_js_1.snapshotExists)(req)) { log.debug("Edit workflow passively canceled. Snapshot will be recovered."); (0, utils_js_1.recoverSnapshot)(log, req); return req.session.save(next); } if (req.casa.editMode && (0, utils_js_1.reachedEditOrigin)(log, req)) { log.trace(`Editing workflow has reached editorigin. Purge MAY be carried out in poststeer hook on context '${req.casa.journeyContext.identity.id}'.`); // eslint-disable-next-line security/detect-object-injection req.casa[utils_js_1.FLAG_FOR_PURGING] = true; return next(); } if (req.casa.editMode && !(0, utils_js_1.snapshotExists)(req)) { log.debug("Editing workflow has just started. Will create snapshot."); (0, utils_js_1.createSnapshot)(log, req); return req.session.save(next); } next(); }; //# sourceMappingURL=pre-steer-hook.js.map