Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let mergeUsers = (users: Array<UserBase>, additionalInfo) => {
- let res: Array<User> = [];
- for (let additionalUser of additionalInfo) {
- if (users.find(user => user.full_name === additionalUser.full_name) !== undefined) {
- let userToAdd: User = {
- gender: additionalUser.gender.charAt(0).toUpperCase() + additionalUser.gender.slice(1),
- title: additionalUser.title,
- full_name: additionalUser.name,
- city: additionalUser.city,
- state: additionalUser.state,
- country: additionalUser.country,
- postcode: Number(additionalUser.postcode),
- coordinates: additionalUser.coordinates,
- timezone: additionalUser.timezone,
- email: additionalUser.email,
- dob: additionalUser.b_day,
- age: additionalUser.age,
- phone: additionalUser.phone,
- picture_large: additionalUser.picture_large,
- picture_thumbnail: additionalUser.picture_thumbnail,
- id: additionalUser.id === undefined ? uuidv4() : additionalUser.id,
- favorite: additionalUser.favorite,
- course: additionalUser.course === undefined ? getRandomCourse() : additionalUser.course,
- bg_color: additionalUser.bg_color === undefined ? "#ffffff" : additionalUser.bg_color,
- note: additionalUser.note,
- }
- res.push(userToAdd);
- }
- }
- for (let user of users) {
- let details = additionalInfo.find(userDetails => user.full_name === userDetails.full_name);
- if (details !== undefined) {
- let userDetails: Details = {
- id: details.id,
- favorite: details.favorite === null ? false : details.favorite,
- course: details.course === null ? getRandomCourse() : details.course,
- bg_color: details.bg_color === null ? "#ffffff" : details.bg_color,
- note: details.note === null ? "" : details.note,
- }
- res.push({...user, ...userDetails });
- } else {
- let userDetails: Details = {
- id: uuidv4(),
- favorite: false,
- course: getRandomCourse(),
- bg_color: "#ffffff",
- note: "",
- }
- res.push({...user, ...userDetails });
- }
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement