Skip to content

Commit

Permalink
Chore : Removed migration API to add github user id (#2051)
Browse files Browse the repository at this point in the history
* Chore : Removed migration API to add github user id

* Chore : Removed unused fixture
  • Loading branch information
joyguptaa authored Jun 18, 2024
1 parent d5be3c7 commit 97e4e26
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 375 deletions.
17 changes: 1 addition & 16 deletions controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { getPaginationLink, getUsernamesFromPRs, getRoleToUpdate } = require("../
const { setInDiscordFalseScript, setUserDiscordNickname } = require("../services/discordService");
const { generateDiscordProfileImageUrl } = require("../utils/discord-actions");
const { addRoleToUser, getDiscordMembers } = require("../services/discordService");
const { fetchAllUsers, addGithubUserId } = require("../models/users");
const { fetchAllUsers } = require("../models/users");
const { getOverdueTasks } = require("../models/tasks");
const { getQualifiers } = require("../utils/helper");
const { parseSearchQuery } = require("../utils/users");
Expand Down Expand Up @@ -918,20 +918,6 @@ async function usersPatchHandler(req, res) {
return res.boom.badImplementation(INTERNAL_SERVER_ERROR);
}
}
const migrations = async (req, res) => {
const { page = 0, size } = req.query;

try {
const result = await addGithubUserId(parseInt(page), parseInt(size));
return res.status(200).json({
message: "Result of migration",
data: result,
});
} catch (error) {
logger.error(`Internal Server Error: ${error}`);
return res.boom.badImplementation(INTERNAL_SERVER_ERROR);
}
};

module.exports = {
verifyUser,
Expand Down Expand Up @@ -962,6 +948,5 @@ module.exports = {
updateDiscordUserNickname,
archiveUserIfNotInDiscord,
usersPatchHandler,
migrations,
isDeveloper,
};
61 changes: 0 additions & 61 deletions models/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,66 +900,6 @@ const getNonNickNameSyncedUsers = async () => {
throw err;
}
};
const addGithubUserId = async (page, size) => {
try {
const usersNotFound = [];
let countUserFound = 0;
let countUserNotFound = 0;

const requestOptions = {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization:
"Basic " + btoa(`${config.get("githubOauth.clientId")}:${config.get("githubOauth.clientSecret")}`),
},
};
const usersSnapshot = await firestore
.collection("users")
.limit(size)
.offset(page * size)
.get();
// Create batch write operations for each batch of documents
const batchWrite = firestore.batch();
const batchWrites = [];
for (const userDoc of usersSnapshot.docs) {
if (userDoc.data().github_user_id) continue;
const githubUsername = userDoc.data().github_id;
const username = userDoc.data().username;
const userId = userDoc.id;
const getUserDetails = fetch(`https://api.github.com/users/${githubUsername}`, requestOptions)
.then((response) => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
})
.then((data) => {
const githubUserId = data.id;
batchWrite.update(userDoc.ref, { github_user_id: `${githubUserId}`, updated_at: Date.now() });
countUserFound++;
})
.catch((error) => {
countUserNotFound++;
const invalidUsers = { userId, username, githubUsername };
usersNotFound.push(invalidUsers);
logger.error("An error occurred at fetch:", error);
});
batchWrites.push(getUserDetails);
}
await Promise.all(batchWrites);
await batchWrite.commit();
return {
totalUsers: usersSnapshot.docs.length,
usersUpdated: countUserFound,
usersNotUpdated: countUserNotFound,
invalidUsersDetails: usersNotFound,
};
} catch (error) {
logger.error(`Error while Updating all users: ${error}`);
throw Error(error);
}
};

module.exports = {
addOrUpdate,
Expand Down Expand Up @@ -990,5 +930,4 @@ module.exports = {
fetchUsersListForMultipleValues,
fetchUserForKeyValue,
getNonNickNameSyncedUsers,
addGithubUserId,
};
8 changes: 0 additions & 8 deletions routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,4 @@ router.patch("/profileURL", authenticate, userValidator.updateProfileURL, users.
router.patch("/rejectDiff", authenticate, authorizeRoles([SUPERUSER]), users.rejectProfileDiff);
router.patch("/:userId", authenticate, authorizeRoles([SUPERUSER]), users.updateUser);
router.get("/suggestedUsers/:skillId", authenticate, authorizeRoles([SUPERUSER]), users.getSuggestedUsers);
// WARNING!! - One time Script/Route to do migration
router.post(
"/migrations",
authenticate,
authorizeRoles([SUPERUSER]),
userValidator.migrationsValidator,
users.migrations
);
module.exports = router;
191 changes: 0 additions & 191 deletions test/fixtures/user/prodUsers.js

This file was deleted.

Loading

0 comments on commit 97e4e26

Please sign in to comment.