Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions graphql/statistics/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@ export class StatisticsResolver {

@FieldResolver((returns) => [ByMonth])
@Authorized(Role.ADMIN)
async registeredPupilsHavingScreening(@Root() statistics: Statistics) {
return await prisma.$queryRaw`SELECT COUNT(*)::INT AS value,
date_part('year', pupil."createdAt"::date) AS year,
date_part('month', pupil."createdAt"::date) AS month
FROM pupil
LEFT JOIN pupil_screening on pupil_screening."pupilId" = pupil.id
WHERE pupil."createdAt" > ${statistics.from}::timestamp
AND pupil."createdAt" < ${statistics.to}::timestamp
AND (pupil_screening."createdAt" IS NOT NULL)
GROUP BY "year", "month"
ORDER BY "year" ASC, "month" ASC`;
}

async pupilRegistrationsByScreeningStatus(@Root() statistics: Statistics) {
return await prisma.$queryRaw`WITH first_screening AS (
SELECT DISTINCT ON ("pupilId")
Expand Down
Loading