'use strict'; import { SiteError } from '../../../lib/site-lib.js'; /* * This is a sample populator. It doesn't run. There is no sample service, etc. * This is simply the pattern you follow to declare a new ExpressJS parameter * populator and export it from your populators library. */ export function populateSampleParameter (controller) { return async function (req, res, next, sampleParameter) { const { sample: sampleService } = controller.dtp.services; try { res.locals.sample = await sampleService.getSample(sampleParameter); if (!res.locals.sample) { throw new SiteError(404, 'Sample not found'); } return next(); } catch (error) { controller.log.error('failed to populate sampleParameter', { sampleParamater, error }); return next(error); } }; }