Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions openapi3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ info:
paths:
/jobs:
get:
operationId: findJobs
operationId: getJobs
parameters:
- $ref: '#/components/parameters/resourceId'
- $ref: '#/components/parameters/version'
Expand All @@ -20,7 +20,7 @@ paths:
- $ref: '#/components/parameters/internalId'
- $ref: '#/components/parameters/domain'
- $ref: '#/components/parameters/shouldReturnAvailableActions'
summary: find jobs by criteria
summary: Get jobs by criteria
tags:
- jobs
responses:
Expand All @@ -34,7 +34,7 @@ paths:
$ref: '#/components/schemas/jobResponse'
post:
operationId: createJob
summary: Creates a new job
summary: Create a new job
tags:
- jobs
requestBody:
Expand Down Expand Up @@ -73,7 +73,7 @@ paths:
/jobs/find:
post:
operationId: findJobsByCriteria
summary: gets jobs by criteria
summary: Find jobs by criteria
tags:
- jobs
requestBody:
Expand All @@ -99,7 +99,7 @@ paths:
- $ref: '#/components/parameters/shouldReturnTasks'
- $ref: '#/components/parameters/shouldReturnAvailableActions'
operationId: getJob
summary: Get job by id
summary: Get job by ID
tags:
- jobs
responses:
Expand All @@ -117,7 +117,7 @@ paths:
$ref: '#/components/schemas/errorMessage'
put:
operationId: updateJob
summary: Updates a job
summary: Update a job
tags:
- jobs
requestBody:
Expand Down Expand Up @@ -179,7 +179,7 @@ paths:
parameters:
- $ref: '#/components/parameters/parameters'
summary: >-
find jobs by job's parameters, temporary only 1 level nested object is
Find jobs by job's parameters, temporary only 1 level nested object is
supported.
tags:
- jobs
Expand All @@ -197,7 +197,7 @@ paths:
- $ref: '#/components/parameters/jobId'
post:
operationId: isJobResettable
summary: checks if job is resettable
summary: Check if job is resettable
tags:
- jobs
responses:
Expand All @@ -212,7 +212,7 @@ paths:
- $ref: '#/components/parameters/jobId'
post:
operationId: resetJob
summary: reset a resettable job
summary: Reset a resettable job
tags:
- jobs
requestBody:
Expand Down Expand Up @@ -250,7 +250,7 @@ paths:
operationId: getTasks
tags:
- tasks
summary: Get all the tasks of a job
summary: Get all tasks of a job
responses:
'200':
description: Array of tasks
Expand Down Expand Up @@ -332,7 +332,7 @@ paths:
- tasks
put:
operationId: updateTask
summary: Update task by task Id
summary: Update task by task ID
requestBody:
required: true
content:
Expand Down Expand Up @@ -408,7 +408,7 @@ paths:
/tasks/find:
post:
operationId: findTasks
summary: return list of matching tasks
summary: Find matching tasks
tags:
- tasks
requestBody:
Expand Down Expand Up @@ -443,7 +443,7 @@ paths:
post:
operationId: startPendingTask
summary: >-
retrive the highest priority pending task and update its status to
Retrieve the highest priority pending task and update its status to
In-Progress
responses:
'200':
Expand All @@ -463,7 +463,7 @@ paths:
/tasks/findInactive:
post:
operationId: findInactiveTasks
summary: retrive list of inactive task ids
summary: Retrieve a list of inactive task ids
requestBody:
required: true
content:
Expand All @@ -488,7 +488,7 @@ paths:
/tasks/releaseInactive:
post:
operationId: releaseInactiveTasks
summary: release inactive tasks and return the ids of the released tasks
summary: Release inactive tasks and return the ids of the released tasks
requestBody:
required: true
content:
Expand All @@ -510,7 +510,7 @@ paths:
post:
operationId: updateExpiredStatus
summary: >-
update status of open jobs and tasks to "Expired" if their expiration
Update status of open jobs and tasks to "Expired" if their expiration
date has passed
responses:
'200':
Expand All @@ -528,7 +528,7 @@ paths:
- $ref: '#/components/parameters/jobId'
post:
operationId: abortTasksAndJob
summary: updates job and pending tasks statuses to "Aborted"
summary: Update job and pending tasks statuses to "Aborted"
responses:
'200':
description: aborted pending tasks
Expand Down Expand Up @@ -745,6 +745,9 @@ components:
shouldReturnAvailableActions:
type: boolean
default: false
shouldExcludeParameters:
type: boolean
default: false
findTaskRequest:
type: object
description: task find model
Expand Down
13 changes: 11 additions & 2 deletions src/DAL/repositories/jobRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,19 @@ export class JobRepository extends GeneralRepository<JobEntity> {
delete filter[key];
}
}
const queryBuilder = this.createQueryBuilder('job');

if (req.shouldExcludeParameters === true) {
queryBuilder.select(excludeColumns(JobEntity, ['parameters', 'tasks']).map((c) => `job.${c}`));
} else {
queryBuilder.select('job');
}

queryBuilder.where(filter);

if (req.shouldReturnTasks !== false) {
filter.relations = ['tasks'];
queryBuilder.leftJoinAndSelect('job.tasks', 'tasks');
}
const queryBuilder = this.createQueryBuilder('job').select().where(filter);
if ((req.types?.length ?? 0) > 0) {
queryBuilder.andWhere('job.type IN (:...types)', { types: req.types });
}
Expand Down
1 change: 1 addition & 0 deletions src/common/dataModels/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface IFindJobsByCriteriaBody {
types?: string[];
shouldReturnTasks?: boolean;
shouldReturnAvailableActions?: boolean;
shouldExcludeParameters?: boolean;
productType?: string;
fromDate?: string;
tillDate?: string;
Expand Down
29 changes: 29 additions & 0 deletions tests/integration/jobs/jobs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import {
import { getApp } from '../../../src/app';
import { FindJobsResponse, IAvailableActions, IGetJobResponse } from '../../../src/common/dataModels/jobs';
import { ResponseCodes } from '../../../src/common/constants';
import { excludeColumns } from '../../../src/common/utils';
import { TaskRepository } from '../../../src/DAL/repositories/taskRepository';
import { TaskEntity } from '../../../src/DAL/entity/task';
import { JobManager } from '../../../src/jobs/models/jobManager';
import { JobsRequestSender, SearchJobsParams } from './helpers/jobsRequestSender';

let jobRepositoryMocks: RepositoryMocks;
let taskRepositoryMocks: RepositoryMocks;

function createJobDataForFind(): unknown {
const taskModel = {
jobId: 'jobId',
Expand Down Expand Up @@ -256,6 +258,7 @@ function createJobDataForAvailableActionsWithAbortableJob(): unknown {
};
return jobModel;
}

function jobModelToEntity(jobModel: unknown): JobEntity {
const model = jobModel as {
created: string;
Expand Down Expand Up @@ -668,6 +671,32 @@ describe('job', function () {
expect(response).toSatisfyApiSpec();
});

it('should exclude parameters when shouldExcludeParameters=true', async () => {
const jobEntity = jobModelToEntity(createJobDataForFind());

jobRepositoryMocks.queryBuilder.getMany.mockResolvedValue([jobEntity]);

await requestSender.findJobs({
shouldExcludeParameters: true,
});

expect(jobRepositoryMocks.queryBuilder.select).toHaveBeenCalledWith(
expect.arrayContaining(excludeColumns(JobEntity, ['parameters', 'tasks']).map((c) => `job.${c}`))
);
});

it('should include parameters when shouldExcludeParameters=false', async () => {
const jobEntity = jobModelToEntity(createJobDataForFind());

jobRepositoryMocks.queryBuilder.getMany.mockResolvedValue([jobEntity]);

await requestSender.findJobs({
shouldExcludeParameters: false,
});

expect(jobRepositoryMocks.queryBuilder.select).toHaveBeenCalledWith('job');
});

it('should not find matched jobs and return status 200 with an empty array', async function () {
const filter = {
isCleaned: true,
Expand Down
Loading