Skip to content

Commit

Permalink
Update campaignApis.ts (#1310)
Browse files Browse the repository at this point in the history
* Update campaignApis.ts

* Update campaignApis.ts
  • Loading branch information
ashish-egov authored Aug 21, 2024
1 parent 69abd2c commit fd3da43
Showing 1 changed file with 3 additions and 15 deletions.
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

0 comments on commit fd3da43

Please sign in to comment.