Advertisement
greedydev

Untitled

Nov 5th, 2022 (edited)
1,609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let mergeUsers = (users: Array<UserBase>, additionalInfo) => {
  2.   let res: Array<User> = [];
  3.   for (let additionalUser of additionalInfo) {
  4.     if (users.find(user => user.full_name === additionalUser.full_name) !== undefined) {
  5.       let userToAdd: User = {
  6.         gender: additionalUser.gender.charAt(0).toUpperCase() + additionalUser.gender.slice(1),
  7.         title: additionalUser.title,
  8.         full_name: additionalUser.name,
  9.         city: additionalUser.city,
  10.         state: additionalUser.state,
  11.         country: additionalUser.country,
  12.         postcode: Number(additionalUser.postcode),
  13.         coordinates: additionalUser.coordinates,
  14.         timezone: additionalUser.timezone,
  15.         email: additionalUser.email,
  16.         dob: additionalUser.b_day,
  17.         age: additionalUser.age,
  18.         phone: additionalUser.phone,
  19.         picture_large: additionalUser.picture_large,
  20.         picture_thumbnail: additionalUser.picture_thumbnail,
  21.         id: additionalUser.id === undefined ? uuidv4() : additionalUser.id,
  22.         favorite: additionalUser.favorite,
  23.         course: additionalUser.course === undefined ? getRandomCourse() : additionalUser.course,
  24.         bg_color: additionalUser.bg_color === undefined ? "#ffffff" : additionalUser.bg_color,
  25.         note: additionalUser.note,
  26.       }
  27.       res.push(userToAdd);
  28.     }
  29.   }
  30.   for (let user of users) {
  31.     let details = additionalInfo.find(userDetails => user.full_name === userDetails.full_name);
  32.     if (details !== undefined) {
  33.       let userDetails: Details = {
  34.         id: details.id,
  35.         favorite: details.favorite === null ? false : details.favorite,
  36.         course: details.course === null ? getRandomCourse() : details.course,
  37.         bg_color: details.bg_color === null ? "#ffffff" : details.bg_color,
  38.         note: details.note === null ? "" : details.note,
  39.       }
  40.       res.push({...user, ...userDetails });
  41.     } else {
  42.       let userDetails: Details = {
  43.         id: uuidv4(),
  44.         favorite: false,
  45.         course: getRandomCourse(),
  46.         bg_color: "#ffffff",
  47.         note: "",
  48.       }
  49.       res.push({...user, ...userDetails });
  50.     }
  51.   }
  52.  
  53.   return res;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement