@@ -287,6 +287,55 @@ async function getHubbleMeasurementsForStudentClass(studentID: number,
287
287
} ) ;
288
288
}
289
289
290
+ export async function getClassMeasurements ( classID : number ,
291
+ includeMergedClasses : boolean = true ,
292
+ excludeWithNull : boolean = false
293
+ ) : Promise < HubbleMeasurement [ ] > {
294
+
295
+ const classWhereConditions : WhereOptions < Class > = [ ] ;
296
+ if ( includeMergedClasses ) {
297
+ const classIDs = await getMergedIDsForClass ( classID ) ;
298
+ classWhereConditions . push ( { id : { [ Op . in ] : classIDs } } ) ;
299
+ } else {
300
+ classWhereConditions . push ( { id : classID } ) ;
301
+ }
302
+
303
+ const measurementWhereConditions : WhereOptions < HubbleMeasurement > = [ ] ;
304
+ if ( excludeWithNull ) {
305
+ measurementWhereConditions . push ( EXCLUDE_MEASUREMENTS_WITH_NULL_CONDITION ) ;
306
+ }
307
+
308
+ return HubbleMeasurement . findAll ( {
309
+ where : measurementWhereConditions ,
310
+ include : [ {
311
+ model : Student ,
312
+ attributes : [ "id" ] ,
313
+ as : "student" ,
314
+ required : true ,
315
+ include : [ {
316
+ model : Class ,
317
+ attributes : [ "id" ] ,
318
+ where : classWhereConditions ,
319
+ } ,
320
+ {
321
+ model : IgnoreStudent ,
322
+ required : false ,
323
+ attributes : [ ] ,
324
+ where : {
325
+ story_name : "hubbles_law" ,
326
+ student_id : { [ Op . is ] : null } ,
327
+ }
328
+ } ] ,
329
+ } ,
330
+ {
331
+ model : Galaxy ,
332
+ attributes : galaxyAttributes ,
333
+ as : "galaxy" ,
334
+ required : true ,
335
+ } ]
336
+ } ) ;
337
+ }
338
+
290
339
async function getHubbleStudentDataForClasses ( classIDs : number [ ] ) : Promise < HubbleStudentData [ ] > {
291
340
return HubbleStudentData . findAll ( {
292
341
include : [ {
@@ -390,11 +439,11 @@ export async function getClassDataIDsForStudent(studentID: number): Promise<numb
390
439
return state ?. getDataValue ( "class_data_students" ) ?? [ ] ;
391
440
}
392
441
393
- export async function getClassMeasurements ( studentID : number ,
394
- classID : number ,
395
- lastChecked : number | null = null ,
396
- excludeWithNull : boolean = false ,
397
- excludeStudent : boolean = false ,
442
+ export async function getClassMeasurementsForStudent ( studentID : number ,
443
+ classID : number ,
444
+ lastChecked : number | null = null ,
445
+ excludeWithNull : boolean = false ,
446
+ excludeStudent : boolean = false ,
398
447
) : Promise < HubbleMeasurement [ ] > {
399
448
let data = await getHubbleMeasurementsForStudentClass ( studentID , classID , excludeWithNull , excludeStudent ) ;
400
449
if ( data . length > 0 && lastChecked != null ) {
@@ -409,11 +458,11 @@ export async function getClassMeasurements(studentID: number,
409
458
// The advantage of this over the function above is that it saves bandwidth,
410
459
// since we aren't sending the data itself.
411
460
// This is intended to be used with cases where we need to frequently check the number of measurements
412
- export async function getClassMeasurementCount ( studentID : number ,
413
- classID : number ,
414
- excludeWithNull : boolean = false ,
461
+ export async function getClassMeasurementCountForStudent ( studentID : number ,
462
+ classID : number ,
463
+ excludeWithNull : boolean = false ,
415
464
) : Promise < number > {
416
- const data = await getClassMeasurements ( studentID , classID , null , excludeWithNull ) ;
465
+ const data = await getClassMeasurementsForStudent ( studentID , classID , null , excludeWithNull ) ;
417
466
return data ?. length ?? 0 ;
418
467
}
419
468
0 commit comments