From 12241d52b934f3255d44fedd7c4b7e56f67cf22c Mon Sep 17 00:00:00 2001 From: Nathan Lamy Date: Tue, 19 Aug 2025 19:32:12 +0200 Subject: [PATCH] feat: add health --- app/controllers/user_controller.ts | 5 ++++- app/services/colle_service.ts | 13 +++++++++++++ start/routes.ts | 18 +++++++++--------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/controllers/user_controller.ts b/app/controllers/user_controller.ts index 244a17d..5a9524c 100644 --- a/app/controllers/user_controller.ts +++ b/app/controllers/user_controller.ts @@ -11,7 +11,10 @@ export default class UserController { async me({ auth }: HttpContext) { return { success: true, - data: auth.user, + data: { + ...auth.user?.serialize(), + email: auth.user!.email || '', + }, } } diff --git a/app/services/colle_service.ts b/app/services/colle_service.ts index 917312d..089a509 100644 --- a/app/services/colle_service.ts +++ b/app/services/colle_service.ts @@ -3,8 +3,19 @@ import Examiner from '#models/examiner' import Room from '#models/room' import Subject from '#models/subject' import User from '#models/user' +import redis from '@adonisjs/redis/services/main' export class ColleService { + async getHealthyUntil(className: string) { + const healtyUntil = await redis.get(`healthy_until_${className}`) + return new Date(healtyUntil || '') + } + + async getLastSync(className: string) { + const lastSync = await redis.get(`last_sync_${className}`) + return new Date(lastSync || '') + } + async getStudent(studentName: string, className: string) { // Find or create a student by name const { firstName, lastName } = this.splitNames(studentName) @@ -90,6 +101,8 @@ export class ColleService { classColles, studentColles, favoriteColles, + healthyUntil: await this.getHealthyUntil(student.className), + lastSync: await this.getLastSync(student.className), } } diff --git a/start/routes.ts b/start/routes.ts index ad2442b..0b8b2e1 100644 --- a/start/routes.ts +++ b/start/routes.ts @@ -37,16 +37,16 @@ const SubjectsController = () => import('#controllers/subjects_controller') router.get('/subjects', [SubjectsController, 'index']).use(middleware.auth()) // TEST ROUTE -import redis from '@adonisjs/redis/services/main' +// import redis from '@adonisjs/redis/services/main' -router.get('/', async () => { - await redis.publish("jobs_queue", JSON.stringify({ - type: 1, - date: "20/09/2019", - class_name: "MPSI 2", - })) - return { message: 'Hello, world!' } -}) +// router.get('/', async () => { +// await redis.publish("jobs_queue", JSON.stringify({ +// type: 1, +// date: "20/09/2019", +// class_name: "MPSI 2", +// })) +// return { message: 'Hello, world!' } +// }) // END TEST ROUTE const CollesController = () => import('#controllers/colles_controller')