generated from hackforla/.github-hackforla-base-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added scripts to backend folder with json data
- Loading branch information
1 parent
d29446f
commit 9c349e8
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
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,33 @@ | ||
import jsonData from './test-data.json' assert {type: 'json'}; | ||
|
||
const emailMap = {}; | ||
|
||
jsonData.forEach(user => { | ||
const lowercaseEmail = user.email.toLowerCase(); | ||
if (!emailMap[lowercaseEmail]) { | ||
emailMap[lowercaseEmail] = user; | ||
} else { | ||
const existingUser = emailMap[lowercaseEmail]; | ||
existingUser.skillsToMatch.push(...user.skillsToMatch); | ||
existingUser.projects.push(...user.projects); | ||
existingUser.managedProjects.push(...user.managedProjects); | ||
existingUser.textingOk = existingUser.textingOk || user.textingOk; | ||
existingUser.isActive = existingUser.isActive || user.isActive; | ||
existingUser.newMember = existingUser.newMember || user.newMember; | ||
existingUser.currentRole = existingUser !== user ? existingUser.currentRole : user.currentRole; | ||
existingUser.desiredRole = existingUser !== user ? existingUser.desiredRole : user.desiredRole; | ||
|
||
if (existingUser.accessLevel === 'admin' || user.accessLevel === 'admin') { | ||
existingUser.accessLevel = 'admin'; | ||
} | ||
// Preserving the older createdDate, firstAttended and modifying the email | ||
if (new Date(user.createdDate) < new Date(existingUser.createdDate)) { | ||
existingUser.createdDate = user.createdDate; | ||
existingUser.firstAttended = user.firstAttended; | ||
existingUser.email = `${user.email.toLowerCase()}_${user._id}` | ||
} | ||
} | ||
// Always lowercase email | ||
user.email = lowercaseEmail; | ||
}); | ||
|