Skip to content
Snippets Groups Projects
Select Git revision
  • 046f0c6bd877561de6de116622f5fdae14e68e6b
  • main default protected
  • jw_sonar
  • v6.0.0 protected
  • bedran_exercise-list
  • ask-user-to-delete-exercises-on-duplicates
  • update-dependencies
  • jw_sonar_backup
  • add_route_assignments
  • 6.0.0-dev
  • 5.0.1
  • 5.0.0
  • 4.1.0
  • 4.0.0
  • 3.5.3
  • 3.5.2
  • 3.5.1
  • 3.5.0
  • 3.4.2
  • 3.4.1
  • 3.4.0
  • 3.3.0
  • 3.2.0
  • 3.1.3
  • 3.1.2
  • 3.1.1
  • 3.1.0
  • 3.0.1
  • 3.0.0
29 results

AssignmentResultExtension.ts

Blame
  • AssignmentResultExtension.ts 1.80 KiB
    import { Prisma }   from '@prisma/client';
    import { Exercise } from '../../../types/DatabaseTypes.js';
    import db           from '../../DatabaseHelper.js';
    import LazyVal      from '../../../shared/helpers/LazyVal.js';
    
    
    async function getCorrections(assignment: { name: string }): Promise<Array<Partial<Exercise>> | undefined> {
        try {
            return await db.exercise.findMany({
                                                  where  : {
                                                      assignmentName  : assignment.name,
                                                      correctionCommit: {
                                                          not: Prisma.JsonNull
                                                      }
                                                  },
                                                  include: {
                                                      assignment: false,
                                                      members   : true,
                                                      results   : false
                                                  }
                                              }) as Array<Partial<Exercise>> ?? undefined;
        } catch ( e ) {
            return undefined;
        }
    }
    
    export default Prisma.defineExtension(client => {
        return client.$extends({
                                   result: {
                                       assignment: {
                                           corrections: {
                                               compute(assignment) {
                                                   return new LazyVal<Array<Partial<Exercise>> | undefined>(() => getCorrections(assignment));
                                               }
                                           }
                                       }
                                   }
                               });
    });