DTP Base provides a scalable and secure Node.js application development harness ready for production service.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

24 lines
823 B

'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);
}
};
}