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