Skip to content

Commit

Permalink
Merge pull request #44 from BaseAdresseNationale/antoineludeau/init-b…
Browse files Browse the repository at this point in the history
…al-into-ban-script

Added init bal into ban script
  • Loading branch information
antoineludeau authored Sep 25, 2023
2 parents 6d362c5 + 9b2bd18 commit d8e90c0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ npm install
npm run dev
```

## Scripts
I. Init a BAL csv into the BAN plateforme using the ID-Fix BAL processing.

Prerequisite : the district data of the BAL to import needs to be already present in the BAN DB. If not, use the POST /district api to create it.

Here is the command to use :
```bash
npm run initBALIntoBAN the/path/to/BAL/CSV
```
replace "the/path/to/BAL/CSV" to the actual path of the BAL csv to process and insert into the BAN

## License
This project is licensed under the MIT License - see the LICENSE file for details.

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build": "npx tsc",
"test": "vitest",
"updateBAL": "ts-node --esm script/update-bal.ts",
"initBALIntoBAN": "ts-node --esm script/init-bal-into-ban.ts",
"start": "node dist/app.js",
"dev": "nodemon src/app.ts",
"ts": "ts-node"
Expand Down
39 changes: 39 additions & 0 deletions script/init-bal-into-ban.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env ts-node
import 'dotenv/config.js';
import fs from "node:fs";
import path from "node:path";
import argvParser from "minimist";
import {
sendBalToBan
} from "../src/bal-converter/index.js";
import { exit } from "node:process";

const args = argvParser(process.argv.slice(2));

const {
_: [pathToBalCSVToInit],
} = args;

if (!pathToBalCSVToInit) {
console.error("Missing path to BAL CSV file");
exit(1);
}

if (!fs.existsSync(pathToBalCSVToInit)) {
console.error(`File '${pathToBalCSVToInit}' does not exist`);
exit(1);
}

if (!pathToBalCSVToInit.match(/\.csv$/)) {
console.error(`File '${pathToBalCSVToInit}' is not a CSV file`);
exit(1);
}

const mockBalCSV = fs.readFileSync(pathToBalCSVToInit, "utf8");

await sendBalToBan(mockBalCSV);
console.log(
`Data from '${path.basename(
pathToBalCSVToInit
)}' initialized in BAN DB`
);

0 comments on commit d8e90c0

Please sign in to comment.