From cb80f507cc2fa83405fb63f2b301c39886deb1f3 Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Wed, 5 Jan 2022 19:54:49 +0300 Subject: [PATCH] refactor: lesson creating --- app/Models/LessonContent.ts | 2 +- app/Repositories/LessonRepository.ts | 4 ++-- app/Validators/Lesson/CreateLessonValidator.ts | 1 - database/factories/index.ts | 2 +- database/migrations/1628017319337_lesson_contents.ts | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/Models/LessonContent.ts b/app/Models/LessonContent.ts index 5a1edd1..17d7662 100644 --- a/app/Models/LessonContent.ts +++ b/app/Models/LessonContent.ts @@ -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; diff --git a/app/Repositories/LessonRepository.ts b/app/Repositories/LessonRepository.ts index c837f80..256fef2 100644 --- a/app/Repositories/LessonRepository.ts +++ b/app/Repositories/LessonRepository.ts @@ -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; } diff --git a/app/Validators/Lesson/CreateLessonValidator.ts b/app/Validators/Lesson/CreateLessonValidator.ts index 64d5de1..976de89 100644 --- a/app/Validators/Lesson/CreateLessonValidator.ts +++ b/app/Validators/Lesson/CreateLessonValidator.ts @@ -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'], diff --git a/database/factories/index.ts b/database/factories/index.ts index 9e53a04..a602976 100644 --- a/database/factories/index.ts +++ b/database/factories/index.ts @@ -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(); diff --git a/database/migrations/1628017319337_lesson_contents.ts b/database/migrations/1628017319337_lesson_contents.ts index 569f178..da14cff 100644 --- a/database/migrations/1628017319337_lesson_contents.ts +++ b/database/migrations/1628017319337_lesson_contents.ts @@ -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 }); });