mirror of
https://github.com/sergeyyarkov/educt-server.git
synced 2026-10-11 02:09:07 +03:00
feat: assign random color to lesson & deleted some colors in enum type
This commit is contained in:
parent
14122905d6
commit
a4adf27831
@ -11,15 +11,6 @@ enum ColorEnum {
|
||||
Purple = '#800080',
|
||||
Indigo = '#4B0082',
|
||||
Teal = '#008080',
|
||||
LightGray = '#D3D3D3',
|
||||
LightSlateGray = '#778899',
|
||||
LightGreen = '#90EE90',
|
||||
LightSeaGreen = '#20B2AA',
|
||||
LightCoral = '#FFA07A',
|
||||
LightCyan = '#E0FFFF',
|
||||
LightSteelBlue = '#B0C4DE',
|
||||
LightBlue = '#ADD8E6',
|
||||
LightSkyBlue = '#87CEFA',
|
||||
MediumVioletRed = '#C71585',
|
||||
MediumOrchid = '#BA55D3',
|
||||
MediumPurple = '#9370DB',
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { BaseModel, beforeCreate, BelongsTo, belongsTo, column, HasOne, hasOne } from '@ioc:Adonis/Lucid/Orm';
|
||||
import ColorHelper from 'App/Helpers/ColorHelper';
|
||||
import Course from './Course';
|
||||
// eslint-disable-next-line import/no-cycle
|
||||
import LessonContent from './LessonContent';
|
||||
@ -58,4 +59,13 @@ export default class Lesson extends BaseModel {
|
||||
public static assignLessonId(lesson: Lesson) {
|
||||
lesson.id = nanoid();
|
||||
}
|
||||
|
||||
@beforeCreate()
|
||||
public static async assignRandomColor(course: Course) {
|
||||
const color = await ColorHelper.generateRandomColor();
|
||||
|
||||
if (color) {
|
||||
course.color_id = color.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,10 +72,13 @@ export default class LessonRepository {
|
||||
* @returns Lesson
|
||||
*/
|
||||
public async create(course: Course, data: CreateLessonValidator['schema']['props']): Promise<Lesson> {
|
||||
await course.loadCount('lessons');
|
||||
|
||||
const lesson = await this.Lesson.create({
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
duration: data.duration.toFormat('HH:mm:ss'),
|
||||
display_order: Number.parseInt(course.$extras.lessons_count, 10) + 1,
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@ -70,7 +70,7 @@ export const LessonFactory = Factory.define(Lesson, ({ faker }) => {
|
||||
minute: faker.datatype.number({ min: 30, max: 59 }),
|
||||
second: 0,
|
||||
}).toFormat('HH:mm:ss'),
|
||||
color_id: faker.datatype.number({ min: 1, max: 25 }),
|
||||
color_id: faker.datatype.number({ min: 1, max: 15 }),
|
||||
};
|
||||
})
|
||||
.relation('content', () => LessonContentFactory)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user