File tree Expand file tree Collapse file tree 3 files changed +73
-72
lines changed
Expand file tree Collapse file tree 3 files changed +73
-72
lines changed Original file line number Diff line number Diff line change 1+ import { prisma } from '@utils/prisma' ;
2+
3+ export interface AbsenceWithRelations {
4+ lessonDate : Date ;
5+ lessonPlan : string | null ;
6+ reasonOfAbsence : string ;
7+ notes : string | null ;
8+ absentTeacher : {
9+ firstName : string ;
10+ lastName : string ;
11+ email : string ;
12+ } ;
13+ substituteTeacher : {
14+ firstName : string ;
15+ lastName : string ;
16+ email : string ;
17+ } | null ;
18+ location : {
19+ name : string ;
20+ abbreviation : string ;
21+ } ;
22+ subject : {
23+ name : string ;
24+ abbreviation : string ;
25+ } ;
26+ }
27+
28+ export const searchAbsences = async ( ) : Promise < AbsenceWithRelations [ ] > => {
29+ try {
30+ const absences : AbsenceWithRelations [ ] = await prisma . absence . findMany ( {
31+ select : {
32+ lessonDate : true ,
33+ subject : {
34+ select : {
35+ name : true ,
36+ abbreviation : true ,
37+ } ,
38+ } ,
39+ lessonPlan : true ,
40+ reasonOfAbsence : true ,
41+ notes : true ,
42+ absentTeacher : {
43+ select : {
44+ firstName : true ,
45+ lastName : true ,
46+ email : true ,
47+ } ,
48+ } ,
49+ substituteTeacher : {
50+ select : {
51+ firstName : true ,
52+ lastName : true ,
53+ email : true ,
54+ } ,
55+ } ,
56+ location : {
57+ select : {
58+ name : true ,
59+ abbreviation : true ,
60+ } ,
61+ } ,
62+ } ,
63+ } ) ;
64+
65+ return absences ;
66+ } catch ( err ) {
67+ console . error ( 'Error fetching absences:' , err ) ;
68+ throw err ;
69+ }
70+ } ;
Original file line number Diff line number Diff line change 1- import { prisma } from '@utils/prisma' ;
21import { NextResponse } from 'next/server' ;
3-
4- export interface AbsenceWithRelations {
5- lessonDate : Date ;
6- lessonPlan : string | null ;
7- reasonOfAbsence : string ;
8- notes : string | null ;
9- absentTeacher : {
10- firstName : string ;
11- lastName : string ;
12- email : string ;
13- } ;
14- substituteTeacher : {
15- firstName : string ;
16- lastName : string ;
17- email : string ;
18- } | null ;
19- location : {
20- name : string ;
21- abbreviation : string ;
22- } ;
23- subject : {
24- name : string ;
25- abbreviation : string ;
26- } ;
27- }
28-
29- export const searchAbsences = async ( ) : Promise < AbsenceWithRelations [ ] > => {
30- try {
31- const absences : AbsenceWithRelations [ ] = await prisma . absence . findMany ( {
32- select : {
33- lessonDate : true ,
34- subject : {
35- select : {
36- name : true ,
37- abbreviation : true ,
38- } ,
39- } ,
40- lessonPlan : true ,
41- reasonOfAbsence : true ,
42- notes : true ,
43- absentTeacher : {
44- select : {
45- firstName : true ,
46- lastName : true ,
47- email : true ,
48- } ,
49- } ,
50- substituteTeacher : {
51- select : {
52- firstName : true ,
53- lastName : true ,
54- email : true ,
55- } ,
56- } ,
57- location : {
58- select : {
59- name : true ,
60- abbreviation : true ,
61- } ,
62- } ,
63- } ,
64- } ) ;
65-
66- return absences ;
67- } catch ( err ) {
68- console . error ( 'Error fetching absences:' , err ) ;
69- throw err ;
70- }
71- } ;
2+ import { AbsenceWithRelations , searchAbsences } from './absences' ;
723
734export async function GET ( ) {
745 try {
75- const absences = await searchAbsences ( ) ;
6+ const absences : AbsenceWithRelations [ ] = await searchAbsences ( ) ;
767
778 if ( ! absences . length ) {
789 return NextResponse . json ( { events : [ ] } , { status : 200 } ) ;
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { getAbsenceEvents, createCalendarFile } from './ics';
33
44const getICSFileById = async ( id : string ) => {
55 console . log ( 'Getting ICS file for id:' , id ) ;
6- let events = await getAbsenceEvents ( ) ;
6+ const events = await getAbsenceEvents ( ) ;
77 return createCalendarFile ( events ) ;
88} ;
99
You can’t perform that action at this time.
0 commit comments