forked from Samagra-Development/workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from Samagra-Anamaya/feat-healthchecks
Adding scripts
- Loading branch information
Showing
11 changed files
with
1,207,219 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const axios = require('axios'); | ||
const fs = require('fs'); | ||
|
||
const VILLAGES_JSON_PATH = 'input/villages.json'; | ||
const ADD_VILLAGE_URL = 'http://localhost:3003/utils/addVillage'; | ||
|
||
async function addVillage(village) { | ||
try { | ||
const response = await axios.post(ADD_VILLAGE_URL, village); | ||
console.log(`Village ${village.villageName} added successfully!`); | ||
} catch (error) { | ||
console.error(`Error adding village ${village.villageName}`, error.response ? error.response.data : error.message); | ||
} | ||
} | ||
|
||
function loadVillages() { | ||
try { | ||
const villagesJson = fs.readFileSync(VILLAGES_JSON_PATH, 'utf8'); | ||
const villages = JSON.parse(villagesJson); | ||
return villages; | ||
} catch (error) { | ||
console.error('Error loading villages:', error.message); | ||
return []; | ||
} | ||
} | ||
|
||
async function main() { | ||
const villages = loadVillages(); | ||
for (const village of villages) { | ||
await addVillage(village); | ||
} | ||
} | ||
|
||
main(); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
const axios = require("axios"); | ||
const csv = require("csv-parser"); | ||
const fs = require("fs"); | ||
const { find } = require("lodash"); | ||
|
||
const FUSION_AUTH_BASE_URL = ""; | ||
const FUSION_AUTH_ENDPOINT = "/api/signup"; | ||
const users = []; | ||
const _users = {}; | ||
const HEADERS = { | ||
"x-application-id": "", | ||
"Content-Type": "application/json", | ||
}; | ||
|
||
async function create_user_in_fusionauth(user) { | ||
console.log({ user }); | ||
try { | ||
const response = await axios.post( | ||
`${FUSION_AUTH_BASE_URL}${FUSION_AUTH_ENDPOINT}`, | ||
user, | ||
{ headers: HEADERS } | ||
); | ||
console.log({ response }); | ||
console.log(`User ${user.user.email} created successfully!`); | ||
} catch (error) { | ||
console.error( | ||
`Error creating user ${user.user.email}: ${ | ||
error.response ? error.response.data : error.message | ||
}` | ||
); | ||
} | ||
} | ||
|
||
function csv_to_users(filename) { | ||
return new Promise((resolve, reject) => { | ||
fs.createReadStream(filename) | ||
.pipe(csv()) | ||
.on("data", (row) => { | ||
// Assuming the CSV has columns 'email', 'password', and 'username' | ||
const prev = find(users, (prevU) => { | ||
return prevU.data.gpCode == `${row["gpCode"]}`; | ||
}); | ||
_users[row["gpCode"]] = { | ||
..._users[row["gpCode"]], | ||
user: { | ||
password: `pass_${row["gpCode"]}`, | ||
username: `gp_${row["gpCode"]}`, | ||
data: { | ||
..._users[row["gpCode"]]?.user?.data, | ||
gpCode: row["gpCode"], | ||
villages: _users[row["gpCode"]]?.user?.data?.villages | ||
? [ | ||
..._users[row["gpCode"]]?.user?.data?.villages, | ||
{ | ||
villageCode: row["villageCode"], | ||
villageName: row["villageName"], | ||
}, | ||
] | ||
: [ | ||
{ | ||
villageCode: row["villageCode"], | ||
villageName: row["villageName"], | ||
}, | ||
], | ||
} | ||
}, | ||
|
||
registration: { | ||
applicationId: "", | ||
preferredLanguages: ["en"], | ||
roles: ["enumerator"], | ||
usernameStatus: "ACTIVE", | ||
}, | ||
}; | ||
}) | ||
.on("end", () => { | ||
resolve(users); | ||
}) | ||
.on("error", (error) => { | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
|
||
async function main() { | ||
try { | ||
const users = await csv_to_users("data2.csv"); | ||
fs.writeFile("users.json", JSON.stringify(users, null, 2), (err) => { | ||
if (err) { | ||
console.error(err); | ||
} | ||
|
||
console.log("User data saved successfully"); | ||
}); | ||
fs.writeFile("_users.json", JSON.stringify(_users, null, 2), (err) => { | ||
if (err) { | ||
console.error(err); | ||
} | ||
|
||
console.log("_User data saved successfully"); | ||
}); | ||
|
||
//console.log({ users }); | ||
// for (const user of users) { | ||
// await create_user_in_fusionauth(user); | ||
// } | ||
} catch (error) { | ||
console.error(`An error occurred: ${error.message}`); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[ | ||
{ | ||
"id": 1, | ||
"stateCode": 21, | ||
"stateName": "ODISHA", | ||
"districtCode": 344, | ||
"districtName": "ANUGUL", | ||
"itdaName": "", | ||
"blockCode": 3276, | ||
"blockName": "ANUGUL", | ||
"isTspBlock": "N", | ||
"gpCode": 115550, | ||
"gpName": "ANGARBANDHA", | ||
"spdpVillageId": 404281, | ||
"villageName": "Angarbandha" | ||
} | ||
] |
Oops, something went wrong.