fix: localize validation and api messages
This commit is contained in:
@@ -14,7 +14,7 @@ const lessonParamsSchema = z.object({
|
||||
const completionSchema = z.object({
|
||||
completed: z.boolean().optional(),
|
||||
watchedSeconds: z.coerce.number().int().min(0).optional(),
|
||||
}).refine((input) => input.completed !== undefined || input.watchedSeconds !== undefined, { message: 'Provide progress or completion state' });
|
||||
}).refine((input) => input.completed !== undefined || input.watchedSeconds !== undefined, { message: 'Informe o progresso ou o status de conclusão.' });
|
||||
|
||||
const commentSchema = z.object({
|
||||
lessonId: z.string().uuid().nullable().optional(),
|
||||
@@ -51,7 +51,7 @@ export const learningRoutes: FastifyPluginAsync = async (app) => {
|
||||
app.get('/courses/:courseId/progress', { preHandler: app.authenticate }, async (request, reply) => {
|
||||
const { courseId } = courseParamsSchema.parse(request.params);
|
||||
if (!(await ensurePublishedCourse(courseId))) {
|
||||
return reply.code(404).send({ error: 'Course not found' });
|
||||
return reply.code(404).send({ error: 'Curso não encontrado.' });
|
||||
}
|
||||
|
||||
const result = await pool.query(
|
||||
@@ -78,7 +78,7 @@ export const learningRoutes: FastifyPluginAsync = async (app) => {
|
||||
);
|
||||
|
||||
if (lesson.rowCount !== 1) {
|
||||
return reply.code(404).send({ error: 'Lesson not found' });
|
||||
return reply.code(404).send({ error: 'Aula não encontrada.' });
|
||||
}
|
||||
|
||||
const result = await pool.query(
|
||||
@@ -99,7 +99,7 @@ export const learningRoutes: FastifyPluginAsync = async (app) => {
|
||||
app.get('/courses/:courseId/comments', { preHandler: app.authenticate }, async (request, reply) => {
|
||||
const { courseId } = courseParamsSchema.parse(request.params);
|
||||
if (!(await canViewCourseComments(courseId, request.user))) {
|
||||
return reply.code(404).send({ error: 'Course not found' });
|
||||
return reply.code(404).send({ error: 'Curso não encontrado.' });
|
||||
}
|
||||
|
||||
const result = await pool.query(
|
||||
@@ -120,13 +120,13 @@ export const learningRoutes: FastifyPluginAsync = async (app) => {
|
||||
const { courseId } = courseParamsSchema.parse(request.params);
|
||||
const input = commentSchema.parse(request.body);
|
||||
if (!(await ensurePublishedCourse(courseId))) {
|
||||
return reply.code(404).send({ error: 'Course not found' });
|
||||
return reply.code(404).send({ error: 'Curso não encontrado.' });
|
||||
}
|
||||
|
||||
if (input.lessonId) {
|
||||
const lesson = await pool.query('select id from lessons where id = $1 and course_id = $2', [input.lessonId, courseId]);
|
||||
if (lesson.rowCount !== 1) {
|
||||
return reply.code(400).send({ error: 'Lesson does not belong to this course' });
|
||||
return reply.code(400).send({ error: 'Esta aula não pertence ao curso.' });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ export const learningRoutes: FastifyPluginAsync = async (app) => {
|
||||
app.put('/comments/:commentId/reply', { preHandler: app.requireRoles(['instructor', 'admin']) }, async (request, reply) => {
|
||||
const { commentId } = commentParamsSchema.parse(request.params);
|
||||
const input = replySchema.parse(request.body);
|
||||
if (!(await canModerateComment(commentId, request.user))) return reply.code(403).send({ error: 'You cannot reply to this comment' });
|
||||
if (!(await canModerateComment(commentId, request.user))) return reply.code(403).send({ error: 'Você não pode responder a este comentário.' });
|
||||
await pool.query(
|
||||
`insert into comment_replies (comment_id, author_id, body)
|
||||
values ($1, $2, $3)
|
||||
@@ -161,7 +161,7 @@ export const learningRoutes: FastifyPluginAsync = async (app) => {
|
||||
|
||||
app.delete('/comments/:commentId', { preHandler: app.requireRoles(['instructor', 'admin']) }, async (request, reply) => {
|
||||
const { commentId } = commentParamsSchema.parse(request.params);
|
||||
if (!(await canModerateComment(commentId, request.user))) return reply.code(403).send({ error: 'You cannot moderate this comment' });
|
||||
if (!(await canModerateComment(commentId, request.user))) return reply.code(403).send({ error: 'Você não pode moderar este comentário.' });
|
||||
await pool.query('delete from comments where id = $1', [commentId]);
|
||||
await recordAudit({ actorId: request.user.id, action: 'comment.deleted', subjectType: 'comment', subjectId: commentId, ipAddress: request.ip });
|
||||
return reply.code(204).send();
|
||||
|
||||
Reference in New Issue
Block a user