Skip to content

Commit

Permalink
chore(script): make tsc happy
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Sep 27, 2024
1 parent 4e1f131 commit 148d34e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
16 changes: 10 additions & 6 deletions scripts/import-accounts-coop.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// src https://stackoverflow.com/questions/40994095/pipe-streams-to-edit-csv-file-in-node-js
import { AxiosError } from "axios";
import { parse, stringify, transform } from "csv";
import fs from "fs";
import { isEmpty, some, toInteger } from "lodash-es";
import { z } from "zod";
import {
getInseeAccessToken,
getOrganizationInfo,
} from "../src/connectors/api-sirene";
import { findByUserId } from "../src/repositories/organization/getters";
import {
linkUserToOrganization,
upsert,
Expand All @@ -26,11 +29,12 @@ import {
isSiretValid,
} from "../src/services/security";

import { parse, stringify, transform } from "csv";
import { findByUserId } from "../src/repositories/organization/getters";

const INPUT_FILE = process.env.INPUT_FILE ?? "./input.csv";
const OUTPUT_FILE = process.env.OUTPUT_FILE ?? "./output.csv";
const { INPUT_FILE, OUTPUT_FILE } = z
.object({
INPUT_FILE: z.string().default("./input.csv"),
OUTPUT_FILE: z.string().default("./output.csv"),
})
.parse(process.env);

// ex: for public insee subscription the script can be run like so:
// npm run update-organization-info 2000
Expand Down Expand Up @@ -95,6 +99,7 @@ const maxInseeCallRateInMs = rateInMsFromArgs !== 0 ? rateInMsFromArgs : 125;
logger.info("");

const transformStream = transform(
{ parallel: 1 }, // avoid messing with line orders
async function (
data: InputCsvData,
done: (err: null | Error, data?: OutputCsvData) => void,
Expand Down Expand Up @@ -224,7 +229,6 @@ const maxInseeCallRateInMs = rateInMsFromArgs !== 0 ? rateInMsFromArgs : 125;
return done(null, { ...data, error: "unexpected_error" });
}
},
{ parallel: 1 }, // avoid messing with line orders
).on("end", () => {
logger.info(`Import done! Import logs are recorded in ${OUTPUT_FILE}.`);
logger.info("");
Expand Down
18 changes: 11 additions & 7 deletions scripts/import-accounts.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// src https://stackoverflow.com/questions/40994095/pipe-streams-to-edit-csv-file-in-node-js
import { AxiosError } from "axios";
import { parse, stringify, transform } from "csv";
import fs from "fs";
import { isEmpty, some, toInteger } from "lodash-es";
import { z } from "zod";
import {
getInseeAccessToken,
getOrganizationInfo,
} from "../src/connectors/api-sirene";
import { findByUserId } from "../src/repositories/organization/getters";
import {
linkUserToOrganization,
upsert,
Expand All @@ -25,11 +28,12 @@ import {
isSiretValid,
} from "../src/services/security";

import { parse, stringify, transform } from "csv";
import { findByUserId } from "../src/repositories/organization/getters";

const INPUT_FILE = process.env.INPUT_FILE ?? "./input.csv";
const OUTPUT_FILE = process.env.OUTPUT_FILE ?? "./output.csv";
const { INPUT_FILE, OUTPUT_FILE } = z
.object({
INPUT_FILE: z.string().default("./input.csv"),
OUTPUT_FILE: z.string().default("./output.csv"),
})
.parse(process.env);

// ex: for public insee subscription the script can be run like so:
// npm run update-organization-info 2000
Expand Down Expand Up @@ -93,6 +97,7 @@ const maxInseeCallRateInMs = rateInMsFromArgs !== 0 ? rateInMsFromArgs : 125;
logger.info("");

const transformStream = transform(
{ parallel: 1 }, // avoid messing with line orders
async function (
data: InputCsvData,
done: (err: null | Error, data?: OutputCsvData) => void,
Expand Down Expand Up @@ -184,7 +189,7 @@ const maxInseeCallRateInMs = rateInMsFromArgs !== 0 ? rateInMsFromArgs : 125;
return done(null, {
email,
inclusionconnect_sub: sub,
moncomptepro_sub: user.id,
moncomptepro_sub: String(user.id),
});
} catch (error) {
logger.error("unexpected error");
Expand All @@ -203,7 +208,6 @@ const maxInseeCallRateInMs = rateInMsFromArgs !== 0 ? rateInMsFromArgs : 125;
return done(null);
}
},
{ parallel: 1 }, // avoid messing with line orders
).on("end", () => {
logger.info(`Import done! Import logs are recorded in ${OUTPUT_FILE}.`);
logger.info("");
Expand Down
11 changes: 8 additions & 3 deletions scripts/import-domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AxiosError } from "axios";
import { parse, stringify, transform } from "csv";
import fs from "fs";
import { isEmpty, some, toInteger } from "lodash-es";
import { z } from "zod";
import { InseeNotFoundError } from "../src/config/errors";
import {
getInseeAccessToken,
Expand All @@ -24,8 +25,12 @@ import {
} from "../src/services/script-helpers";
import { isDomainValid, isSiretValid } from "../src/services/security";

const INPUT_FILE = process.env.INPUT_FILE ?? "./input.csv";
const OUTPUT_FILE = process.env.OUTPUT_FILE ?? "./output.csv";
const { INPUT_FILE, OUTPUT_FILE } = z
.object({
INPUT_FILE: z.string().default("./input.csv"),
OUTPUT_FILE: z.string().default("./output.csv"),
})
.parse(process.env);

// ex: for public insee subscription the script can be run like so:
// npm run update-organization-info 2000
Expand Down Expand Up @@ -76,6 +81,7 @@ const maxInseeCallRateInMs = rateInMsFromArgs !== 0 ? rateInMsFromArgs : 125;
logger.info("");

const transformStream = transform(
{ parallel: 1 }, // avoid messing with line orders
async function (
data: InputCsvData,
done: (err: null | Error, data: OutputCsvData) => void,
Expand Down Expand Up @@ -200,7 +206,6 @@ const maxInseeCallRateInMs = rateInMsFromArgs !== 0 ? rateInMsFromArgs : 125;
return done(null, { ...data, result: "unexpected_error" });
}
},
{ parallel: 1 }, // avoid messing with line orders
).on("end", () => {
logger.info(`Import done! Import logs are recorded in ${OUTPUT_FILE}.`);
logger.info("");
Expand Down

0 comments on commit 148d34e

Please sign in to comment.