From a59c242ee1b70a744fad4b6552b50f41eb1b6d83 Mon Sep 17 00:00:00 2001 From: Diana Vashchilina <dianavashch@gmail.com> Date: Tue, 26 Nov 2024 16:22:51 +0200 Subject: [PATCH] Add a status field for resources in cooperation model (#966) * add completionStatus field to resources in cooperations * update docs for cooperation to include completionStatus * add availableQuizzes finishedQuizzes to docs for cooperation * add missing info to docs for cooperations * fix ref errors in docs for cooperation * fix docs user schema for cooperation * fix docs body schemas to have id strings instead of refs --- docs/cooperation/cooperation-schema.yaml | 529 +++++------------------ docs/cooperation/cooperation.yaml | 20 +- docs/quiz/quiz-schema.yaml | 103 ++--- docs/user/user-schema.yaml | 13 +- src/consts/validation.js | 1 + src/models/cooperation.js | 11 +- 6 files changed, 207 insertions(+), 470 deletions(-) diff --git a/docs/cooperation/cooperation-schema.yaml b/docs/cooperation/cooperation-schema.yaml index 6c8fc989..0d80d806 100644 --- a/docs/cooperation/cooperation-schema.yaml +++ b/docs/cooperation/cooperation-schema.yaml @@ -7,22 +7,32 @@ definitions: _id: type: string offer: - type: string - ref: '#components/offer' + $ref: '#/definitions/offer' initiator: - type: string - ref: '#/components/user' + $ref: '#/definitions/user' initiatorRole: type: string receiver: - type: string - ref: '#components/user' + $ref: '#/definitions/user' receiverRole: type: string price: type: number title: type: string + additionalInfo: + type: string + minLength: 30 + maxLength: 1000 + proficiencyLevel: + type: string + enum: + - Beginner + - Intermediate + - Advanced + - Test Preparation + - Professional + - Specialized status: type: string enum: @@ -30,39 +40,65 @@ definitions: - active - declined - closed + availableQuizzes: + type: array + items: + $ref: '#/definitions/quiz' + finishedQuizzes: + type: array + items: + $ref: '#/definitions/finishedQuiz' needAction: type: string enum: - student - tutor - createdAt: - type: string - format: date-time - updatedAt: - type: string - format: date-time + user: + type: object + description: Details of the partner user involved in the cooperation + properties: + _id: + type: string + firstName: + type: string + lastName: + type: string + photo: + type: string + role: + type: string cooperation: type: object properties: _id: type: string offer: - type: string - ref: '#components/offer' + $ref: '#/definitions/offer' initiator: - type: string - ref: '#/components/user' + $ref: '#/definitions/user' initiatorRole: type: string receiver: - type: string - ref: '#components/user' + $ref: '#/definitions/user' receiverRole: type: string price: type: number title: type: string + additionalInfo: + type: string + minLength: 30 + maxLength: 1000 + proficiencyLevel: + type: string + enum: + - Beginner + - Intermediate + - Advanced + - Test Preparation + - Professional + - Specialized status: type: string enum: @@ -70,43 +106,18 @@ definitions: - active - declined - closed + availableQuizzes: + type: array + items: + $ref: '#/definitions/quiz' + finishedQuizzes: + type: array + items: + $ref: '#/definitions/finishedQuiz' sections: type: array items: - type: object - properties: - title: - type: string - description: - type: string - resources: - type: array - items: - type: object - properties: - resource: - type: object - additionalProperties: true - resourceType: - type: string - enum: - - lesson - - quiz - - attachment - availability: - type: object - properties: - status: - type: string - enum: - - open - - closed - - openFrom - default: open - date: - type: string - format: date-time - default: null + $ref: '#/definitions/section' needAction: type: string enum: @@ -123,385 +134,79 @@ definitions: properties: offer: type: string - ref: '#components/offer' + description: _id + ref: '#/definitions/offer' receiver: type: string - ref: '#components/user' + description: _id + ref: '#/definitions/user' receiverRole: type: string price: type: number - status: + title: + type: string + additionalInfo: + type: string + minLength: 30 + maxLength: 1000 + proficiencyLevel: type: string enum: - - pending - - active - - declined - - closed + - Beginner + - Intermediate + - Advanced + - Test Preparation + - Professional + - Specialized sections: type: array items: - type: object - properties: - title: - type: string - description: - type: string - resources: - type: array - items: - type: object - properties: - resource: - type: object - additionalProperties: true - resourceType: - type: string - enum: - - lesson - - quiz - - attachment - availability: - type: object - properties: - status: - type: string - enum: - - open - - closed - - openFrom - default: open - date: - type: string - format: date-time - default: null - cooperationResponse: + $ref: '#/definitions/section' + required: + - title + - offer + - receiver + - proficiencyLevel + - receiverRole + - price + section: type: object properties: - _id: - type: string - offer: - type: object - properties: - _id: - type: string - proficiencyLevel: - type: array - items: - type: string - title: - type: string - description: - type: string - languages: - type: array - items: - type: string - author: - type: object - properties: - totalReviews: - type: object - properties: - student: - type: integer - tutor: - type: integer - averageRating: - type: object - properties: - student: - type: number - tutor: - type: number - _id: - type: string - firstName: - type: string - lastName: - type: string - photo: - type: string - professionalSummary: - type: string - subject: - type: object - properties: - _id: - type: string - name: - type: string - category: - type: object - properties: - appearance: - type: object - properties: - color: - type: string - icon: - type: string - _id: - type: string - name: - type: string - initiator: - type: object - properties: - address: - type: object - properties: - country: - type: string - city: - type: string - mainSubjects: - type: object - properties: - student: - type: array - items: - type: string - tutor: - type: array - items: - type: string - totalReviews: - type: object - properties: - student: - type: integer - tutor: - type: integer - averageRating: - type: object - properties: - student: - type: number - tutor: - type: number - status: - type: object - properties: - student: - type: string - tutor: - type: string - admin: - type: string - videoLink: - type: object - properties: - student: - type: string - professionalBlock: - type: object - properties: - awards: - type: string - scientificActivities: - type: string - workExperience: - type: string - education: - type: string - notificationSettings: - type: object - properties: - isOfferStatusNotification: - type: boolean - isChatNotification: - type: boolean - isSimilarOffersNotification: - type: boolean - isEmailNotification: - type: boolean - _id: - type: string - role: - type: array - items: - type: string - firstName: - type: string - lastName: - type: string - email: - type: string - nativeLanguage: - type: string - lastLogin: - type: string - createdAt: - type: string - updatedAt: - type: string - professionalSummary: - type: string - initiatorRole: - type: string - receiver: - type: object - properties: - address: - type: object - properties: - country: - type: string - city: - type: string - mainSubjects: - type: object - properties: - student: - type: array - items: - type: string - tutor: - type: array - items: - type: object - properties: - category: - type: string - subjects: - type: array - items: - type: string - _id: - type: string - totalReviews: - type: object - properties: - student: - type: integer - tutor: - type: integer - averageRating: - type: object - properties: - student: - type: number - tutor: - type: number - status: - type: object - properties: - student: - type: string - tutor: - type: string - admin: - type: string - videoLink: - type: object - properties: - tutor: - type: string - professionalBlock: - type: object - properties: - awards: - type: string - scientificActivities: - type: string - workExperience: - type: string - education: - type: string - notificationSettings: - type: object - properties: - isOfferStatusNotification: - type: boolean - isChatNotification: - type: boolean - isSimilarOffersNotification: - type: boolean - isEmailNotification: - type: boolean - _id: - type: string - role: - type: array - items: - type: string - firstName: - type: string - lastName: - type: string - email: - type: string - nativeLanguage: - type: string - lastLogin: - type: string - createdAt: - type: string - updatedAt: - type: string - photo: - type: string - professionalSummary: - type: string - receiverRole: - type: string title: type: string - proficiencyLevel: + description: type: string - price: - type: integer - status: - type: string - needAction: - type: string - availableQuizzes: - type: array - items: - type: string - finishedQuizzes: - type: array - items: - type: string - sections: + resources: type: array items: type: object properties: - title: + resource: + type: object + additionalProperties: true + resourceType: type: string - description: + enum: + - lesson + - quiz + - attachment + availability: + type: object + properties: + status: + type: string + enum: + - open + - closed + - openFrom + default: open + date: + type: string + format: date-time + default: null + completionStatus: type: string - resources: - type: array - items: - type: object - properties: - resource: - type: object - additionalProperties: true - resourceType: - type: string - enum: - - lesson - - quiz - - attachment - availability: - type: object - properties: - status: - type: string - enum: - - open - - closed - - openFrom - default: open - date: - type: string - format: date-time - default: null - createdAt: - type: string - updatedAt: - type: string + enum: + - active + - completed diff --git a/docs/cooperation/cooperation.yaml b/docs/cooperation/cooperation.yaml index f68472de..999ff63a 100644 --- a/docs/cooperation/cooperation.yaml +++ b/docs/cooperation/cooperation.yaml @@ -30,7 +30,12 @@ paths: needAction: student availableQuizzes: [] finishedQuizzes: [] - sections: [] + user: + _id: '6255bc080a75adf9223df100' + firstName: 'Emily' + lastName: 'Jhonson' + photo: '' + role: 'student' createdAt: 2021-05-09T11:34:53.243+00:00 updatedAt: 2022-07-02T11:59:53.243+00:00 - _id: 63ebc6fbd2f34037d0aba314 @@ -46,7 +51,12 @@ paths: needAction: tutor availableQuizzes: [] finishedQuizzes: [] - sections: [] + user: + _id: '6255bc080a75adf9223df100' + firstName: 'Emily' + lastName: 'Jhonson' + photo: '' + role: 'student' createdAt: 2021-04-09T11:34:53.243+00:00 updatedAt: 2022-09-02T11:59:53.243+00:00 401: @@ -74,8 +84,10 @@ paths: content: application/json: schema: - $ref: '#/definitions/cooperation' + $ref: '#/definitions/cooperationBody' example: + title: Violin lessons + proficiencyLevel: Test Preparation offer: 63ebc6fbd2f34037d0aba791 receiver: 6255bc080a75adf9223df100 receiverRole: student @@ -147,7 +159,7 @@ paths: content: application/json: schema: - $ref: '#/definitions/cooperationResponse' + $ref: '#/definitions/cooperation' example: _id: 8755bc080a00adr9243df106 offer: diff --git a/docs/quiz/quiz-schema.yaml b/docs/quiz/quiz-schema.yaml index afd648c5..9990657a 100644 --- a/docs/quiz/quiz-schema.yaml +++ b/docs/quiz/quiz-schema.yaml @@ -8,32 +8,31 @@ definitions: type: string title: type: string - description: + description: type: string items: type: array - $ref: '#/components/question' + items: + $ref: '#/definitions/question' author: - type: string - $ref: '#/components/user' + $ref: '#/definitions/user' category: - type: string $ref: '#/definitions/resourcesCategory' - settings: + settings: type: object - properties: + properties: view: type: string - enum: + enum: - Stepper - Scroll shuffle: type: boolean pointValues: type: boolean - scoredResponses: + scoredResponses: type: boolean - correctAnswers: + correctAnswers: type: boolean createdAt: type: string @@ -46,30 +45,34 @@ definitions: properties: title: type: string - description: + description: type: string category: type: string - $ref: '#/definitions/resourcesCategory' + description: _id + ref: '#/definitions/resourcesCategory' items: type: array - $ref: '#/components/question' - settings: - type: object - properties: - view: - type: string - enum: - - Stepper - - Scroll - shuffle: - type: boolean - pointValues: - type: boolean - scoredResponses: - type: boolean - correctAnswers: - type: boolean + items: + type: string + description: _id + ref: '#/components/question' + settings: + type: object + properties: + view: + type: string + enum: + - Stepper + - Scroll + shuffle: + type: boolean + pointValues: + type: boolean + scoredResponses: + type: boolean + correctAnswers: + type: boolean quiz: type: object properties: @@ -77,37 +80,35 @@ definitions: type: string title: type: string - description: + description: type: string items: type: array - $ref: '#/components/question' + items: + $ref: '#/definitions/question' author: - type: string - $ref: '#/components/user' + $ref: '#/definitions/user' category: - type: string $ref: '#/definitions/resourcesCategory' - settings: - type: object - properties: - view: - type: string - enum: - - Stepper - - Scroll - shuffle: - type: boolean - pointValues: - type: boolean - scoredResponses: - type: boolean - correctAnswers: - type: boolean + settings: + type: object + properties: + view: + type: string + enum: + - Stepper + - Scroll + shuffle: + type: boolean + pointValues: + type: boolean + scoredResponses: + type: boolean + correctAnswers: + type: boolean createdAt: type: string format: date-time updatedAt: type: string format: date-time - \ No newline at end of file diff --git a/docs/user/user-schema.yaml b/docs/user/user-schema.yaml index 90c805a1..cf67af55 100644 --- a/docs/user/user-schema.yaml +++ b/docs/user/user-schema.yaml @@ -221,8 +221,17 @@ definitions: type: number nativeLanguage: type: string - notificatoinSettings: - + notificationSettings: + type: object + properties: + isOfferStatusNotification: + type: boolean + isChatNotification: + type: boolean + isSimilarOffersNotification: + type: boolean + isEmailNotification: + type: boolean address: type: object properties: diff --git a/src/consts/validation.js b/src/consts/validation.js index 127be5df..a21266f4 100644 --- a/src/consts/validation.js +++ b/src/consts/validation.js @@ -29,6 +29,7 @@ const enums = { QUIZ_SETTINGS_ENUM: ['view', 'shuffle', 'pointValues', 'scoredResponses', 'correctAnswers'], RESOURCE_STATUS_ENUM: ['available', 'finished'], RESOURCE_AVAILABILITY_STATUS_ENUM: ['open', 'closed', 'openFrom'], + RESOURCE_COMPLETION_STATUS_ENUM: ['active', 'completed'], RESOURCES_TYPES_ENUM: ['lesson', 'quiz', 'attachment', 'question'] } diff --git a/src/models/cooperation.js b/src/models/cooperation.js index f6834f10..39b50fe4 100644 --- a/src/models/cooperation.js +++ b/src/models/cooperation.js @@ -14,7 +14,8 @@ const { PROFICIENCY_LEVEL_ENUM, MAIN_ROLE_ENUM, RESOURCES_TYPES_ENUM, - RESOURCE_AVAILABILITY_STATUS_ENUM + RESOURCE_AVAILABILITY_STATUS_ENUM, + RESOURCE_COMPLETION_STATUS_ENUM } } = require('~/consts/validation') const { REQUESTED, UPDATED } = require('~/consts/notificationTypes') @@ -144,6 +145,14 @@ const cooperationSchema = new Schema( type: Date, default: null } + }, + completionStatus: { + type: String, + enum: { + values: RESOURCE_COMPLETION_STATUS_ENUM, + message: ENUM_CAN_BE_ONE_OF('resource completion status', RESOURCE_COMPLETION_STATUS_ENUM) + }, + default: RESOURCE_COMPLETION_STATUS_ENUM[0] } } ]