Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created new fields for course #634

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 114 additions & 21 deletions docs/course/course-schema.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
definitions:
courses:
type: array
items:
items:
type: object
properties:
_id:
Expand All @@ -13,16 +13,47 @@ definitions:
author:
type: string
ref: '#components/user'
lessons:
category:
type: string
ref: '#components/category'
subject:
type: string
ref: '#components/subject'
proficiencyLevel:
type: array
items:
type: string
ref: '#/components/lesson'
attachments:
enum:
- Beginner
- Intermediate
- Advanced
- Test Preparation
- Professional
- Specialized
sections:
type: array
items:
type: string
ref: '#/components/attachments'
type: object
properties:
title:
type: string
description:
type: string
lessons:
type: array
items:
type: string
ref: '#/components/lesson'
quizzes:
type: array
items:
type: string
ref: '#/components/quiz'
attachments:
type: array
items:
type: string
ref: '#/components/attachments'
createdAt:
type: string
format: date-time
Expand All @@ -41,22 +72,53 @@ definitions:
author:
type: string
ref: '#components/user'
lessons:
category:
type: string
ref: '#components/category'
subject:
type: string
ref: '#components/subject'
proficiencyLevel:
type: array
items:
type: string
ref: '#/components/lesson'
attachments:
enum:
- Beginner
- Intermediate
- Advanced
- Test Preparation
- Professional
- Specialized
sections:
type: array
items:
type: string
ref: '#/components/attachments'
type: object
properties:
title:
type: string
description:
type: string
lessons:
type: array
items:
type: string
ref: '#/components/lesson'
quizzes:
type: array
items:
type: string
ref: '#/components/quiz'
attachments:
type: array
items:
type: string
ref: '#/components/attachments'
createdAt:
type: string
format: date-time
type: string
format: date-time
updatedAt:
type: string
format: date-time
type: string
format: date-time
courseBody:
type: object
properties:
Expand All @@ -67,16 +129,47 @@ definitions:
author:
type: string
ref: '#components/user'
lessons:
category:
type: string
ref: '#components/category'
subject:
type: string
ref: '#components/subject'
proficiencyLevel:
type: array
items:
type: string
ref: '#/components/lesson'
attachments:
enum:
- Beginner
- Intermediate
- Advanced
- Test Preparation
- Professional
- Specialized
sections:
type: array
items:
type: string
ref: '#/components/attachments'
type: object
properties:
title:
type: string
description:
type: string
lessons:
type: array
items:
type: string
ref: '#/components/lesson'
quizzes:
type: array
items:
type: string
ref: '#/components/quiz'
attachments:
type: array
items:
type: string
ref: '#/components/attachments'
required:
- title
- description
- description
61 changes: 48 additions & 13 deletions docs/course/course.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,30 @@ paths:
title: Advanced English
description: Advanced english course with 5 modules and separated lessons for improving speaking, listening and reading.
author: 63da8767c9ad4c9a0b0eacd3
attachments: [ 63ed1cd25e9d781cdb6a6b15 ]
lessons: [ 63ed1cd25e9d781cdb6a6b17, 63ac1ad47e9d526cdb6f4n51 ]
createdAt: 2023-02-14T23:44:21.334Z
updatedAt: 2023-02-14T23:44:21.334Z
category: 64884f33fdc2d1a130c24ac2
subject: 6488509cfdc2d1a130c24ae4
proficiencyLevel: [Advanced]
sections:
- title: Section First
description: some description
lessons: [63ed1cd25e9d781cdb6a6b17, 63ac1ad47e9d526cdb6f4n51]
quizzes: [64ba39c714b7bc037a29d712]
attachments: [63ed1cd25e9d781cdb6a6b15]
createdAt: 2023-11-15T16:15:09.004Z
updatedAt: 2023-11-15T16:15:09.004Z
- _id: 640461e3cfdda3f3d16dcac5
title: Advanced Ukrainian
description: Advanced Ukrainian course with 5 modules and separated lessons for improving speaking, listening and reading.
author: 63da8767c9ad4c9a0b0eacd3
attachments: []
lessons: []
category: 64884f33fdc2d1a130c24ac2
subject: 6488509cfdc2d1a130c24ae4
proficiencyLevel: [Advanced]
sections:
- title: Section Second
- description: some description
- lessons: [63ed1cd25e9d781cdb6a6b17, 63ac1ad47e9d526cdb6f4n51]
- quizzes: [64ba39c714b7bc037a29d712]
- attachments: [63ed1cd25e9d781cdb6a6b15]
createdAt: 2023-20-01T13:25:36.292Z
updatedAt: 2023-20-01T13:25:36.292Z
401:
Expand Down Expand Up @@ -83,8 +97,15 @@ paths:
title: Advanced English
description: Advanced english course with 5 modules and separated lessons for improving speaking, listening and reading.
author: 63da8767c9ad4c9a0b0eacd3
attachments: [ 63ed1cd25e9d781cdb6a6b15 ]
lessons: [ 63ed1cd25e9d781cdb6a6b17, 63ac1ad47e9d526cdb6f4n51 ]
category: 64884f33fdc2d1a130c24ac2
subject: 6488509cfdc2d1a130c24ae4
proficiencyLevel: [Advanced]
sections:
- title: Section First
description: some description
lessons: [63ed1cd25e9d781cdb6a6b17, 63ac1ad47e9d526cdb6f4n51]
quizzes: [64ba39c714b7bc037a29d712]
attachments: [63ed1cd25e9d781cdb6a6b15]
responses:
201:
description: Created
Expand All @@ -96,8 +117,15 @@ paths:
title: Advanced English
description: Advanced english course with 5 modules and separated lessons for improving speaking, listening and reading.
author: 63da8767c9ad4c9a0b0eacd3
attachments: [ 63ed1cd25e9d781cdb6a6b15 ]
lessons: [ 63ed1cd25e9d781cdb6a6b17, 63ac1ad47e9d526cdb6f4n51 ]
category: 64884f33fdc2d1a130c24ac2
subject: 6488509cfdc2d1a130c24ae4
proficiencyLevel: [Advanced]
sections:
- title: Section First
description: some description
lessons: [63ed1cd25e9d781cdb6a6b17, 63ac1ad47e9d526cdb6f4n51]
quizzes: [64ba39c714b7bc037a29d712]
attachments: [63ed1cd25e9d781cdb6a6b15]
_id: 63ec1cd51e9d781cdb6f4b14
createdAt: 2023-02-14T23:44:21.334Z
updatedAt: 2023-02-14T23:44:21.334Z
Expand Down Expand Up @@ -209,8 +237,15 @@ paths:
title: Advanced English
description: Advanced english course with 5 modules and separated lessons for improving speaking, listening and reading.
author: 63da8767c9ad4c9a0b0eacd3
attachments: [ 63ed1cd25e9d781cdb6a6b15 ]
lessons: [ 63ed1cd25e9d781cdb6a6b17, 63ac1ad47e9d526cdb6f4n51 ]
category: 64884f33fdc2d1a130c24ac2
subject: 6488509cfdc2d1a130c24ae4
proficiencyLevel: [Advanced]
sections:
- title: Section First
description: some description
lessons: [63ed1cd25e9d781cdb6a6b17, 63ac1ad47e9d526cdb6f4n51]
quizzes: [64ba39c714b7bc037a29d712]
attachments: [63ed1cd25e9d781cdb6a6b15]
_id: 63ec1cd51e9d781cdb6f4b14
createdAt: 2023-02-14T23:44:21.334Z
updatedAt: 2023-02-14T23:44:21.334Z
Expand Down Expand Up @@ -281,4 +316,4 @@ paths:
example:
status: 404
code: DOCUMENT_NOT_FOUND
message: Course with the specified id was not found.
message: Course with the specified id was not found.
73 changes: 64 additions & 9 deletions models/course.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
const { Schema, model } = require('mongoose')

const { FIELD_CANNOT_BE_EMPTY, FIELD_CANNOT_BE_SHORTER, FIELD_CANNOT_BE_LONGER } = require('~/consts/errors')
const { COURSE, USER, LESSON, ATTACHMENT } = require('~/consts/models')
const {
ENUM_CAN_BE_ONE_OF,
FIELD_CANNOT_BE_EMPTY,
FIELD_CANNOT_BE_SHORTER,
FIELD_CANNOT_BE_LONGER
} = require('~/consts/errors')

const {
COURSE,
USER,
LESSON,
ATTACHMENT,
QUIZ,
CATEGORY,
SUBJECT
} = require('~/consts/models')

const {
enums: {
PROFICIENCY_LEVEL_ENUM
}
} = require('~/consts/validation')

const courseSchema = new Schema(
{
Expand All @@ -22,14 +42,49 @@ const courseSchema = new Schema(
ref: USER,
required: [true, FIELD_CANNOT_BE_EMPTY('author')]
},
lessons: {
type: [Schema.Types.ObjectId],
ref: LESSON
category: {
type: Schema.Types.ObjectId,
ref: CATEGORY,
default: null
},
subject: {
type: Schema.Types.ObjectId,
ref: SUBJECT,
required: [true, FIELD_CANNOT_BE_EMPTY('author')]
},
proficiencyLevel: {
type: [String],
enum: {
values: PROFICIENCY_LEVEL_ENUM,
message: ENUM_CAN_BE_ONE_OF('proficiency level', PROFICIENCY_LEVEL_ENUM)
},
required: [true, FIELD_CANNOT_BE_EMPTY('proficiency level')]
},
attachments: {
type: [Schema.Types.ObjectId],
ref: ATTACHMENT
}
sections: [{
title: {
type: String,
required: [true, FIELD_CANNOT_BE_EMPTY('title')],
minLength: [1, FIELD_CANNOT_BE_SHORTER('title', 1)],
maxLength: [100, FIELD_CANNOT_BE_LONGER('title', 100)]
},
description: {
type: String,
maxLength: [150, FIELD_CANNOT_BE_LONGER('description', 150)],
trim: true
},
lessons: {
type: [Schema.Types.ObjectId],
ref: LESSON
},
quizzes: {
type: [Schema.Types.ObjectId],
ref: QUIZ
},
attachments: {
type: [Schema.Types.ObjectId],
ref: ATTACHMENT
}
}]
},
{
versionKey: false,
Expand Down
15 changes: 12 additions & 3 deletions services/course.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@ const courseService = {
},

createCourse: async (author, data) => {
const { title, description, lessons, attachments } = data
const {
title,
description,
category,
subject,
proficiencyLevel,
sections
} = data

return await Course.create({
title,
description,
author,
lessons,
attachments
category,
subject,
proficiencyLevel,
sections
})
},

Expand Down
Loading
Loading