Add random PIS return

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface
2023-05-25 21:27:37 +01:00
parent a12951fe4f
commit b590eb6cf5
4 changed files with 27 additions and 4 deletions

View File

@@ -28,7 +28,7 @@ async function findPisByOrigDest(start,end) {
}
async function findPisByCode(code) {
log.out(`pisServices.findPisByCode: Searching for PIS code: ${code}`);
log.out(`pisServices.findPisByCode: Searching for PIS code: ${code}`, 'dbug');
const cleanCode = clean.removeNonNumeric(code);
const query = {
'code': parseInt(cleanCode)
@@ -37,9 +37,21 @@ async function findPisByCode(code) {
return await search;
}
async function findRandom() {
log.out('pisServices.findRandom: Finding five random PIS Codes', 'dbug');
const query = {
$sample: {
size: 5
}
};
const results = db.query('pis', query);
return results;
}
// Hopefully at some point, I will also be able to implement a find PIS code by headcode option.
module.exports = {
findPisByOrigDest,
findPisByCode
findPisByCode,
findRandom
};