mirror of
https://github.com/sergeyyarkov/educt-server.git
synced 2026-10-11 10:19:20 +03:00
refactor: lesson creating
This commit is contained in:
parent
df08f65a3b
commit
cb80f507cc
@ -11,7 +11,7 @@ export default class LessonContent extends BaseModel {
|
|||||||
public lesson_id: string;
|
public lesson_id: string;
|
||||||
|
|
||||||
@column()
|
@column()
|
||||||
public video_url: string;
|
public body: string;
|
||||||
|
|
||||||
@belongsTo(() => Lesson, { foreignKey: 'lesson_id' })
|
@belongsTo(() => Lesson, { foreignKey: 'lesson_id' })
|
||||||
public lesson: BelongsTo<typeof Lesson>;
|
public lesson: BelongsTo<typeof Lesson>;
|
||||||
|
|||||||
@ -110,7 +110,7 @@ export default class LessonRepository {
|
|||||||
/**
|
/**
|
||||||
* Create content
|
* 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
|
* Move video file to disk and save to database
|
||||||
@ -170,7 +170,7 @@ export default class LessonRepository {
|
|||||||
/**
|
/**
|
||||||
* Load data
|
* 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;
|
return lesson;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,6 @@ export default class CreateLessonValidator {
|
|||||||
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' }),
|
duration: schema.date({ format: 'HH:mm:ss' }),
|
||||||
video_url: schema.string({}, [rules.url()]),
|
|
||||||
video: schema.file({
|
video: schema.file({
|
||||||
size: '5000mb',
|
size: '5000mb',
|
||||||
extnames: ['mp4', 'mov', 'avi', 'wmv', 'webm', 'flv'],
|
extnames: ['mp4', 'mov', 'avi', 'wmv', 'webm', 'flv'],
|
||||||
|
|||||||
@ -56,7 +56,7 @@ export const StudentFactory = Factory.define(User, ({ faker }) => makeFakeUser(f
|
|||||||
|
|
||||||
export const LessonContentFactory = Factory.define(LessonContent, ({ faker }) => {
|
export const LessonContentFactory = Factory.define(LessonContent, ({ faker }) => {
|
||||||
return {
|
return {
|
||||||
video_url: `/uploads/videos/${faker.datatype.string(10)}`,
|
body: `${faker.lorem.sentences(40)}`,
|
||||||
};
|
};
|
||||||
}).build();
|
}).build();
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ export default class LessonContents extends BaseSchema {
|
|||||||
this.schema.createTable(this.tableName, table => {
|
this.schema.createTable(this.tableName, table => {
|
||||||
table.increments('id').primary();
|
table.increments('id').primary();
|
||||||
table.string('lesson_id', 21).unsigned().references('lessons.id').unique().onDelete('CASCADE');
|
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('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