mirror of
https://github.com/sergeyyarkov/educt-server.git
synced 2026-10-11 10:19:20 +03:00
feat: added duration column to lesson
This commit is contained in:
parent
be2f05a780
commit
1a9bddd0d3
@ -19,6 +19,9 @@ export default class Lesson extends BaseModel {
|
|||||||
@column()
|
@column()
|
||||||
public description: string;
|
public description: string;
|
||||||
|
|
||||||
|
@column()
|
||||||
|
public duration: string;
|
||||||
|
|
||||||
@belongsTo(() => Course, {
|
@belongsTo(() => Course, {
|
||||||
foreignKey: 'course_id',
|
foreignKey: 'course_id',
|
||||||
})
|
})
|
||||||
|
|||||||
@ -75,6 +75,7 @@ export default class LessonRepository {
|
|||||||
const lesson = await this.Lesson.create({
|
const lesson = await this.Lesson.create({
|
||||||
title: data.title,
|
title: data.title,
|
||||||
description: data.description,
|
description: data.description,
|
||||||
|
duration: data.duration.toFormat('HH:mm:ss'),
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -8,6 +8,7 @@ export default class CreateLessonValidator {
|
|||||||
course_id: schema.string({}, [rules.exists({ table: 'courses', column: 'id' })]),
|
course_id: schema.string({}, [rules.exists({ table: 'courses', column: 'id' })]),
|
||||||
title: schema.string({}, [rules.maxLength(255)]),
|
title: schema.string({}, [rules.maxLength(255)]),
|
||||||
description: schema.string(),
|
description: schema.string(),
|
||||||
|
duration: schema.date({ format: 'HH:mm:ss' }),
|
||||||
video_url: schema.string({}, [rules.url()]),
|
video_url: schema.string({}, [rules.url()]),
|
||||||
materials: schema.array.optional().members(
|
materials: schema.array.optional().members(
|
||||||
schema.file({
|
schema.file({
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import Lesson from 'App/Models/Lesson';
|
|||||||
import LessonContent from 'App/Models/LessonContent';
|
import LessonContent from 'App/Models/LessonContent';
|
||||||
import Role from 'App/Models/Role';
|
import Role from 'App/Models/Role';
|
||||||
import User from 'App/Models/User';
|
import User from 'App/Models/User';
|
||||||
|
import { DateTime } from 'luxon';
|
||||||
|
|
||||||
const makeFakeUser = (faker: Faker.FakerStatic, loginPrefix?: string) => {
|
const makeFakeUser = (faker: Faker.FakerStatic, loginPrefix?: string) => {
|
||||||
return {
|
return {
|
||||||
@ -62,6 +63,11 @@ export const LessonFactory = Factory.define(Lesson, ({ faker }) => {
|
|||||||
return {
|
return {
|
||||||
title: `Lesson #${faker.datatype.number(200)}`,
|
title: `Lesson #${faker.datatype.number(200)}`,
|
||||||
description: faker.lorem.sentence(5),
|
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)
|
.relation('content', () => LessonContentFactory)
|
||||||
|
|||||||
@ -9,6 +9,7 @@ export default class Lessons extends BaseSchema {
|
|||||||
table.string('course_id', 21).unsigned().references('courses.id').onDelete('CASCADE');
|
table.string('course_id', 21).unsigned().references('courses.id').onDelete('CASCADE');
|
||||||
table.string('title').notNullable();
|
table.string('title').notNullable();
|
||||||
table.string('description');
|
table.string('description');
|
||||||
|
table.time('duration').notNullable();
|
||||||
table.timestamp('created_at', { useTz: true });
|
table.timestamp('created_at', { useTz: true });
|
||||||
table.timestamp('updated_at', { useTz: true });
|
table.timestamp('updated_at', { useTz: true });
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user