mirror of
https://github.com/sergeyyarkov/educt-server.git
synced 2026-10-11 10:19:20 +03:00
feat: update image of course
This commit is contained in:
parent
71a99fe556
commit
d62bccc9dd
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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' })]),
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user