Skip to content
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

feat: script to clean up backend emails #1612

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions backend/scripts/emailCleaner.mjs
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;
});

Loading