Cleaned up loading the availability schedule
This commit is contained in:
		
							parent
							
								
									9d5186f1e3
								
							
						
					
					
						commit
						e3dbc52676
					
				
					 1 changed files with 10 additions and 19 deletions
				
			
		|  | @ -377,6 +377,7 @@ export async function getServerSideProps(context) { | ||||||
|       timeZone: true, |       timeZone: true, | ||||||
|       startTime: true, |       startTime: true, | ||||||
|       endTime: true, |       endTime: true, | ||||||
|  |       availability: true, | ||||||
|     } |     } | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|  | @ -392,29 +393,19 @@ export async function getServerSideProps(context) { | ||||||
|       length: true, |       length: true, | ||||||
|       hidden: true, |       hidden: true, | ||||||
|       locations: true, |       locations: true, | ||||||
|  |       availability: true, | ||||||
|     } |     } | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   let schedules = await prisma.schedule.findMany({ |   const getAvailability = (providesAvailability) => ( | ||||||
|     where: { |     providesAvailability.availability && providesAvailability.availability.length | ||||||
|       eventTypeId: parseInt(context.query.type), |   ) ? providesAvailability.availability : null; | ||||||
|     }, |  | ||||||
|   }); |  | ||||||
| 
 | 
 | ||||||
|   if (!schedules.length) { |   const schedules = getAvailability(eventType) || getAvailability(user) || [ { | ||||||
|     schedules = await prisma.schedule.findMany({ |     days: [ 1, 2, 3, 4, 5, 6, 7 ], | ||||||
|       where: { |     startTime: user.startTime, | ||||||
|         userId: user.id, |     length: user.endTime >= 1440 ? 1439 : user.endTime, | ||||||
|       }, |   } ]; | ||||||
|     }); |  | ||||||
|     if (!schedules.length) { |  | ||||||
|       schedules.push({ |  | ||||||
|         days: [ 1, 2, 3, 4, 5, 6, 7 ], |  | ||||||
|         startTime: user.startTime, |  | ||||||
|         length: user.endTime >= 1440 ? 1439 : user.endTime, |  | ||||||
|       }); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| 
 | 
 | ||||||
|   return { |   return { | ||||||
|     props: { |     props: { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Alex van Andel
						Alex van Andel