mirror of
https://github.com/sergeyyarkov/educt-server.git
synced 2026-10-11 18:29:15 +03:00
feat: added new fields to course model
This commit is contained in:
parent
a4d8628c81
commit
11f0d30092
@ -34,6 +34,9 @@ export default class Course extends BaseModel {
|
||||
@column()
|
||||
public description: string;
|
||||
|
||||
@column()
|
||||
public education_description: string | null;
|
||||
|
||||
@column({ serializeAs: null })
|
||||
public teacher_id: string;
|
||||
|
||||
|
||||
@ -81,9 +81,12 @@ export default class CourseRepository {
|
||||
const course = await this.Course.query()
|
||||
.preload('teacher')
|
||||
.preload('color')
|
||||
.preload('category')
|
||||
.preload('category', q => q.preload('color'))
|
||||
.preload('lessons', q => q.preload('color').orderBy('display_order', 'asc').withCount('materials'))
|
||||
.preload('students', q => q.preload('roles').preload('contacts'))
|
||||
.withCount('likes')
|
||||
.withCount('lessons')
|
||||
.withCount('students')
|
||||
.where('id', id)
|
||||
.first();
|
||||
|
||||
@ -194,6 +197,7 @@ export default class CourseRepository {
|
||||
|
||||
course.title = data.title;
|
||||
course.description = data.description;
|
||||
course.education_description = data.education_description;
|
||||
course.status = data.status;
|
||||
course.teacher_id = data.teacher_id;
|
||||
course.category_id = data.category_id;
|
||||
@ -255,6 +259,7 @@ export default class CourseRepository {
|
||||
course.merge({
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
education_description: data.education_description,
|
||||
teacher_id: data.teacher_id,
|
||||
category_id: data.category_id,
|
||||
});
|
||||
|
||||
@ -37,7 +37,10 @@ export default class MeService {
|
||||
const user = await auth.use(this.authGuard).authenticate();
|
||||
|
||||
await user.load(loader => {
|
||||
loader.load('roles').load('contacts');
|
||||
loader
|
||||
.load('roles')
|
||||
.load('contacts')
|
||||
.load('likes', q => q.select('id'));
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@ -5,15 +5,15 @@ export default class CreateContactsValidator {
|
||||
constructor(protected ctx: HttpContextContract) {}
|
||||
|
||||
public schema = schema.create({
|
||||
phone_number: schema.string.optional({}, [
|
||||
phone_number: schema.string.nullableAndOptional({}, [
|
||||
rules.mobile({
|
||||
locales: ['ru-RU', 'en-US'],
|
||||
strict: true,
|
||||
}),
|
||||
]),
|
||||
vk_id: schema.string.optional({}, [rules.regex(/^[a-zA-Z0-9_]+$/)]),
|
||||
twitter_id: schema.string.optional({}, [rules.regex(/^[a-zA-Z0-9_]+$/)]),
|
||||
telegram_id: schema.string.optional({}, [rules.regex(/^[a-zA-Z0-9_]+$/)]),
|
||||
vk_id: schema.string.nullableAndOptional({}, [rules.regex(/^[a-zA-Z0-9_]+$/)]),
|
||||
twitter_id: schema.string.nullableAndOptional({}, [rules.regex(/^[a-zA-Z0-9_]+$/)]),
|
||||
telegram_id: schema.string.nullableAndOptional({}, [rules.regex(/^[a-zA-Z0-9_]+$/)]),
|
||||
});
|
||||
|
||||
public messages = {};
|
||||
|
||||
@ -8,6 +8,7 @@ export default class CreateCourseValidator {
|
||||
public schema = schema.create({
|
||||
title: schema.string(),
|
||||
description: schema.string(),
|
||||
education_description: schema.string.nullable(),
|
||||
image: schema.file.optional({
|
||||
size: '10mb',
|
||||
extnames: ['jpg', 'jpeg', 'png'],
|
||||
|
||||
@ -7,6 +7,7 @@ export default class UpdateCourseValidator {
|
||||
public schema = schema.create({
|
||||
title: schema.string.optional(),
|
||||
description: schema.string.optional(),
|
||||
education_description: schema.string.nullable(),
|
||||
image: schema.file.optional({
|
||||
size: '10mb',
|
||||
extnames: ['jpg', 'jpeg', 'png'],
|
||||
|
||||
@ -87,6 +87,7 @@ export const CourseFactory = Factory.define(Course, ({ faker }) => {
|
||||
return {
|
||||
title: faker.lorem.sentence(8),
|
||||
description: faker.lorem.sentence(20),
|
||||
education_description: faker.lorem.sentence(15),
|
||||
status: CourseStatusEnum.PUBLISHED,
|
||||
};
|
||||
})
|
||||
|
||||
@ -14,6 +14,7 @@ export default class Courses extends BaseSchema {
|
||||
table.json('image');
|
||||
table.string('title').notNullable();
|
||||
table.string('description').notNullable();
|
||||
table.string('education_description', 250);
|
||||
table.string('teacher_id', 21).unsigned().references('users.id').notNullable().onDelete('CASCADE');
|
||||
table.string('category_id', 21).unsigned().references('categories.id').notNullable().onDelete('CASCADE');
|
||||
table.integer('color_id').unsigned().references('colors.id');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user