Skip to content

Commit

Permalink
docs: add enrollment routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Joabesv committed Oct 31, 2023
1 parent 17ce71d commit ee948d3
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 6 deletions.
3 changes: 1 addition & 2 deletions apps/core/src/modules/enrollments/handlers/enrollment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { CommentModel, EnrollmentModel } from '@next/models';
import type { FastifyReply, FastifyRequest } from 'fastify';
import type { ObjectId } from 'mongoose';

export type RouteParams = { enrollmentId: ObjectId };
type RouteParams = { enrollmentId: ObjectId };
export async function enrollment(
request: FastifyRequest<{ Params: RouteParams }>,
reply: FastifyReply,
) {
const { enrollmentId } = request.params;
const user = request.user;

if (!user?.ra) {
return {};
}
Expand Down
7 changes: 4 additions & 3 deletions apps/core/src/modules/enrollments/route.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { listEnrollments } from './handlers/listEnrollments.js';
import { type RouteParams, enrollment } from './handlers/enrollment.js';
import { enrollment } from './handlers/enrollment.js';
import { enrollmentSchema, listEnrollmentsSchema } from './schema.js';
import type { FastifyInstance } from 'fastify';

// eslint-disable-next-line require-await
export async function enrollmentsRoute(app: FastifyInstance) {
app.get('/', listEnrollments);
app.get<{ Params: RouteParams }>('/:enrollmentId', enrollment);
app.get('/', { schema: listEnrollmentsSchema }, listEnrollments);
app.get('/:enrollmentId', { schema: enrollmentSchema }, enrollment);
}
92 changes: 92 additions & 0 deletions apps/core/src/modules/enrollments/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { z } from 'zod';
import type { FastifySchema } from 'fastify';
import type { ObjectId } from 'mongoose';

const subjectSchema = z.object({
_id: z.custom<ObjectId>(),
name: z.string(),
search: z.string(),
creditos: z.number().optional(),
createdAt: z.date(),
updatedAt: z.date(),
__v: z.number().optional(),
});

const teoriaSchema = z.object({
_id: z.custom<ObjectId>(),
name: z.string(),
alias: z.string().array(),
createdAt: z.date(),
updatedAt: z.date(),
__v: z.number().optional(),
});

const listEnrollmentsResponse = z
.object({
_id: z.custom<ObjectId>(),
year: z.number(),
quad: z.number(),
identifier: z.string(),
ra: z.number(),
disciplina: z.string(),
subject: subjectSchema,
campus: z.string(),
turno: z.string(),
turma: z.string(),
teoria: teoriaSchema.optional(),
pratica: teoriaSchema.optional(),
mainTeacher: z.custom<ObjectId>().optional(),
comments: z.string().array().optional(),
conceito: z.string(),
creditos: z.number(),
createdAt: z.date(),
updatedAt: z.date(),
__v: z.number().optional(),
})
.array()
.describe('Modelo das matérias que temos registradas');

const enrollmentResponse = z
.object({
enrollment: z.object({
_id: z.custom<ObjectId>(),
year: z.number(),
quad: z.number(),
identifier: z.string(),
ra: z.number(),
disciplina: z.string(),
subject: subjectSchema,
campus: z.string(),
turno: z.string(),
turma: z.string(),
teoria: teoriaSchema.optional(),
pratica: teoriaSchema.optional(),
mainTeacher: z.custom<ObjectId>().optional(),
comments: z.array(z.nullable(z.string())).optional(),
conceito: z.string(),
creditos: z.number(),
createdAt: z.date(),
updatedAt: z.date(),
__v: z.number().optional(),
}),
comments: z.string().array().nullable(),
})
.describe('Modelo das matérias que temos registradas');

/** User enrollments */
export const listEnrollmentsSchema = {
tags: ['Enrollments'],
description: 'Rota que retorna um array de matérias que o aluno cursou',
response: {
200: listEnrollmentsResponse,
},
} satisfies FastifySchema;

/**Enrollment */
export const enrollmentSchema = {
tags: ['Enrollments'],
description: 'Rota que retorna uma matéria que o aluno cursou',
response: {
200: enrollmentResponse,
},
} satisfies FastifySchema;
2 changes: 1 addition & 1 deletion apps/core/src/modules/user/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const usersInfoResponse = z
updatedAt: z.date(),
__v: z.number(),
email: z.string().email(),
ra: z.string(),
ra: z.number(),
})
.describe('Informações do usuário da sessão');

Expand Down

0 comments on commit ee948d3

Please sign in to comment.