@@ -154,6 +154,49 @@ const getPracticeSlots = async (req, res, next) => {
154
154
} ;
155
155
156
156
157
+ const getSoltsByDate = async ( req , res , next ) => {
158
+ try {
159
+ const date = req . body . date
160
+ // Fetch practice slots with populated college details
161
+
162
+ const slots = await PracticeSlotModel . find ( { date : new Date ( date ) } ) ;
163
+
164
+ // Check if practice slots are found
165
+ if ( ! slots || slots . length === 0 ) {
166
+ return res . status ( 404 ) . json ( { status : 404 , message : "Practice slots not found" } ) ;
167
+ }
168
+
169
+ // Map the practice slots data to include college name, location, and team details
170
+ const populatedSlots = await Promise . all ( slots . map ( async ( slot ) => {
171
+ const College = await CollegeModel . findById ( slot . college ) ;
172
+ // Check if college is found
173
+ if ( ! College ) {
174
+ throw new Error ( "College not found for practice slot" ) ;
175
+ }
176
+ // Format the data with college name and location
177
+ const slotData = {
178
+ order : slot . number ,
179
+ date :slot . date ,
180
+ college : College . name ,
181
+ location : College . location ,
182
+ team : slot . index
183
+ } ;
184
+ return slotData ;
185
+ } ) ) ;
186
+
187
+ // Return the populated data with college details
188
+ return res . json ( {
189
+ status : 200 ,
190
+ message : "Success" ,
191
+ data : populatedSlots
192
+ } ) ;
193
+ } catch ( error ) {
194
+ console . error ( "Error fetching practice slots:" , error ) ;
195
+ return res . status ( 500 ) . json ( { status : 500 , message : "Internal Server Error" } ) ;
196
+ }
197
+ } ;
198
+
199
+
157
200
158
201
const deletePracticeSlots = async ( req , res ) => {
159
202
const date = req . body . date ;
@@ -167,5 +210,6 @@ const deletePracticeSlots = async (req, res) => {
167
210
module . exports = {
168
211
createPracticeSlot,
169
212
getPracticeSlots,
170
- deletePracticeSlots
213
+ deletePracticeSlots,
214
+ getSoltsByDate
171
215
}
0 commit comments