| 
									
										
										
										
											2018-02-16 23:18:53 +00:00
										 |  |  | import { isURL } from 'validator'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-19 20:32:14 +00:00
										 |  |  | import { addPlaceholderImage } from './'; | 
					
						
							| 
									
										
										
										
											2018-02-16 23:18:53 +00:00
										 |  |  | import { | 
					
						
							|  |  |  |   prepUniqueDaysByHours, | 
					
						
							|  |  |  |   calcCurrentStreak, | 
					
						
							|  |  |  |   calcLongestStreak | 
					
						
							|  |  |  | } from '../utils/user-stats'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const publicUserProps = [ | 
					
						
							|  |  |  |   'about', | 
					
						
							|  |  |  |   'calendar', | 
					
						
							| 
									
										
										
										
											2018-05-15 14:56:26 +01:00
										 |  |  |   'completedChallenges', | 
					
						
							|  |  |  |   'githubProfile', | 
					
						
							| 
									
										
										
										
											2018-02-16 23:18:53 +00:00
										 |  |  |   'isApisMicroservicesCert', | 
					
						
							|  |  |  |   'isBackEndCert', | 
					
						
							|  |  |  |   'isCheater', | 
					
						
							| 
									
										
										
										
											2018-02-27 14:03:06 +00:00
										 |  |  |   'is2018DataVisCert', | 
					
						
							| 
									
										
										
										
											2018-02-16 23:18:53 +00:00
										 |  |  |   'isDataVisCert', | 
					
						
							|  |  |  |   'isFrontEndCert', | 
					
						
							|  |  |  |   'isFullStackCert', | 
					
						
							|  |  |  |   'isFrontEndLibsCert', | 
					
						
							|  |  |  |   'isHonest', | 
					
						
							|  |  |  |   'isInfosecQaCert', | 
					
						
							|  |  |  |   'isJsAlgoDataStructCert', | 
					
						
							|  |  |  |   'isRespWebDesignCert', | 
					
						
							|  |  |  |   'linkedin', | 
					
						
							|  |  |  |   'location', | 
					
						
							|  |  |  |   'name', | 
					
						
							|  |  |  |   'points', | 
					
						
							|  |  |  |   'portfolio', | 
					
						
							| 
									
										
										
										
											2018-05-20 04:07:41 +01:00
										 |  |  |   'profileUI', | 
					
						
							| 
									
										
										
										
											2018-02-16 23:18:53 +00:00
										 |  |  |   'projects', | 
					
						
							|  |  |  |   'streak', | 
					
						
							|  |  |  |   'twitter', | 
					
						
							|  |  |  |   'username', | 
					
						
							|  |  |  |   'website' | 
					
						
							|  |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const userPropsForSession = [ | 
					
						
							|  |  |  |   ...publicUserProps, | 
					
						
							|  |  |  |   'currentChallengeId', | 
					
						
							|  |  |  |   'email', | 
					
						
							| 
									
										
										
										
											2018-05-28 22:52:15 +01:00
										 |  |  |   'emailVerified', | 
					
						
							| 
									
										
										
										
											2018-02-16 23:18:53 +00:00
										 |  |  |   'id', | 
					
						
							|  |  |  |   'sendQuincyEmail', | 
					
						
							|  |  |  |   'theme' | 
					
						
							|  |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function normaliseUserFields(user) { | 
					
						
							|  |  |  |   const about = user.bio && !user.about ? user.bio : user.about; | 
					
						
							|  |  |  |   const picture = user.picture || addPlaceholderImage(user.username); | 
					
						
							|  |  |  |   const twitter = user.twitter && isURL(user.twitter) ? | 
					
						
							|  |  |  |     user.twitter : | 
					
						
							|  |  |  |     user.twitter && `https://www.twitter.com/${user.twitter.replace(/^@/, '')}`; | 
					
						
							|  |  |  |   return { about, picture, twitter }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function getProgress(progressTimestamps, timezone = 'EST') { | 
					
						
							|  |  |  |   const calendar = progressTimestamps | 
					
						
							| 
									
										
										
										
											2018-05-15 14:56:26 +01:00
										 |  |  |     .filter(Boolean) | 
					
						
							|  |  |  |     .reduce((data, timestamp) => { | 
					
						
							|  |  |  |       data[Math.floor(timestamp / 1000)] = 1; | 
					
						
							| 
									
										
										
										
											2018-02-16 23:18:53 +00:00
										 |  |  |       return data; | 
					
						
							|  |  |  |   }, {}); | 
					
						
							| 
									
										
										
										
											2018-05-15 14:56:26 +01:00
										 |  |  |   const uniqueHours = prepUniqueDaysByHours(progressTimestamps, timezone); | 
					
						
							| 
									
										
										
										
											2018-02-16 23:18:53 +00:00
										 |  |  |   const streak = { | 
					
						
							|  |  |  |     longest: calcLongestStreak(uniqueHours, timezone), | 
					
						
							|  |  |  |     current: calcCurrentStreak(uniqueHours, timezone) | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   return { calendar, streak }; | 
					
						
							|  |  |  | } |