diff --git a/app/Models/Lesson.ts b/app/Models/Lesson.ts index dc81f31..75eca39 100644 --- a/app/Models/Lesson.ts +++ b/app/Models/Lesson.ts @@ -19,6 +19,9 @@ export default class Lesson extends BaseModel { @column() public description: string; + @column() + public duration: string; + @belongsTo(() => Course, { foreignKey: 'course_id', }) diff --git a/app/Repositories/LessonRepository.ts b/app/Repositories/LessonRepository.ts index 19c7d5f..9eff7fc 100644 --- a/app/Repositories/LessonRepository.ts +++ b/app/Repositories/LessonRepository.ts @@ -75,6 +75,7 @@ export default class LessonRepository { const lesson = await this.Lesson.create({ title: data.title, description: data.description, + duration: data.duration.toFormat('HH:mm:ss'), }); /** diff --git a/app/Validators/Lesson/CreateLessonValidator.ts b/app/Validators/Lesson/CreateLessonValidator.ts index c50fb5c..5a82dba 100644 --- a/app/Validators/Lesson/CreateLessonValidator.ts +++ b/app/Validators/Lesson/CreateLessonValidator.ts @@ -8,6 +8,7 @@ export default class CreateLessonValidator { course_id: schema.string({}, [rules.exists({ table: 'courses', column: 'id' })]), title: schema.string({}, [rules.maxLength(255)]), description: schema.string(), + duration: schema.date({ format: 'HH:mm:ss' }), video_url: schema.string({}, [rules.url()]), materials: schema.array.optional().members( schema.file({ diff --git a/database/factories/index.ts b/database/factories/index.ts index feef999..34862c1 100644 --- a/database/factories/index.ts +++ b/database/factories/index.ts @@ -15,6 +15,7 @@ import Lesson from 'App/Models/Lesson'; import LessonContent from 'App/Models/LessonContent'; import Role from 'App/Models/Role'; import User from 'App/Models/User'; +import { DateTime } from 'luxon'; const makeFakeUser = (faker: Faker.FakerStatic, loginPrefix?: string) => { return { @@ -62,6 +63,11 @@ export const LessonFactory = Factory.define(Lesson, ({ faker }) => { return { title: `Lesson #${faker.datatype.number(200)}`, description: faker.lorem.sentence(5), + duration: DateTime.fromObject({ + hour: faker.datatype.number(2), + minute: faker.datatype.number({ min: 30, max: 59 }), + second: 0, + }).toFormat('HH:mm:ss'), }; }) .relation('content', () => LessonContentFactory) diff --git a/database/migrations/1628016919501_lessons.ts b/database/migrations/1628016919501_lessons.ts index 76b3c9d..870d974 100644 --- a/database/migrations/1628016919501_lessons.ts +++ b/database/migrations/1628016919501_lessons.ts @@ -9,6 +9,7 @@ export default class Lessons extends BaseSchema { table.string('course_id', 21).unsigned().references('courses.id').onDelete('CASCADE'); table.string('title').notNullable(); table.string('description'); + table.time('duration').notNullable(); table.timestamp('created_at', { useTz: true }); table.timestamp('updated_at', { useTz: true }); });