diff --git a/apps/core/src/modules/Public/public.module.ts b/apps/core/src/modules/Public/public.module.ts index 705b64f1..4254f785 100644 --- a/apps/core/src/modules/Public/public.module.ts +++ b/apps/core/src/modules/Public/public.module.ts @@ -1,8 +1,6 @@ import { statusRoute } from './status/route.js'; import { summaryRoute } from './summary/route.js'; -import { statsGeneralRoute } from './stats/general/general.route.js'; -import { statsStudentRoute } from './stats/students/student.route.js'; -import { statsDisciplinaRoute } from './stats/disciplinas/disciplinaStats.route.js'; +import { publicStatsRoute } from './stats/stats.route.js'; import type { FastifyInstance } from 'fastify'; export async function publicModule(app: FastifyInstance) { @@ -12,13 +10,7 @@ export async function publicModule(app: FastifyInstance) { await app.register(statusRoute, { prefix: '/public', }); - await app.register(statsGeneralRoute, { - prefix: '/public', - }); - await app.register(statsStudentRoute, { - prefix: '/public', - }); - await app.register(statsDisciplinaRoute, { + await app.register(publicStatsRoute, { prefix: '/public', }); } diff --git a/apps/core/src/modules/Public/stats/disciplinas/disciplinaStats.handler.ts b/apps/core/src/modules/Public/stats/disciplinas/disciplinaStats.handler.ts deleted file mode 100644 index 758d557f..00000000 --- a/apps/core/src/modules/Public/stats/disciplinas/disciplinaStats.handler.ts +++ /dev/null @@ -1,203 +0,0 @@ -import { courseId, type currentQuad } from '@next/common'; -import { type Component, ComponentModel } from '@/models/Component.js'; -import { type Student, StudentModel } from '@/models/Student.js'; -import type { FastifyReply, FastifyRequest } from 'fastify'; -import type { FilterQuery } from 'mongoose'; - -type Season = ReturnType; - -type DisciplinaStatsRequest = { - Querystring: { - season: Season; - turno: 'noturno' | 'diurno'; - curso_id: number; - ratio: number; - limit: number; - page: number; - }; - Params: { - action: 'overview' | 'disciplines' | 'courses'; - }; -}; - -export class DisciplinaStatsHandler { - async disciplinaStats( - request: FastifyRequest, - reply: FastifyReply, - ) { - const { action } = request.params; - const { season, turno, curso_id, ratio, limit, page } = Object.assign( - request.query, - { - limit: 10, - page: 0, - }, - ); - - if (!season) { - return reply.badRequest('Missing season'); - } - - // check if query has been made - const match: FilterQuery = { - season, - }; - - if (turno) { - match.turno = turno; - } - - if (curso_id) { - // get interCourseIds - const interIds = [ - await courseId( - 'Bacharelado em Ciência e Tecnologia', - season, - StudentModel, - ), - await courseId( - 'Bacharelado em Ciências e Humanidades', - season, - StudentModel, - ), - ]; - match.obrigatorias = { $in: [curso_id] }; - - // if passed course is not a BI, take BIs off query - if (!interIds.includes(curso_id)) { - match.obrigatorias.$nin = interIds; - } - } - - // check if we are dealing with previous data or current - const isPrevious = await ComponentModel.countDocuments({ - season, - before_kick: { $exists: true, $ne: [] }, - }); - const dataKey = isPrevious ? '$before_kick' : '$alunos_matriculados'; - - const stats = ComponentModel.aggregate([ - { - $match: { match }, - }, - { - $project: { - vagas: 1, - turno: 1, - codigo: 1, - disciplina: 1, - obrigatorias: 1, - turma: 1, - requisicoes: { $size: { $ifNull: [dataKey, []] } }, - }, - }, - { $match: { vagas: { $gt: 0 } } }, - { - $project: { - vagas: 1, - turno: 1, - codigo: 1, - disciplina: 1, - obrigatorias: 1, - requisicoes: 1, - turma: 1, - deficit: { $subtract: ['$requisicoes', '$vagas'] }, - ratio: { $divide: ['$requisicoes', '$vagas'] }, - }, - }, - ...(ratio !== null ? [{ $match: { ratio: { $gt: ratio } } }] : []), - ...(action === 'overview' - ? [ - { - $group: { - _id: null, - vagas: { $sum: '$vagas' }, - requisicoes: { $sum: '$requisicoes' }, - deficit: { $sum: '$deficit' }, - }, - }, - ] - : action === 'disciplines' - ? [ - { - $group: { - _id: '$codigo', - disciplina: { $first: '$disciplina' }, - vagas: { $sum: '$vagas' }, - requisicoes: { $sum: '$requisicoes' }, - }, - }, - { - $project: { - disciplina: 1, - vagas: 1, - requisicoes: 1, - codigo: 1, - deficit: { $subtract: ['$requisicoes', '$vagas'] }, - ratio: { $divide: ['$requisicoes', '$vagas'] }, - }, - }, - ] - : action === 'courses' - ? [ - { $unwind: '$obrigatorias' }, - { $match: match }, - { - $group: { - _id: '$obrigatorias', - obrigatorias: { $first: '$obrigatorias' }, - disciplina: { $first: '$disciplina' }, - vagas: { $sum: '$vagas' }, - requisicoes: { $sum: '$requisicoes' }, - }, - }, - { - $project: { - vagas: 1, - requisicoes: 1, - deficit: { $subtract: ['$requisicoes', '$vagas'] }, - ratio: { $divide: ['$requisicoes', '$vagas'] }, - }, - }, - ] - : []), - { - $facet: { - total: [{ $count: 'total' }], - data: [ - { $sort: { [ratio != null ? 'ratio' : 'deficit']: -1 } }, - { $skip: page * limit }, - { $limit: limit }, - { - $project: { - codigo: 1, - disciplina: 1, - turma: 1, - turno: 1, - vagas: 1, - requisicoes: 1, - deficit: 1, - ratio: 1, - }, - }, - ], - }, - }, - { - $addFields: { - total: { $ifNull: [{ $arrayElemAt: ['$total.total', 0] }, 0] }, - page, - }, - }, - { - $project: { - total: 1, - data: 1, - page: 1, - }, - }, - ]); - - return stats; - } -} diff --git a/apps/core/src/modules/Public/stats/disciplinas/disciplinaStats.route.ts b/apps/core/src/modules/Public/stats/disciplinas/disciplinaStats.route.ts deleted file mode 100644 index 29b45309..00000000 --- a/apps/core/src/modules/Public/stats/disciplinas/disciplinaStats.route.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { DisciplinaStatsHandler } from './disciplinaStats.handler.js'; -import { disciplinaStatsSchema } from './disciplinaStats.schema.js'; -import type { FastifyInstance } from 'fastify'; - - -export async function statsDisciplinaRoute(app: FastifyInstance) { - const disciplinaStatsHandler = new DisciplinaStatsHandler(); - app.get( - "/stats/disciplinas/:action", - { schema: disciplinaStatsSchema }, - disciplinaStatsHandler.disciplinaStats, - ); -} diff --git a/apps/core/src/modules/Public/stats/disciplinas/disciplinaStats.schema.ts b/apps/core/src/modules/Public/stats/disciplinas/disciplinaStats.schema.ts deleted file mode 100644 index 16c8c4a9..00000000 --- a/apps/core/src/modules/Public/stats/disciplinas/disciplinaStats.schema.ts +++ /dev/null @@ -1,6 +0,0 @@ -import type { FastifySchema } from "fastify"; - -export const disciplinaStatsSchema = { - tags: ["Public"], - description: "Rota para obter estatísticas de disciplinas baseado em uma ação", -} satisfies FastifySchema; \ No newline at end of file diff --git a/apps/core/src/modules/Public/stats/general/general.handlers.ts b/apps/core/src/modules/Public/stats/general/general.handlers.ts deleted file mode 100644 index a0d65253..00000000 --- a/apps/core/src/modules/Public/stats/general/general.handlers.ts +++ /dev/null @@ -1,96 +0,0 @@ -import { CommentModel } from '@/models/Comment.js'; -import { ComponentModel } from '@/models/Component.js'; -import { EnrollmentModel } from '@/models/Enrollment.js'; -import { StudentModel } from '@/models/Student.js'; -import { UserModel } from '@/models/User.js'; -import type { currentQuad } from '@next/common'; -import type { FastifyReply, FastifyRequest } from 'fastify'; - -type Season = ReturnType; - -export class GeneralStatsHandler { - async generalStats( - request: FastifyRequest<{ Querystring: { season: Season } }>, - reply: FastifyReply, - ) { - const { season } = request.query; - if (!season) { - return reply.badRequest('Missing season'); - } - - const teacherCountQuery = [ - { - $group: { - _id: null, - teoria: { $addToSet: '$teoria' }, - pratica: { $addToSet: '$pratica' }, - }, - }, - { - $project: { teachers: { $setUnion: ['$teoria', '$pratica'] } }, - }, - { $unwind: { path: '$teachers', preserveNullAndEmptyArrays: true } }, - { $group: { _id: null, total: { $sum: 1 } } }, - { $project: { _id: 0 } }, - ]; - - const subjectsCountQuery = [ - { $group: { _id: null, total: { $sum: 1 } } }, - { $project: { _id: 0 } }, - ]; - - // check if we are dealing with previous data or current - const isPrevious = await ComponentModel.countDocuments({ - season, - before_kick: { $exists: true, $ne: [] }, - }); - - const dataKey = isPrevious ? '$before_kick' : '$alunos_matriculados'; - - const studentCount = [ - { - $unwind: dataKey, - }, - { $group: { _id: null, alunos: { $addToSet: dataKey } } }, - { $unwind: '$alunos' }, - { $group: { _id: null, total: { $sum: 1 } } }, - ]; - - const [disciplinasStats] = await ComponentModel.aggregate([ - { $match: { season } }, - { - $facet: { - teachers: teacherCountQuery, - totalAlunos: studentCount, - subjects: subjectsCountQuery, - }, - }, - { - $addFields: { - teachers: { $ifNull: [{ $arrayElemAt: ['$teachers.total', 0] }, 0] }, - totalAlunos: { - $ifNull: [{ $arrayElemAt: ['$totalAlunos.total', 0] }, 0], - }, - subjects: { $ifNull: [{ $arrayElemAt: ['$subjects.total', 0] }, 0] }, - }, - }, - ]); - - const generalStatsCount = { - users: await UserModel.countDocuments({}), - currentAlunos: await StudentModel.countDocuments({ season }), - comments: await CommentModel.countDocuments({}), - enrollments: await EnrollmentModel.countDocuments({ - conceito: { $in: ['A', 'B', 'C', 'D', 'O', 'F'] }, - }), - }; - - const platformGeneralStats = Object.assign( - {}, - disciplinasStats, - generalStatsCount, - ); - - return platformGeneralStats; - } -} diff --git a/apps/core/src/modules/Public/stats/general/general.route.ts b/apps/core/src/modules/Public/stats/general/general.route.ts deleted file mode 100644 index 57eb58f5..00000000 --- a/apps/core/src/modules/Public/stats/general/general.route.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { GeneralStatsHandler } from "./general.handlers.js"; -import { generalStatsSchema } from "./general.schema.js"; -import type { FastifyInstance } from "fastify"; - - -export async function statsGeneralRoute(app: FastifyInstance) { - const generalStatsHandler = new GeneralStatsHandler(); - app.get( - "/stats/usage", - { schema: generalStatsSchema }, - generalStatsHandler.generalStats, - ); -} diff --git a/apps/core/src/modules/Public/stats/general/general.schema.ts b/apps/core/src/modules/Public/stats/general/general.schema.ts deleted file mode 100644 index 1ecf3fc4..00000000 --- a/apps/core/src/modules/Public/stats/general/general.schema.ts +++ /dev/null @@ -1,6 +0,0 @@ -import type { FastifySchema } from "fastify"; - -export const generalStatsSchema = { - tags: ["Public"], - description: "Rota para obter estatísticas gerais", -} satisfies FastifySchema; diff --git a/apps/core/src/modules/Public/stats/handlers/components.ts b/apps/core/src/modules/Public/stats/handlers/components.ts new file mode 100644 index 00000000..987f83b0 --- /dev/null +++ b/apps/core/src/modules/Public/stats/handlers/components.ts @@ -0,0 +1,201 @@ +import { ComponentModel, type Component } from '@/models/Component.js'; +import { StudentModel, type Student } from '@/models/Student.js'; +import { courseId, type currentQuad } from '@next/common'; +import type { FastifyReply, FastifyRequest } from 'fastify'; +import type { FilterQuery } from 'mongoose'; + +type Season = ReturnType; + +type ComponentStatsRequest = { + Querystring: { + season: Season; + turno: 'noturno' | 'diurno'; + curso_id: number; + ratio: number; + limit: number; + page: number; + }; + Params: { + action: 'overview' | 'disciplines' | 'courses'; + }; +}; + +export async function componentStats( + request: FastifyRequest, + reply: FastifyReply, +) { + const { action } = request.params; + const { season, turno, curso_id, ratio, limit, page } = Object.assign( + request.query, + { + limit: 10, + page: 0, + }, + ); + + if (!season) { + return reply.badRequest('Missing season'); + } + + // check if query has been made + const match: FilterQuery = { + season, + }; + + if (turno) { + match.turno = turno; + } + + if (curso_id) { + // get interCourseIds + const interIds = [ + await courseId( + 'Bacharelado em Ciência e Tecnologia', + season, + StudentModel, + ), + await courseId( + 'Bacharelado em Ciências e Humanidades', + season, + StudentModel, + ), + ]; + match.obrigatorias = { $in: [curso_id] }; + + // if passed course is not a BI, take BIs off query + if (!interIds.includes(curso_id)) { + match.obrigatorias.$nin = interIds; + } + } + + // check if we are dealing with previous data or current + const isPrevious = await ComponentModel.countDocuments({ + season, + before_kick: { $exists: true, $ne: [] }, + }); + const dataKey = isPrevious ? '$before_kick' : '$alunos_matriculados'; + + const stats = ComponentModel.aggregate([ + { + $match: { match }, + }, + { + $project: { + vagas: 1, + turno: 1, + codigo: 1, + disciplina: 1, + obrigatorias: 1, + turma: 1, + requisicoes: { $size: { $ifNull: [dataKey, []] } }, + }, + }, + { $match: { vagas: { $gt: 0 } } }, + { + $project: { + vagas: 1, + turno: 1, + codigo: 1, + disciplina: 1, + obrigatorias: 1, + requisicoes: 1, + turma: 1, + deficit: { $subtract: ['$requisicoes', '$vagas'] }, + ratio: { $divide: ['$requisicoes', '$vagas'] }, + }, + }, + ...(ratio !== null ? [{ $match: { ratio: { $gt: ratio } } }] : []), + ...(action === 'overview' + ? [ + { + $group: { + _id: null, + vagas: { $sum: '$vagas' }, + requisicoes: { $sum: '$requisicoes' }, + deficit: { $sum: '$deficit' }, + }, + }, + ] + : action === 'disciplines' + ? [ + { + $group: { + _id: '$codigo', + disciplina: { $first: '$disciplina' }, + vagas: { $sum: '$vagas' }, + requisicoes: { $sum: '$requisicoes' }, + }, + }, + { + $project: { + disciplina: 1, + vagas: 1, + requisicoes: 1, + codigo: 1, + deficit: { $subtract: ['$requisicoes', '$vagas'] }, + ratio: { $divide: ['$requisicoes', '$vagas'] }, + }, + }, + ] + : action === 'courses' + ? [ + { $unwind: '$obrigatorias' }, + { $match: match }, + { + $group: { + _id: '$obrigatorias', + obrigatorias: { $first: '$obrigatorias' }, + disciplina: { $first: '$disciplina' }, + vagas: { $sum: '$vagas' }, + requisicoes: { $sum: '$requisicoes' }, + }, + }, + { + $project: { + vagas: 1, + requisicoes: 1, + deficit: { $subtract: ['$requisicoes', '$vagas'] }, + ratio: { $divide: ['$requisicoes', '$vagas'] }, + }, + }, + ] + : []), + { + $facet: { + total: [{ $count: 'total' }], + data: [ + { $sort: { [ratio != null ? 'ratio' : 'deficit']: -1 } }, + { $skip: page * limit }, + { $limit: limit }, + { + $project: { + codigo: 1, + disciplina: 1, + turma: 1, + turno: 1, + vagas: 1, + requisicoes: 1, + deficit: 1, + ratio: 1, + }, + }, + ], + }, + }, + { + $addFields: { + total: { $ifNull: [{ $arrayElemAt: ['$total.total', 0] }, 0] }, + page, + }, + }, + { + $project: { + total: 1, + data: 1, + page: 1, + }, + }, + ]); + + return stats; +} diff --git a/apps/core/src/modules/Public/stats/handlers/general.ts b/apps/core/src/modules/Public/stats/handlers/general.ts new file mode 100644 index 00000000..cfbbee4a --- /dev/null +++ b/apps/core/src/modules/Public/stats/handlers/general.ts @@ -0,0 +1,94 @@ +import { CommentModel } from '@/models/Comment.js'; +import { ComponentModel } from '@/models/Component.js'; +import { EnrollmentModel } from '@/models/Enrollment.js'; +import { StudentModel } from '@/models/Student.js'; +import { UserModel } from '@/models/User.js'; +import type { currentQuad } from '@next/common'; +import type { FastifyReply, FastifyRequest } from 'fastify'; + +type Season = ReturnType; + +export async function generalStats( + request: FastifyRequest<{ Querystring: { season: Season } }>, + reply: FastifyReply, +) { + const { season } = request.query; + if (!season) { + return reply.badRequest('Missing season'); + } + + const teacherCountQuery = [ + { + $group: { + _id: null, + teoria: { $addToSet: '$teoria' }, + pratica: { $addToSet: '$pratica' }, + }, + }, + { + $project: { teachers: { $setUnion: ['$teoria', '$pratica'] } }, + }, + { $unwind: { path: '$teachers', preserveNullAndEmptyArrays: true } }, + { $group: { _id: null, total: { $sum: 1 } } }, + { $project: { _id: 0 } }, + ]; + + const subjectsCountQuery = [ + { $group: { _id: null, total: { $sum: 1 } } }, + { $project: { _id: 0 } }, + ]; + + // check if we are dealing with previous data or current + const isPrevious = await ComponentModel.countDocuments({ + season, + before_kick: { $exists: true, $ne: [] }, + }); + + const dataKey = isPrevious ? '$before_kick' : '$alunos_matriculados'; + + const studentCount = [ + { + $unwind: dataKey, + }, + { $group: { _id: null, alunos: { $addToSet: dataKey } } }, + { $unwind: '$alunos' }, + { $group: { _id: null, total: { $sum: 1 } } }, + ]; + + const [disciplinasStats] = await ComponentModel.aggregate([ + { $match: { season } }, + { + $facet: { + teachers: teacherCountQuery, + totalAlunos: studentCount, + subjects: subjectsCountQuery, + }, + }, + { + $addFields: { + teachers: { $ifNull: [{ $arrayElemAt: ['$teachers.total', 0] }, 0] }, + totalAlunos: { + $ifNull: [{ $arrayElemAt: ['$totalAlunos.total', 0] }, 0], + }, + subjects: { $ifNull: [{ $arrayElemAt: ['$subjects.total', 0] }, 0] }, + }, + }, + ]); + + const generalStatsCount = { + users: await UserModel.countDocuments({}), + currentAlunos: await StudentModel.countDocuments({ season }), + comments: await CommentModel.countDocuments({}), + enrollments: await EnrollmentModel.countDocuments({ + conceito: { $in: ['A', 'B', 'C', 'D', 'O', 'F'] }, + }), + }; + + const platformGeneralStats = Object.assign( + {}, + disciplinasStats, + generalStatsCount, + ); + + return platformGeneralStats; +} diff --git a/apps/core/src/modules/Public/stats/handlers/students.ts b/apps/core/src/modules/Public/stats/handlers/students.ts new file mode 100644 index 00000000..59a9d7e7 --- /dev/null +++ b/apps/core/src/modules/Public/stats/handlers/students.ts @@ -0,0 +1,38 @@ +import { ComponentModel } from '@/models/Component.js'; +import type { currentQuad } from '@next/common'; +import type { FastifyReply, FastifyRequest } from 'fastify'; + +type Season = ReturnType; + +export async function studentStats( + request: FastifyRequest<{ Querystring: { season: Season } }>, + reply: FastifyReply, +) { + const { season } = request.query; + if (!season) { + return reply.badRequest('Missing season'); + } + + // check if we are dealing with previous data or current + const isPrevious = await ComponentModel.countDocuments({ + season, + before_kick: { $exists: true, $ne: [] }, + }); + const dataKey = isPrevious ? '$before_kick' : '$alunos_matriculados'; + + const studentsStats = ComponentModel.aggregate([ + { $match: { season } }, + { $unwind: dataKey }, + { $group: { _id: dataKey, count: { $sum: 1 } } }, + { $group: { _id: '$count', students_number: { $sum: 1 } } }, + { $sort: { _id: 1 } }, + { + $project: { + students_number: 1, + components_number: '$_id', + }, + }, + ]); + + return studentsStats; +} diff --git a/apps/core/src/modules/Public/stats/stats.route.ts b/apps/core/src/modules/Public/stats/stats.route.ts new file mode 100644 index 00000000..9f7d3efa --- /dev/null +++ b/apps/core/src/modules/Public/stats/stats.route.ts @@ -0,0 +1,19 @@ +import type { FastifyInstance } from 'fastify'; +import { + componentStatsSchema, + generalStatsSchema, + studentStatsSchema, +} from './stats.schema.js'; +import { studentStats } from './handlers/students.js'; +import { generalStats } from './handlers/general.js'; +import { componentStats } from './handlers/components.js'; + +export async function publicStatsRoute(app: FastifyInstance) { + app.get('/stats/student', { schema: studentStatsSchema }, studentStats); + app.get('/stats/usage', { schema: generalStatsSchema }, generalStats); + app.get( + '/stats/disciplinas/:action', + { schema: componentStatsSchema }, + componentStats, + ); +} diff --git a/apps/core/src/modules/Public/stats/stats.schema.ts b/apps/core/src/modules/Public/stats/stats.schema.ts new file mode 100644 index 00000000..732c5a9b --- /dev/null +++ b/apps/core/src/modules/Public/stats/stats.schema.ts @@ -0,0 +1,40 @@ +import type { FastifySchema } from 'fastify'; +import { z } from 'zod'; + +export const generalStatsSchema = { + tags: ['Public'], + description: 'Rota para obter estatísticas gerais', + response: { + 200: z.object({ + teachers: z.number().int().describe('Professores no quadrimestre'), + totalAlunos: z + .number() + .int() + .describe('Quantidade total de requisições em matérias ofertadas'), + subjects: z + .number() + .int() + .describe( + 'Matérias ofertadas no quadrimestre (atualmente está incorreto)', + ), + users: z.number().int(), + currentAlunos: z + .number() + .int() + .describe('Alunos que utilizaram a extensão no quadrimestre'), + comments: z.number().int(), + enrollments: z.number().int(), + }), + }, +} satisfies FastifySchema; + +export const studentStatsSchema = { + tags: ['Public'], + description: 'Rota para obter estatísticas dos alunos', +} satisfies FastifySchema; + +export const componentStatsSchema = { + tags: ['Public'], + description: + 'Rota para obter estatísticas de disciplinas baseado em uma ação', +} satisfies FastifySchema; diff --git a/apps/core/src/modules/Public/stats/students/student.handlers.ts b/apps/core/src/modules/Public/stats/students/student.handlers.ts deleted file mode 100644 index cfa6d3c9..00000000 --- a/apps/core/src/modules/Public/stats/students/student.handlers.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { ComponentModel } from '@/models/Component.js'; -import type { currentQuad } from '@next/common'; -import type { FastifyReply, FastifyRequest } from 'fastify'; - -type Season = ReturnType; - -export class StudentStatsHandler { - async studentStats( - request: FastifyRequest<{ Querystring: { season: Season } }>, - reply: FastifyReply, - ) { - const { season } = request.query; - if (!season) { - return reply.badRequest('Missing season'); - } - - // check if we are dealing with previous data or current - const isPrevious = await ComponentModel.countDocuments({ - season, - before_kick: { $exists: true, $ne: [] }, - }); - const dataKey = isPrevious ? '$before_kick' : '$alunos_matriculados'; - - const studentsStats = ComponentModel.aggregate([ - { $match: { season } }, - { $unwind: dataKey }, - { $group: { _id: dataKey, count: { $sum: 1 } } }, - { $group: { _id: '$count', students_number: { $sum: 1 } } }, - { $sort: { _id: 1 } }, - { - $project: { - students_number: 1, - disciplines_number: '$_id', - }, - }, - ]); - - return studentsStats; - } -} diff --git a/apps/core/src/modules/Public/stats/students/student.route.ts b/apps/core/src/modules/Public/stats/students/student.route.ts deleted file mode 100644 index 13bf294a..00000000 --- a/apps/core/src/modules/Public/stats/students/student.route.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { StudentStatsHandler } from "./student.handlers.js"; -import { studentStatsSchema } from "./student.schema.js"; -import type { FastifyInstance } from "fastify"; - - -export async function statsStudentRoute(app: FastifyInstance) { - const studentStatsHandler = new StudentStatsHandler(); - app.get( - "/stats/student", - { schema: studentStatsSchema }, - studentStatsHandler.studentStats, - ); -} diff --git a/apps/core/src/modules/Public/stats/students/student.schema.ts b/apps/core/src/modules/Public/stats/students/student.schema.ts deleted file mode 100644 index 98e6573f..00000000 --- a/apps/core/src/modules/Public/stats/students/student.schema.ts +++ /dev/null @@ -1,6 +0,0 @@ -import type { FastifySchema } from "fastify"; - -export const studentStatsSchema = { - tags: ["Public"], - description: "Rota para obter estatísticas dos alunos", -} satisfies FastifySchema; \ No newline at end of file diff --git a/apps/core/src/modules/Public/status/route.ts b/apps/core/src/modules/Public/status/route.ts index 168a05b5..a59d3772 100644 --- a/apps/core/src/modules/Public/status/route.ts +++ b/apps/core/src/modules/Public/status/route.ts @@ -1,9 +1,9 @@ import { connections, STATES } from 'mongoose'; -import { statusCheckSchema } from './schema.js'; +import { statusSchema } from './schema.js'; import type { FastifyInstance } from 'fastify'; export async function statusRoute(app: FastifyInstance) { - app.get('/status', { schema: statusCheckSchema }, (_, reply) => { + app.get('/status', { schema: statusSchema }, (_, reply) => { const [connection] = connections; const isDatabaseUp = !!`${STATES[connection.readyState]}`; return reply.send({ diff --git a/apps/core/src/modules/Public/status/schema.ts b/apps/core/src/modules/Public/status/schema.ts index 5183ab27..a6c2fa6b 100644 --- a/apps/core/src/modules/Public/status/schema.ts +++ b/apps/core/src/modules/Public/status/schema.ts @@ -5,7 +5,7 @@ const statusSuccessResponse = z.object({ databaseConnected: z.boolean().describe('Is server connected'), }); -export const statusCheckSchema = { +export const statusSchema = { $id: 'healthCheckSchema', tags: ['Public'], description: