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, | ||||
|       startTime: true, | ||||
|       endTime: true, | ||||
|       availability: true, | ||||
|     } | ||||
|   }); | ||||
| 
 | ||||
|  | @ -392,29 +393,19 @@ export async function getServerSideProps(context) { | |||
|       length: true, | ||||
|       hidden: true, | ||||
|       locations: true, | ||||
|       availability: true, | ||||
|     } | ||||
|   }); | ||||
| 
 | ||||
|   let schedules = await prisma.schedule.findMany({ | ||||
|     where: { | ||||
|       eventTypeId: parseInt(context.query.type), | ||||
|     }, | ||||
|   }); | ||||
|   const getAvailability = (providesAvailability) => ( | ||||
|     providesAvailability.availability && providesAvailability.availability.length | ||||
|   ) ? providesAvailability.availability : null; | ||||
| 
 | ||||
|   if (!schedules.length) { | ||||
|     schedules = await prisma.schedule.findMany({ | ||||
|       where: { | ||||
|         userId: user.id, | ||||
|       }, | ||||
|     }); | ||||
|     if (!schedules.length) { | ||||
|       schedules.push({ | ||||
|   const schedules = getAvailability(eventType) || getAvailability(user) || [ { | ||||
|     days: [ 1, 2, 3, 4, 5, 6, 7 ], | ||||
|     startTime: user.startTime, | ||||
|     length: user.endTime >= 1440 ? 1439 : user.endTime, | ||||
|       }); | ||||
|     } | ||||
|   } | ||||
|   } ]; | ||||
| 
 | ||||
|   return { | ||||
|     props: { | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Alex van Andel
						Alex van Andel