@@ -101,6 +101,28 @@ router.get('/courses', async (req, res) => {
101101 res . send ( courseUnitRealisationsWithCourseUnits )
102102} )
103103
104+ router . get ( '/courses/count' , async ( req , res ) => {
105+ const courseStartTreshold = addMonths ( new Date ( ) , 48 )
106+
107+ const courseUnitRealisationsCount = await models . CourseUnitRealisation . count ( {
108+ where : {
109+ [ Op . and ] : [
110+ {
111+ 'activityPeriod.endDate' : {
112+ [ Op . gte ] : new Date ( )
113+ }
114+ } ,
115+ {
116+ 'activityPeriod.startDate' : {
117+ [ Op . lte ] : courseStartTreshold
118+ }
119+ }
120+ ]
121+ }
122+ } )
123+ res . json ( courseUnitRealisationsCount )
124+ } )
125+
104126apparaattiRouter . get ( '/enrolments-new' , async ( req , res ) => {
105127 const { since : sinceRaw , limit, offset } = req . query
106128 if ( ! limit || ! offset ) return res . sendStatus ( 400 )
@@ -141,6 +163,12 @@ apparaattiRouter.get('/persons', async (req, res) => {
141163 res . send ( persons )
142164} )
143165
166+ apparaattiRouter . get ( '/persons/count' , async ( req , res ) => {
167+ const personsCount = await models . Person . count ( )
168+
169+ res . json ( personsCount )
170+ } )
171+
144172const getEducationByIdForStudyright = async id => {
145173 try {
146174 const education = await models . Education . findOne ( {
@@ -237,6 +265,15 @@ apparaattiRouter.get('/studyrights', async (req, res) => {
237265 }
238266} )
239267
268+ apparaattiRouter . get ( '/studyrights/count' , async ( req , res ) => {
269+ try {
270+ const studyRights = await models . StudyRight . count ( )
271+ return res . json ( studyRights )
272+ } catch ( e ) {
273+ res . status ( 500 ) . json ( e . toString ( ) )
274+ }
275+ } )
276+
240277//this is partially taken from archeology.js
241278apparaattiRouter . get ( '/:studentNumber/studyrights' , async ( req , res ) => {
242279 try {
@@ -329,6 +366,24 @@ apparaattiRouter.get('/organisations', async (req, res) => {
329366 res . send ( organisations )
330367} )
331368
369+ apparaattiRouter . get ( '/organisations/count' , async ( req , res ) => {
370+ const { limit, offset } = req . query
371+ if ( ! limit || ! offset ) return res . sendStatus ( 400 )
372+
373+ const organisations = await models . Organisation . count ( {
374+ where : {
375+ [ Op . and ] : [
376+ // Only latest snapshot
377+ models . Organisation . sequelize . literal (
378+ '(code, snapshot_date_time) in (select code, max(snapshot_date_time) from organisations group by code)'
379+ )
380+ ]
381+ }
382+ } )
383+
384+ res . json ( organisations )
385+ } )
386+
332387router . use ( '/' , apparaattiRouter )
333388
334389module . exports = router
0 commit comments