diff --git a/app/Repositories/CourseRepository.ts b/app/Repositories/CourseRepository.ts index 654b06f..f5edffb 100644 --- a/app/Repositories/CourseRepository.ts +++ b/app/Repositories/CourseRepository.ts @@ -240,12 +240,30 @@ export default class CourseRepository { .first(); if (course) { - course.merge(data); + /** + * Update fields + */ + course.merge({ + title: data.title, + description: data.description, + teacher_id: data.teacher_id, + category_id: data.category_id, + }); + + /** + * Update image + */ + if (data.image) { + course.image = Attachment.fromFile(data.image); + } + + /** + * Load other updated data + */ course.load('category'); course.load('teacher'); await course.save(); - return course; } diff --git a/app/Validators/Course/UpdateCourseValidator.ts b/app/Validators/Course/UpdateCourseValidator.ts index 61cbe97..a5096c1 100644 --- a/app/Validators/Course/UpdateCourseValidator.ts +++ b/app/Validators/Course/UpdateCourseValidator.ts @@ -7,6 +7,10 @@ export default class UpdateCourseValidator { public schema = schema.create({ title: schema.string.optional(), description: schema.string.optional(), + image: schema.file.optional({ + size: '10mb', + extnames: ['jpg', 'jpeg', 'png'], + }), teacher_id: schema.string.optional({}, [rules.exists({ table: 'users', column: 'id' })]), category_id: schema.string.optional({}, [rules.exists({ table: 'categories', column: 'id' })]), });