refactor: lesson creating

This commit is contained in:
Sergey Yarkov 2022-01-05 19:54:49 +03:00
parent df08f65a3b
commit cb80f507cc
5 changed files with 5 additions and 6 deletions

View File

@ -11,7 +11,7 @@ export default class LessonContent extends BaseModel {
public lesson_id: string;
@column()
public video_url: string;
public body: string;
@belongsTo(() => Lesson, { foreignKey: 'lesson_id' })
public lesson: BelongsTo<typeof Lesson>;

View File

@ -110,7 +110,7 @@ export default class LessonRepository {
/**
* Create content
*/
await lesson.related('content').create({ video_url: data.video_url });
await lesson.related('content').create({ body: '' });
/**
* Move video file to disk and save to database
@ -170,7 +170,7 @@ export default class LessonRepository {
/**
* Load data
*/
await lesson.load(loader => loader.load('content').load('materials').load('video'));
await lesson.load(loader => loader.load('content').load('materials').load('video').load('progress'));
return lesson;
}

View File

@ -9,7 +9,6 @@ export default class CreateLessonValidator {
title: schema.string({}, [rules.maxLength(255)]),
description: schema.string(),
duration: schema.date({ format: 'HH:mm:ss' }),
video_url: schema.string({}, [rules.url()]),
video: schema.file({
size: '5000mb',
extnames: ['mp4', 'mov', 'avi', 'wmv', 'webm', 'flv'],

View File

@ -56,7 +56,7 @@ export const StudentFactory = Factory.define(User, ({ faker }) => makeFakeUser(f
export const LessonContentFactory = Factory.define(LessonContent, ({ faker }) => {
return {
video_url: `/uploads/videos/${faker.datatype.string(10)}`,
body: `${faker.lorem.sentences(40)}`,
};
}).build();

View File

@ -7,7 +7,7 @@ export default class LessonContents extends BaseSchema {
this.schema.createTable(this.tableName, table => {
table.increments('id').primary();
table.string('lesson_id', 21).unsigned().references('lessons.id').unique().onDelete('CASCADE');
table.string('video_url').notNullable();
table.text('body');
table.timestamp('created_at', { useTz: true });
table.timestamp('updated_at', { useTz: true });
});