diff --git a/src/job/index.ts b/src/job/index.ts index 302cf9e..ffdd368 100644 --- a/src/job/index.ts +++ b/src/job/index.ts @@ -67,7 +67,7 @@ export interface JobAttributes */ data: T | any; - unique?: any; + uniqueQuery?: any; uniqueOpts?: { insertOnly: boolean; }; diff --git a/src/job/unique.ts b/src/job/unique.ts index 628ff3e..4fe9d73 100644 --- a/src/job/unique.ts +++ b/src/job/unique.ts @@ -1,15 +1,19 @@ +import { Filter } from 'mongodb'; import { Job } from '.'; -export type UniqueMethod = (unique: any, options?: { insertOnly: boolean }) => Job; +export type UniqueMethod = ( + filter: Filter, + options?: { insertOnly: boolean } +) => Job; /** * Data to ensure is unique for job to be created * @name Job#unique * @function - * @param unique mongo data query for unique + * @param filter mongo data query for unique * @param options unique options */ -export const unique: UniqueMethod = function (this: Job, unique, options?) { - this.attrs.unique = unique; +export const unique: UniqueMethod = function (this: Job, filter, options?) { + this.attrs.uniqueQuery = filter; this.attrs.uniqueOpts = options; return this; }; diff --git a/src/pulse/save-job.ts b/src/pulse/save-job.ts index 702f468..a64ed44 100644 --- a/src/pulse/save-job.ts +++ b/src/pulse/save-job.ts @@ -77,12 +77,12 @@ export const saveJob: SaveJobMethod = async function (this: Pulse, job) { // Grab information needed to save job but that we don't want to persist in MongoDB const id = job.attrs._id; - const { unique, uniqueOpts } = job.attrs; + const { uniqueQuery: unique, uniqueOpts } = job.attrs; // Store job as JSON and remove props we don't want to store from object const props = job.toJSON(); delete props._id; - delete props.unique; + delete props.uniqueQuery; delete props.uniqueOpts; // Store name of pulse queue as last modifier in job data @@ -143,7 +143,7 @@ export const saveJob: SaveJobMethod = async function (this: Pulse, job) { if (unique) { // If we want the job to be unique, then we can upsert based on the 'unique' query object that was passed in - const query = job.attrs.unique; + const query = job.attrs.uniqueQuery; query.name = props.name; if (uniqueOpts?.insertOnly) { // @ts-expect-error