feat: update image of course

This commit is contained in:
Sergey Yarkov 2021-11-14 19:07:41 +03:00
parent 71a99fe556
commit d62bccc9dd
2 changed files with 24 additions and 2 deletions

View File

@ -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;
}

View File

@ -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' })]),
});