Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
fix(gql): jobs query. validate limit and offset args
Browse files Browse the repository at this point in the history
  • Loading branch information
s-r-x committed Jun 11, 2021
1 parent caea5c8 commit 1a43a06
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/root/src/gql/data-sources/bull/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { Maybe } from '../../../typings/utils';
import redisInfo from 'redis-info';
import { DataTextSearcher } from './data-text-search';
import isNil from 'lodash/isNil';

type Config = {
textSearchScanCount?: number;
Expand All @@ -39,6 +40,8 @@ export enum ErrorEnum {
QUEUE_NOT_FOUND = 'Queue not found',
JOB_NOT_FOUND = 'Job not found',
DATA_SEARCH_STATUS_REQUIRED = 'Job status is required for data search',
BAD_OFFSET = 'Offset should be >= 0',
BAD_LIMIT = 'Limit should be >= 1',
}
export class BullDataSource extends DataSource {
private _queuesMap: Map<string, BullQueue> = new Map();
Expand Down Expand Up @@ -91,6 +94,12 @@ export class BullDataSource extends DataSource {
status?: JobStatus;
queue: string;
}) {
if (!isNil(offset) && offset < 0) {
this._throwInternalError(ErrorEnum.BAD_OFFSET);
}
if (!isNil(limit) && limit < 1) {
this._throwInternalError(ErrorEnum.BAD_LIMIT);
}
const bullQueue = this.getQueueByName(queue, true) as BullQueue;
if (ids) {
const jobs = await Promise.all(ids.map(id => bullQueue.getJob(id)));
Expand Down

0 comments on commit 1a43a06

Please sign in to comment.