import ExpressPromiseRouter from 'express-promise-router' ; var router = ExpressPromiseRouter ( ) ; import NotificationService = require ( '@app/core/notification/NotificationService' ) ; import User from '@app/core/user/model/User' ; import UserService = require ( '@app/core/user/UserService' ) ; import { restGet } from '../decorator/RestDecorator' ; import UserAuthorizeMiddleware from '../middleware/UserAuthorizeMiddleware' ; router . use ( UserAuthorizeMiddleware ) ; restGet ( router , '/' ) ( async function ( context , req ) { var user = context . user ; var offset , limit ; if ( ! req . query . offset ) offset = 0 ; else offset = Number ( req . query . offset ) ; if ( ! req . query . limit ) limit = 20 ; else limit = Number ( req . query . limit ) ; let notification = await NotificationService . getNewestByUser ( user , offset , limit ) ; if ( req . query . explicit ) await UserService . updateNotificationCheckDate ( user ) ; return notification ; } ) ; restGet ( router , '/count' ) ( async function ( context , req ) { var user = context . user ; let count = await NotificationService . countUnreadByUser ( user ) ; return { count : count } ; } ) ; export = router ;