Skip to content

Commit

Permalink
linting pt 1
Browse files Browse the repository at this point in the history
  • Loading branch information
despadam committed Oct 15, 2024
1 parent 431151c commit 90a8fe4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/common/handlebars-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Helpers should be registered in app.module.ts
*/
import { JobClass } from "src/jobs/schemas/job.schema";
import { JobParams } from "src/jobs/types/job-types.enum";
import { JobParams } from "src/jobs/types/job-types.enum";

/**
* Convert json objects to HTML
Expand Down
36 changes: 24 additions & 12 deletions src/jobs/jobs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { FilterQuery } from "mongoose";
import { JobsService } from "./jobs.service";
import { CreateJobDto } from "./dto/create-job.dto";
import { StatusUpdateJobDto } from "./dto/status-update-job.dto";
import { DatasetListDto } from "./dto/dataset-list.dto";
import { DatasetListDto } from "./dto/dataset-list.dto";
import { PoliciesGuard } from "src/casl/guards/policies.guard";
import { CheckPolicies } from "src/casl/decorators/check-policies.decorator";
import { AppAbility, CaslAbilityFactory } from "src/casl/casl-ability.factory";
Expand Down Expand Up @@ -51,7 +51,7 @@ import {
jobsFullQueryDescriptionFields,
} from "src/common/utils";
import { JobAction } from "./config/jobconfig";
import { JobType, DatasetState, JobParams } from "./types/job-types.enum";
import { JobType, DatasetState, JobParams } from "./types/job-types.enum";
import { IJobFields } from "./interfaces/job-filters.interface";

@ApiBearerAuth()
Expand Down Expand Up @@ -102,7 +102,9 @@ export class JobsController {
jobParams: Record<string, unknown>,
jobType: string,
): Promise<DatasetListDto[]> {
const datasetList = jobParams[JobParams.DatasetList] as Array<DatasetListDto>;
const datasetList = jobParams[
JobParams.DatasetList
] as Array<DatasetListDto>;
// check that datasetList is a non empty array
if (!Array.isArray(datasetList)) {
throw new HttpException(
Expand All @@ -125,12 +127,15 @@ export class JobsController {

// check that datasetList is of type DatasetListDto[]
const datasetListDtos: DatasetListDto[] = datasetList.map(item => {

Check failure on line 129 in src/jobs/jobs.controller.ts

View workflow job for this annotation

GitHub Actions / eslint

Replace `item` with `(item)`
return Object.assign(new DatasetListDto(), item);
return Object.assign(new DatasetListDto(), (item));

Check failure on line 130 in src/jobs/jobs.controller.ts

View workflow job for this annotation

GitHub Actions / eslint

Replace `(item)` with `item`
});
const allowedKeys = [JobParams.Pid, JobParams.Files] as string[];
for (const datasetListDto of datasetListDtos) {
const keys = Object.keys(datasetListDto);
if (keys.length !== 2 || !keys.every(key => allowedKeys.includes(key))) {
if (
keys.length !== 2 ||
!keys.every((key) => allowedKeys.includes(key))
) {
throw new HttpException(
{
status: HttpStatus.BAD_REQUEST,
Expand Down Expand Up @@ -161,7 +166,7 @@ export class JobsController {
};
}

const datasetIds = datasetList.map(x => x.pid);
const datasetIds = datasetList.map((x) => x.pid);
const filter: condition = {
where: {
pid: { $in: datasetIds },
Expand Down Expand Up @@ -194,10 +199,9 @@ export class JobsController {
datasetList: DatasetListDto[],
jobType: string,
): Promise<void> {
const datasetIds = datasetList.map(x => x.pid);
const datasetIds = datasetList.map((x) => x.pid);
switch (jobType) {
case JobType.Retrieve:
// Intentional fall through
case JobType.Retrieve: // Intentional fall through
case JobType.Archive:
{
const filter = {
Expand Down Expand Up @@ -329,7 +333,12 @@ export class JobsController {
{
status: HttpStatus.BAD_REQUEST,
message: "At least one requested file could not be found.",
error: JSON.stringify(checkResults.map(({ pid, nonExistFiles }) => ({ pid, nonExistFiles }))),
error: JSON.stringify(
checkResults.map(({ pid, nonExistFiles }) => ({
pid,
nonExistFiles,
}))

Check failure on line 340 in src/jobs/jobs.controller.ts

View workflow job for this annotation

GitHub Actions / eslint

Insert `,`
),
},
HttpStatus.BAD_REQUEST,
);
Expand Down Expand Up @@ -411,7 +420,10 @@ export class JobsController {
// validate datasetList, if it exists in jobParams
let datasetList: DatasetListDto[] = [];
if (JobParams.DatasetList in jobCreateDto.jobParams) {
datasetList = await this.validateDatasetList(jobCreateDto.jobParams, jobCreateDto.type);
datasetList = await this.validateDatasetList(
jobCreateDto.jobParams,
jobCreateDto.type,
);
jobInstance.jobParams = {
...jobInstance.jobParams,
[JobParams.DatasetList]: datasetList,
Expand Down Expand Up @@ -500,7 +512,7 @@ export class JobsController {
};
}

const datasetIds = datasetList.map(x => x.pid);
const datasetIds = datasetList.map((x) => x.pid);
const datasetsWhere: datasetsWhere = {
where: {
pid: { $in: datasetIds },
Expand Down

0 comments on commit 90a8fe4

Please sign in to comment.