Skip to content
Snippets Groups Projects
Commit c8590e80 authored by michael.minelli's avatar michael.minelli
Browse files

Prisma => Add extensions with corrections informations

parent 60df9b0e
No related branches found
No related tags found
No related merge requests found
import { Prisma } from '@prisma/client';
import { Exercise } from '../../../types/DatabaseTypes';
import db from '../../DatabaseHelper';
import LazyVal from '../../../shared/helpers/LazyVal';
async function getCorrections(assignment: { name: string }): Promise<Array<Exercise> | undefined> {
try {
return await db.exercise.findMany({
where: {
assignmentName : assignment.name,
correctionCommit: {
not: Prisma.JsonNull
}
}
}) as Array<Exercise> ?? undefined;
} catch ( e ) {
return undefined;
}
}
export default Prisma.defineExtension(client => {
return client.$extends({
result: {
assignment: {
corrections: {
compute(assignment) {
return new LazyVal<Array<Exercise> | undefined>(() => {
return getCorrections(assignment);
});
}
}
}
}
});
});
\ No newline at end of file
import { Prisma } from '@prisma/client';
export default Prisma.defineExtension(client => {
return client.$extends({
result: {
exercise: {
isCorrection: {
needs: {
correctionCommit: true
},
compute(exercise) {
return exercise.correctionCommit != null;
}
}
}
}
});
});
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment