Skip to content

Commit 97e4e26

Browse files
authored
Chore : Removed migration API to add github user id (#2051)
* Chore : Removed migration API to add github user id * Chore : Removed unused fixture
1 parent d5be3c7 commit 97e4e26

File tree

5 files changed

+1
-375
lines changed

5 files changed

+1
-375
lines changed

controllers/users.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const { getPaginationLink, getUsernamesFromPRs, getRoleToUpdate } = require("../
1515
const { setInDiscordFalseScript, setUserDiscordNickname } = require("../services/discordService");
1616
const { generateDiscordProfileImageUrl } = require("../utils/discord-actions");
1717
const { addRoleToUser, getDiscordMembers } = require("../services/discordService");
18-
const { fetchAllUsers, addGithubUserId } = require("../models/users");
18+
const { fetchAllUsers } = require("../models/users");
1919
const { getOverdueTasks } = require("../models/tasks");
2020
const { getQualifiers } = require("../utils/helper");
2121
const { parseSearchQuery } = require("../utils/users");
@@ -918,20 +918,6 @@ async function usersPatchHandler(req, res) {
918918
return res.boom.badImplementation(INTERNAL_SERVER_ERROR);
919919
}
920920
}
921-
const migrations = async (req, res) => {
922-
const { page = 0, size } = req.query;
923-
924-
try {
925-
const result = await addGithubUserId(parseInt(page), parseInt(size));
926-
return res.status(200).json({
927-
message: "Result of migration",
928-
data: result,
929-
});
930-
} catch (error) {
931-
logger.error(`Internal Server Error: ${error}`);
932-
return res.boom.badImplementation(INTERNAL_SERVER_ERROR);
933-
}
934-
};
935921

936922
module.exports = {
937923
verifyUser,
@@ -962,6 +948,5 @@ module.exports = {
962948
updateDiscordUserNickname,
963949
archiveUserIfNotInDiscord,
964950
usersPatchHandler,
965-
migrations,
966951
isDeveloper,
967952
};

models/users.js

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -900,66 +900,6 @@ const getNonNickNameSyncedUsers = async () => {
900900
throw err;
901901
}
902902
};
903-
const addGithubUserId = async (page, size) => {
904-
try {
905-
const usersNotFound = [];
906-
let countUserFound = 0;
907-
let countUserNotFound = 0;
908-
909-
const requestOptions = {
910-
method: "GET",
911-
headers: {
912-
"Content-Type": "application/json",
913-
Authorization:
914-
"Basic " + btoa(`${config.get("githubOauth.clientId")}:${config.get("githubOauth.clientSecret")}`),
915-
},
916-
};
917-
const usersSnapshot = await firestore
918-
.collection("users")
919-
.limit(size)
920-
.offset(page * size)
921-
.get();
922-
// Create batch write operations for each batch of documents
923-
const batchWrite = firestore.batch();
924-
const batchWrites = [];
925-
for (const userDoc of usersSnapshot.docs) {
926-
if (userDoc.data().github_user_id) continue;
927-
const githubUsername = userDoc.data().github_id;
928-
const username = userDoc.data().username;
929-
const userId = userDoc.id;
930-
const getUserDetails = fetch(`https://api.github.com/users/${githubUsername}`, requestOptions)
931-
.then((response) => {
932-
if (!response.ok) {
933-
throw new Error("Network response was not ok");
934-
}
935-
return response.json();
936-
})
937-
.then((data) => {
938-
const githubUserId = data.id;
939-
batchWrite.update(userDoc.ref, { github_user_id: `${githubUserId}`, updated_at: Date.now() });
940-
countUserFound++;
941-
})
942-
.catch((error) => {
943-
countUserNotFound++;
944-
const invalidUsers = { userId, username, githubUsername };
945-
usersNotFound.push(invalidUsers);
946-
logger.error("An error occurred at fetch:", error);
947-
});
948-
batchWrites.push(getUserDetails);
949-
}
950-
await Promise.all(batchWrites);
951-
await batchWrite.commit();
952-
return {
953-
totalUsers: usersSnapshot.docs.length,
954-
usersUpdated: countUserFound,
955-
usersNotUpdated: countUserNotFound,
956-
invalidUsersDetails: usersNotFound,
957-
};
958-
} catch (error) {
959-
logger.error(`Error while Updating all users: ${error}`);
960-
throw Error(error);
961-
}
962-
};
963903

964904
module.exports = {
965905
addOrUpdate,
@@ -990,5 +930,4 @@ module.exports = {
990930
fetchUsersListForMultipleValues,
991931
fetchUserForKeyValue,
992932
getNonNickNameSyncedUsers,
993-
addGithubUserId,
994933
};

routes/users.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,4 @@ router.patch("/profileURL", authenticate, userValidator.updateProfileURL, users.
6565
router.patch("/rejectDiff", authenticate, authorizeRoles([SUPERUSER]), users.rejectProfileDiff);
6666
router.patch("/:userId", authenticate, authorizeRoles([SUPERUSER]), users.updateUser);
6767
router.get("/suggestedUsers/:skillId", authenticate, authorizeRoles([SUPERUSER]), users.getSuggestedUsers);
68-
// WARNING!! - One time Script/Route to do migration
69-
router.post(
70-
"/migrations",
71-
authenticate,
72-
authorizeRoles([SUPERUSER]),
73-
userValidator.migrationsValidator,
74-
users.migrations
75-
);
7668
module.exports = router;

test/fixtures/user/prodUsers.js

Lines changed: 0 additions & 191 deletions
This file was deleted.

0 commit comments

Comments
 (0)