Skip to content

Commit

Permalink
Merge pull request #67 from italia/feat/update_validatore_1.1.10
Browse files Browse the repository at this point in the history
feat: update crawler 1.1.10
  • Loading branch information
lorenzo-vernocchi authored Dec 6, 2024
2 parents 85d997a + c61a1e0 commit a04eb71
Show file tree
Hide file tree
Showing 8 changed files with 510 additions and 19 deletions.
5 changes: 4 additions & 1 deletion command/scanManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ dbSM
});

const cleanConsoleOutput = (consoleOutput: string) => {
return consoleOutput.replace("[32m", "").replace("[0m", "").replace("", "");
return consoleOutput
.replace("/[32m/g", "")
.replace("/[0m/g", "")
.replace("//g", "");
};

const uploadLogs = async (
Expand Down
55 changes: 55 additions & 0 deletions controller/jobController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { entityController } from "./entityController.js";
import { preserveReasons } from "../database/models/job.js";
import { define as jobDefine } from "../database/models/job.js";
import { Queue } from "bullmq";
import { preFilterPayload, jsonToSequelizeWhere } from "../utils/utils.js";

export class jobController {
db: Sequelize;
Expand Down Expand Up @@ -283,4 +284,58 @@ export class jobController {

return entityJobs.length > 0;
}

async query(
filters: object,
page: string,
limit: string,
countOnly: boolean
): Promise<
| {
totalElements: number;
currentPage: number;
pages: number;
jobs: mappedJob[];
}
| { count: number }
> {
const returnValues = {
totalElements: 0,
currentPage: parseInt(page),
pages: 0,
jobs: [],
};

preFilterPayload(filters);
const sequelizeWhere = jsonToSequelizeWhere(filters);

const totalCount = await jobDefine(this.db).count({
where: sequelizeWhere,
});

if (countOnly) return { count: totalCount };

let queryObj = {};
if (parseInt(limit) >= 0) {
queryObj = {
where: sequelizeWhere,
offset: parseInt(page) * parseInt(limit),
limit: parseInt(limit),
};
} else {
queryObj = {
where: sequelizeWhere,
};
}

const jobs: Job[] = await jobDefine(this.db).findAll(queryObj);

returnValues.totalElements = totalCount;
returnValues.pages =
parseInt(limit) >= 0 ? Math.ceil(totalCount / parseInt(limit)) : 1;
returnValues.currentPage = parseInt(page);
returnValues.jobs = jobs;

return returnValues;
}
}
15 changes: 7 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crawler-handler",
"version": "3.0.26",
"version": "3.0.27",
"description": "Handler per il validatore di comuni e scuole",
"main": "index.js",
"type": "module",
Expand Down Expand Up @@ -42,7 +42,7 @@
"mysql2": "^2.3.3",
"nodemon": "^2.0.16",
"npm-run-all": "^4.1.5",
"pa-website-validator-ng": "github:italia/pa-website-validator-ng#v1.1.9",
"pa-website-validator-ng": "github:italia/pa-website-validator-ng#v1.1.10",
"pg": "^8.7.3",
"ps-list": "^8.1.1",
"redis": "^4.1.0",
Expand Down
Loading

0 comments on commit a04eb71

Please sign in to comment.