Skip to content

Commit

Permalink
Quick script to bulk move contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
kennsippell committed May 22, 2024
1 parent d770b31 commit bf42eee
Show file tree
Hide file tree
Showing 2 changed files with 491 additions and 0 deletions.
34 changes: 34 additions & 0 deletions scripts/move-contacts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { queueManager } from "../../shared/queues";
import { Config } from "../../src/config";
import { ChtApi } from "../../src/lib/cht-api";
import ChtSession from "../../src/lib/cht-session";
import MoveLib from "../../src/lib/move";
import SessionCache from "../../src/services/session-cache";

import allPlacesToMove from "./laikipia-west";

const username = 'kenn_sippell_medic_user_manager';
const password = 'f*CcG8#lOJtt2V^';
const authInfo = Config.getAuthenticationInfo('laikipia.echis.go.ke');
const contactType = Config.getContactType('d_community_health_volunteer_area');
const batchToMove = allPlacesToMove.slice(7, 50);

(async () => {
for (const toMove of batchToMove) {
const [from_SUBCOUNTY, from_CHU, from_replacement, to_SUBCOUNTY, to_CHU] = toMove;
const formData = {
from_SUBCOUNTY, from_CHU, from_replacement,
to_SUBCOUNTY, to_CHU,
};
const session = await ChtSession.create(authInfo, username, password);
const chtApi = new ChtApi(session);
const sessionCache = SessionCache.getForSession(session);

try {
const result = await MoveLib.move(formData, contactType, sessionCache, chtApi, queueManager);
console.log(JSON.stringify(result));
} catch (error) {
console.log(`error: `, error);
}
}
})();
Loading

0 comments on commit bf42eee

Please sign in to comment.