UNPKG

agenda-admin

Version:
56 lines (55 loc) 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildGetJobsQuery = void 0; const build_job_query_1 = require("./build-job-query"); const buildGetJobsQuery = (requestQuery) => { const { query, statusFilter, sortBy, sortType } = (0, build_job_query_1.buildJobQuery)(requestQuery); return [ { $match: query, }, { $sort: { [sortBy]: sortType }, }, { $project: { job: '$$ROOT', status: { running: { $and: ['$lastRunAt', { $gt: ['$lastRunAt', '$lastFinishedAt'] }], }, scheduled: { $and: ['$nextRunAt', { $gte: ['$nextRunAt', new Date()] }], }, queued: { $and: [ '$nextRunAt', { $gte: [new Date(), '$nextRunAt'] }, { $gte: ['$nextRunAt', '$lastFinishedAt'] }, ], }, completed: { $and: [ '$lastFinishedAt', { $gt: ['$lastFinishedAt', '$failedAt'] }, ], }, failed: { $and: [ '$lastFinishedAt', '$failedAt', { $eq: ['$lastFinishedAt', '$failedAt'] }, ], }, repeating: { $and: ['$repeatInterval', { $ne: ['$repeatInterval', null] }], }, }, }, }, { $match: statusFilter, }, ]; }; exports.buildGetJobsQuery = buildGetJobsQuery;