Skip to content

Commit

Permalink
Fix/updateRoute (#90)
Browse files Browse the repository at this point in the history
* updating status to done for automatic route decisions

* updating readme

* updating antoine's request
  • Loading branch information
Bouba-cassation authored Mar 25, 2024
1 parent 784d5ac commit e97412e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion docs/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,6 @@ Revert a migration.

Run migrations.

## updateRoute
## updateRouteForFreeDocuments

Reapply route rules for documents with a specific status.
2 changes: 1 addition & 1 deletion packages/courDeCassation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ prod label script exportSpecificDocument --documentNumber=10000 --source=jurinet

In Wallix, with a Cygwin terminal:
```
prod label script updateRoute --status=free
prod label script updateRouteForFreeDocuments
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function extractRoute(
criminalCaseCode: documentType['decisionMetadata']['criminalCaseCode'];
NACCode: documentType['decisionMetadata']['NACCode'];
endCaseCode: documentType['decisionMetadata']['endCaseCode'];
status?: documentType['status'];
},
source: documentType['source'],
): documentType['route'] {
Expand Down
64 changes: 33 additions & 31 deletions packages/courDeCassation/src/scripts/updateRoute.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
import yargs from 'yargs';
import { buildBackend, buildDocumentRepository, logger } from '@label/backend';
import { parametersHandler } from '../lib/parametersHandler';
import { documentType } from '@label/core';
import { extractRoute } from '../connector/mapper/extractors';
import * as readline from 'readline';

(async () => {
const { environment, settings } = await parametersHandler.getParameters();
const { status } = parseArgv();
const backend = buildBackend(environment, settings);

backend.runScript(() => updateRoute(status), {
shouldLoadDb: true,
const prompt = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const { environment, settings } = await parametersHandler.getParameters();
prompt.question(
'Voulez vous mettre a jour le circuit de relecture de tous les documents free (yes/no)?',
(answer: any) => {
if (answer == 'yes') {
const backend = buildBackend(environment, settings);
backend.runScript(() => updateRouteForFreeDocuments(), {
shouldLoadDb: true,
});
} else {
logger.log({
operationName: 'updateRouteForFreeDocuments',
msg: `updateRouteForFreeDocuments script is canceled`,
});
}
prompt.close();
},
);
})();

async function updateRoute(status: documentType['status']) {
async function updateRouteForFreeDocuments() {
logger.log({
operationName: 'updateRoute',
msg: `Update route of documents with status ${status}`,
operationName: 'updateRouteForFreeDocuments',
msg: `Update route of documents with status Free`,
});

const documentRepository = buildDocumentRepository();

const documentsToUpdate = await documentRepository.findAllByStatus([status]);
const documentsToUpdate = await documentRepository.findAllByStatus(['free']);
logger.log({
operationName: 'updateRoute',
operationName: 'updateRouteForFreeDocuments',
msg: `${documentsToUpdate.length} documents to update route`,
});

Expand All @@ -48,31 +62,19 @@ async function updateRoute(status: documentType['status']) {
},
documentsToUpdate[index].source,
);

logger.log({
operationName: 'updateRoute',
operationName: 'updateRouteForFreeDocuments',
msg: `New route for the document ${documentsToUpdate[index]._id} : ${newRoute}`,
});

await documentRepository.updateRouteById(
documentsToUpdate[index]._id,
newRoute,
);
}
}

function parseArgv() {
const argv = yargs
.option({
status: {
demandOption: true,
description: 'status of the document you want to update route',
type: 'string',
},
})
.help()
.alias('help', 'h').argv;

return {
status: argv.status as documentType['status'],
};
if (newRoute === 'automatic') {
documentRepository.updateStatusById(documentsToUpdate[index]._id, 'done');
}
}
}

0 comments on commit e97412e

Please sign in to comment.