fix: localize validation and api messages
All checks were successful
CI / Validate frontend and API (push) Successful in 39s
CI / Build and publish Docker images (push) Successful in 22s

This commit is contained in:
Cauê Faleiros
2026-09-08 13:40:38 -03:00
parent 987eb210eb
commit ad736758a7
17 changed files with 97 additions and 82 deletions

View File

@@ -37,7 +37,7 @@ const lessonSchema = z.object({
const coverImageUrlSchema = z.string().url().refine((value) => {
const protocol = new URL(value).protocol;
return protocol === 'https:' || (config.APP_ENV !== 'production' && protocol === 'http:');
}, { message: 'Cover image URL must use HTTPS.' });
}, { message: 'A URL da imagem de capa deve usar HTTPS.' });
const courseSchema = z.object({
title: z.string().trim().min(1).max(255),
@@ -94,7 +94,7 @@ async function insertAssets(client: PoolClient, parent: { courseId?: string; les
async function assertActiveCategory(category: string) {
const result = await pool.query('select 1 from course_categories where name = $1 and is_active', [category]);
if (!result.rowCount) throw new CourseContentConflict('Select an active category created by the superadmin.');
if (!result.rowCount) throw new CourseContentConflict('Selecione uma trilha ativa criada pelo superadmin.');
}
function assertPublishable(input: CourseInput) {
@@ -103,7 +103,7 @@ function assertPublishable(input: CourseInput) {
lesson.media.length === 0 || lesson.media.some((media) => media.status !== 'ready'),
);
if (unplayableLesson) {
throw new CoursePublicationBlocked(`The course cannot be published while "${unplayableLesson.title}" has no ready video.`);
throw new CoursePublicationBlocked(`O curso não pode ser publicado enquanto “${unplayableLesson.title}” não tiver um vídeo pronto.`);
}
}
@@ -112,7 +112,7 @@ async function replaceCourseContents(client: PoolClient, courseId: string, input
const existingIds = new Set(existingLessons.rows.map((lesson) => lesson.id));
const submittedIds = new Set(input.lessons.flatMap((lesson) => lesson.id ? [lesson.id] : []));
const unknownLessonId = [...submittedIds].find((lessonId) => !existingIds.has(lessonId));
if (unknownLessonId) throw new Error('A lesson being edited does not belong to this course.');
if (unknownLessonId) throw new Error('Uma aula em edição não pertence a este curso.');
const removedLessonIds = [...existingIds].filter((lessonId) => !submittedIds.has(lessonId));
if (removedLessonIds.length > 0) {
@@ -125,7 +125,7 @@ async function replaceCourseContents(client: PoolClient, courseId: string, input
[removedLessonIds],
);
if (usage.rowCount) {
throw new CourseContentConflict('A lesson with student progress or comments cannot be removed. Keep it or archive the course instead.');
throw new CourseContentConflict('Uma aula com progresso ou comentários de alunos não pode ser removida. Mantenha-a ou arquive o curso.');
}
await client.query('delete from lessons where id = any($1::uuid[])', [removedLessonIds]);
}
@@ -170,9 +170,9 @@ async function replaceCourseContents(client: PoolClient, courseId: string, input
async function assertCanManageCourse(courseId: string, user: { id: string; role: string }) {
const result = await pool.query<{ instructor_id: string }>('select instructor_id from courses where id = $1', [courseId]);
const course = result.rows[0];
if (!course) return { error: 'Course not found', statusCode: 404 as const };
if (!course) return { error: 'Curso não encontrado.', statusCode: 404 as const };
if (user.role !== 'admin' && course.instructor_id !== user.id) {
return { error: 'You can only manage your own courses', statusCode: 403 as const };
return { error: 'Você só pode gerenciar seus próprios cursos.', statusCode: 403 as const };
}
return null;
}
@@ -288,7 +288,7 @@ export const manageCourseRoutes: FastifyPluginAsync = async (app) => {
);
if (!original.rows[0]) {
await client.query('rollback');
return reply.code(404).send({ error: 'Course not found' });
return reply.code(404).send({ error: 'Curso não encontrado.' });
}
const source = original.rows[0];
const title = `${source.title} (cópia)`;