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

Update campaignApis.ts #1310

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Changes from all commits
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
18 changes: 3 additions & 15 deletions utilities/project-factory/src/server/api/campaignApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,15 +564,6 @@ function convertUserRoles(employees: any[], request: any) {
}
}

function generateHash(input: string): string {
const prime = 31; // Prime number
let hash = 0;
for (let i = 0; i < input.length; i++) {
hash = (hash * prime + input.charCodeAt(i)) % 100000; // Limit hash to 5 digits
}
return hash.toString().padStart(6, '0');
}

function generateUserPassword() {
// Function to generate a random lowercase letter
function getRandomLowercaseLetter() {
Expand Down Expand Up @@ -609,15 +600,12 @@ function generateUserPassword() {


function enrichUserNameAndPassword(employees: any[]) {
const epochTime = Date.now();
employees.forEach((employee) => {
const { user, "!row#number!": rowNumber } = employee;
const nameInitials = user.name.split(' ').map((name: any) => name.charAt(0)).join('');
const generatedCode = `${nameInitials}${generateHash(`${epochTime}`)}${rowNumber}`;
const { user } = employee;
const generatedPassword = config?.user?.userPasswordAutoGenerate == "true" ? generateUserPassword() : config?.user?.userDefaultPassword
user.userName = generatedCode;
user.userName = null;
user.password = generatedPassword;
employee.code = generatedCode
employee.code = null
});
}

Expand Down
Loading