generated from RealDevSquad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 280
GitHub duplication Fixed and Migration #1044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iamYashSinha
wants to merge
72
commits into
RealDevSquad:develop
Choose a base branch
from
iamYashSinha:bugfix/issue957
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
72 commits
Select commit
Hold shift + click to select a range
5941bc5
Merge branch 'develop' into main-resolve-conflict
shubham-y 5aad16d
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
shubham-y 7358662
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
shubham-y 0c2e8ce
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
shubham-y 0ee25fd
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
shubham-y d54f16a
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
shubham-y 4e5aff3
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
shubham-y 9afcbd0
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
shubham-y 0fbfc9a
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
shubham-y cc487d9
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
shubham-y a5ca925
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
shubham-y f01f146
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
shubham-y 558dd2d
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
shubham-y adaf3cb
fixingdoc_duplication
iamYashSinha 8d8232c
fixed linting error
iamYashSinha e88520b
tests added for github_user_id
iamYashSinha 2e0838b
tests added for github_user_id
iamYashSinha 65f4545
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
shubham-y fcac418
added migration route
iamYashSinha a45e5c8
updated the add or update function
iamYashSinha 63cf7d0
Delete firestore-private-key.json
iamYashSinha 45b2f3b
changed to post method
iamYashSinha 9ee96fc
resolved errors in 15 testcases
iamYashSinha 0fb5eca
fixed contribution tests error
iamYashSinha 0d60558
protection on migration route
iamYashSinha 7c6d7aa
required changes done
iamYashSinha e1e57a9
typecast github_user_id field
iamYashSinha a481fb6
added batch api calls and fixed test cases
iamYashSinha 66b6e07
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
shubham-y b25554d
added dynamic batchCount for migration
iamYashSinha 75d682f
fixed tests and batchWrites call
iamYashSinha aa0f615
deleted migration fixtures
iamYashSinha fa249fc
Delete migration.js
iamYashSinha 241df6a
fixed tests and added migration fixture
iamYashSinha 88aaabd
Merge branch 'bugfix/issue957' of https://github.com/iamYashSinha/web…
iamYashSinha 7353c58
fixed tests and added migration fixtures
iamYashSinha e56cd15
removed github_user_id field in migration fixture
iamYashSinha 2bdff72
Merge branch 'Real-Dev-Squad:develop' into bugfix/issue957
iamYashSinha d59ae9e
removed unwanted spaces
iamYashSinha d1b213c
fixed desc of model test
iamYashSinha eccbbd5
replaced res.send and removed validation on github_id
iamYashSinha 9c0fa42
Merge branch 'develop' into bugfix/issue957
iamYashSinha f61ff70
changed the variable name in usersModel
iamYashSinha 7bcdb26
updated tests and replaced res.send
iamYashSinha 348ce2b
fixed failing test cases and status code
iamYashSinha 5247952
removed beforeEach and afterEach block in migration test
iamYashSinha 468b057
made the GitHub API call authenticated
iamYashSinha 1f04c76
fixed the variable name and spacing
iamYashSinha 8e9414e
removed unwanted tests
iamYashSinha 421c736
added a method to find where github_id is not valid
iamYashSinha 3d11b0b
added users data in response, fixed test cases
iamYashSinha 20f0b3e
updated variable name
iamYashSinha 34f235c
fixed sinon test
iamYashSinha ae3bfd8
fixed integration test
iamYashSinha 9569688
fixed sinon.stub and resolves method
iamYashSinha 5484294
fixed sinon.stub timeout
iamYashSinha d20932d
fixed test cases
iamYashSinha 6d309e3
auth token yet to be generated
iamYashSinha 240ccb9
Merge branch 'develop' into bugfix/issue957
iamYashSinha d0ed63c
add missing closing bracket
shubham-y c3bd1db
fix conflict in users integration test file
shubham-y 2dc68a5
Merge branch 'develop' of https://github.com/shubham-y/website-backen…
shubham-y e9a0819
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
shubham-y ed2dfc3
add github_user_id in user fixtures
shubham-y 7b57924
update response data for migrate function
shubham-y 97f0959
update tests for migrate route
shubham-y 0dfda95
update tests for migrate route
shubham-y b2c933e
update response data for migrate function
shubham-y 8158773
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
shubham-y 31ad08a
update controller function
shubham-y 708d57e
refactor tests
shubham-y 7f79193
update integration test
shubham-y File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| const axios = require("axios"); | ||
prakashchoudhary07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const firestore = require("../utils/firestore"); | ||
| const chaincodeQuery = require("../models/chaincodes"); | ||
| const userQuery = require("../models/users"); | ||
| const profileDiffsQuery = require("../models/profileDiffs"); | ||
|
|
@@ -462,6 +464,65 @@ const filterUsers = async (req, res) => { | |
| } | ||
| }; | ||
|
|
||
| // one time script function to perform the migration - adding github_user_id field to the document | ||
| const migrate = async (req, res) => { | ||
RitikJaiswal75 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| try { | ||
| // Fetch user data from GitHub API for each document in the users collection | ||
| const usersSnapshot = await firestore.collection("users").get(); | ||
| const batchSize = Math.ceil(usersSnapshot.docs.length / 2); | ||
| const batch1 = usersSnapshot.docs.slice(0, batchSize); | ||
| const batch2 = usersSnapshot.docs.slice(batchSize); | ||
heyrandhir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const batchWrites = []; | ||
|
|
||
| // Create batch write operations for the first batch of documents | ||
| const batch1Write = firestore.batch(); | ||
| for (const userDoc of batch1) { | ||
| const githubUsername = userDoc.data().github_id; | ||
| batch1Write.update(userDoc.ref, { github_user_id: null }); | ||
| batchWrites.push( | ||
| axios | ||
| .get(`https://api.github.com/users/${githubUsername}`) | ||
| .then((response) => { | ||
| const githubUserId = response.data.id; | ||
| batch1Write.update(userDoc.ref, { github_user_id: `${githubUserId}` }); | ||
heyrandhir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }) | ||
| .catch((error) => { | ||
| res.send(error); | ||
| }) | ||
| ); | ||
| } | ||
|
|
||
| // Create batch write operations for the second batch of documents | ||
| const batch2Write = firestore.batch(); | ||
| for (const userDoc of batch2) { | ||
| const githubUsername = userDoc.data().github_id; | ||
| batch2Write.update(userDoc.ref, { github_user_id: null }); | ||
| batchWrites.push( | ||
| axios | ||
| .get(`https://api.github.com/users/${githubUsername}`) | ||
| .then((response) => { | ||
| const githubUserId = response.data.id; | ||
| batch2Write.update(userDoc.ref, { github_user_id: `${githubUserId}` }); | ||
| }) | ||
| .catch((error) => { | ||
| res.send(error); | ||
| }) | ||
| ); | ||
| } | ||
|
|
||
| // Execute both batch writes in parallel | ||
| await Promise.all(batchWrites); | ||
|
|
||
| // Commit both batch writes to update the Firestore documents | ||
| await batch1Write.commit(); | ||
| await batch2Write.commit(); | ||
|
|
||
| return res.send("Documents updated successfully"); | ||
| } catch (error) { | ||
| return res.status(500).send("Internal server error"); | ||
shubham-y marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| }; | ||
|
|
||
| module.exports = { | ||
| verifyUser, | ||
| generateChaincode, | ||
|
|
@@ -481,4 +542,5 @@ module.exports = { | |
| addDefaultArchivedRole, | ||
| getUserSkills, | ||
| filterUsers, | ||
| migrate, | ||
| }; | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.