diff --git a/.github/workflows/codesee-arch-diagram.yml b/.github/workflows/codesee-arch-diagram.yml new file mode 100644 index 0000000..16b971e --- /dev/null +++ b/.github/workflows/codesee-arch-diagram.yml @@ -0,0 +1,81 @@ +on: + push: + branches: + - main + pull_request_target: + types: [opened, synchronize, reopened] + +name: CodeSee Map + +jobs: + test_map_action: + runs-on: ubuntu-latest + continue-on-error: true + name: Run CodeSee Map Analysis + steps: + - name: checkout + id: checkout + uses: actions/checkout@v2 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.event.pull_request.head.ref }} + fetch-depth: 0 + + # codesee-detect-languages has an output with id languages. + - name: Detect Languages + id: detect-languages + uses: Codesee-io/codesee-detect-languages-action@latest + + - name: Configure JDK 16 + uses: actions/setup-java@v2 + if: ${{ fromJSON(steps.detect-languages.outputs.languages).java }} + with: + java-version: '16' + distribution: 'zulu' + + # CodeSee Maps Go support uses a static binary so there's no setup step required. + + - name: Configure Node.js 14 + uses: actions/setup-node@v2 + if: ${{ fromJSON(steps.detect-languages.outputs.languages).javascript }} + with: + node-version: '14' + + - name: Configure Python 3.x + uses: actions/setup-python@v2 + if: ${{ fromJSON(steps.detect-languages.outputs.languages).python }} + with: + python-version: '3.x' + architecture: 'x64' + + - name: Configure Ruby '3.x' + uses: ruby/setup-ruby@v1 + if: ${{ fromJSON(steps.detect-languages.outputs.languages).ruby }} + with: + ruby-version: '3.0' + + # CodeSee Maps Rust support uses a static binary so there's no setup step required. + + - name: Generate Map + id: generate-map + uses: Codesee-io/codesee-map-action@latest + with: + step: map + github_ref: ${{ github.ref }} + languages: ${{ steps.detect-languages.outputs.languages }} + + - name: Upload Map + id: upload-map + uses: Codesee-io/codesee-map-action@latest + with: + step: mapUpload + api_token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }} + github_ref: ${{ github.ref }} + + - name: Insights + id: insights + uses: Codesee-io/codesee-map-action@latest + with: + step: insights + api_token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }} + github_ref: ${{ github.ref }} diff --git a/.gitignore b/.gitignore index 1dcef2d..4d29575 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,23 @@ -node_modules -.env \ No newline at end of file +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..2a74ad3 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "arrowParens": "always", + "useTabs": false, + "tabWidth": 4 +} diff --git a/src/Graphql/Resolvers/courses.js b/src/Graphql/Resolvers/courses.js index e7b08cd..cfc97f7 100644 --- a/src/Graphql/Resolvers/courses.js +++ b/src/Graphql/Resolvers/courses.js @@ -1,5 +1,6 @@ const Course = require('../../Models/Courses'); const User = require('../../Models/Users'); +const checkAuth = require('../../Util/check_auth'); module.exports = { @@ -41,6 +42,30 @@ module.exports = { } }, + async getCourse(_, { courseId }, context) { + + try { + + const student = checkAuth(context); + + if(!student) { + throw new Error('No se encuentra disponible') + } + + const course = await Course.findOne({ + $and: [ + {'_id': courseId}, + {'students.student_id': student.id} + ] + }); + + return course; + + } catch (err) { + throw new Error(err); + } + + } }, Mutation: { @@ -51,11 +76,18 @@ module.exports = { teacherId }) { + const teacher = await User.findById(teacherId); + const newCourse = new Course({ name, grade_section, - teacher_id: teacherId + teacher: { + teacher_id: teacher.id, + name: teacher.name, + email: teacher.email, + cellphone: teacher.cellphone, + } }); diff --git a/src/Graphql/Resolvers/homeworks.js b/src/Graphql/Resolvers/homeworks.js index 850e601..1297d2d 100644 --- a/src/Graphql/Resolvers/homeworks.js +++ b/src/Graphql/Resolvers/homeworks.js @@ -1,6 +1,9 @@ const Homework = require('../../Models/Homework'); +const Course = require('../../Models/Courses'); +const Reminder = require('../../Models/Reminders'); const checkAuth = require('../../Util/check_auth'); const { UserInputError } = require('apollo-server'); +const { findById } = require('../../Models/Reminders'); module.exports = { @@ -33,7 +36,7 @@ module.exports = { Mutation: { - async createHomework(_, { courseId, title, content }, context) { + async createHomework(_, { courseId, title, content, endDate }, context) { const user = checkAuth(context); @@ -54,6 +57,19 @@ module.exports = { const res = await newHomework.save(); + const course = await findById(course_id); + + if(res) { + const newReminder = new Reminder({ + homework_id: res.id, + title: res.title, + endDate: endDate, + students: course.students, + }); + + await newReminder.save(); + } + return res; }, diff --git a/src/Graphql/Resolvers/users.js b/src/Graphql/Resolvers/users.js index e20fbe4..f2e52d5 100644 --- a/src/Graphql/Resolvers/users.js +++ b/src/Graphql/Resolvers/users.js @@ -15,7 +15,6 @@ function generateToken(user) { lastname: user.lastname, email: user.email, cellphone: user.cellphone, - username: user.username }, SECRET_KEY, { @@ -102,8 +101,7 @@ module.exports = { async registerUser(_, { name, - lastname, - username, + lastname, cellphone, email, rol, @@ -111,7 +109,7 @@ module.exports = { confirmPassword }) { - const { valid, errors } = validateRegisterInput(username, email, password, confirmPassword); + const { valid, errors } = validateRegisterInput(email, password, confirmPassword); if(!valid) { throw new UserInputError('Errors', {errors}); @@ -130,7 +128,6 @@ module.exports = { const newUser = new User({ name, lastname, - username, cellphone, email, rol, diff --git a/src/Graphql/typeDefs.js b/src/Graphql/typeDefs.js index 5bd66b5..4edae0e 100644 --- a/src/Graphql/typeDefs.js +++ b/src/Graphql/typeDefs.js @@ -33,12 +33,19 @@ module.exports = gql` } + type Teacher { + teacher_id: ID! + name: String! + email: String! + cellphone: Int! + } + type Course { id: ID! name: String! grade_section: ID! - teacher_id: ID! + teacher: Teacher students: [Student!] } @@ -94,6 +101,7 @@ module.exports = gql` getUsers: [User] getUser(userId: ID!): User getCourses(userId: ID!): [Course] + getCourse(courseId: ID!): Course getGrades: [Grade] getHomeworks(courseId: ID!, userId: ID!): [Homework] @@ -102,7 +110,7 @@ module.exports = gql` type Mutation { login(email: String!, password: String!): User - registerUser(name: String!, lastname: String!, username: String!, cellphone: Int!, email: String!, rol: String!, password: String!, confirmPassword: String! ): User + registerUser(name: String!, lastname: String!, cellphone: Int!, email: String!, rol: String!, password: String!, confirmPassword: String! ): User updateUser(userId: ID!, name: String!, lastname: String!, email: String!): User deleteUser(userId: ID!): String createGrade(grade: String!, section: String!, teacherId: String!): Grade! diff --git a/src/Models/Courses.js b/src/Models/Courses.js index 66327ec..78d479f 100644 --- a/src/Models/Courses.js +++ b/src/Models/Courses.js @@ -11,10 +11,13 @@ const courseSchema = new Schema({ ref: 'Grades', required: true, }, - teacher_id: { - type: Schema.Types.ObjectId, - ref: 'Users', - required: true, + teacher: { + _id: false, + teacher_id: { type: Schema.Types.ObjectId, ref: 'User' }, + name: { type: String }, + email: { type: String }, + cellphone: { type: Number }, + }, students: [ { diff --git a/src/Models/Reminders.js b/src/Models/Reminders.js new file mode 100644 index 0000000..3cfc16a --- /dev/null +++ b/src/Models/Reminders.js @@ -0,0 +1,20 @@ +const { Schema, model } = require('mongoose'); + +const reminderSchema = new Schema({ + + homework_id: { type: Schema.Types.ObjectId, ref: 'Homework' }, + title: { type: String }, + endDate: { type: Date }, + students: [ + { + _id: false, + student_id: { + type: Schema.Types.ObjectId, + ref: 'Users', + }, + } + ] + +}); + +module.exports = model('Reminder', reminderSchema); \ No newline at end of file diff --git a/src/Models/Users.js b/src/Models/Users.js index 5987e87..05f4b87 100644 --- a/src/Models/Users.js +++ b/src/Models/Users.js @@ -9,12 +9,6 @@ const userSchema = new Schema({ type: String, required: true }, - username:{ - type: String, - required: true, - trim: true, - unique: true - }, cellphone:{ type: Number, required: true, diff --git a/src/Util/random_number.js b/src/Util/random_number.js new file mode 100644 index 0000000..2e4d023 --- /dev/null +++ b/src/Util/random_number.js @@ -0,0 +1,30 @@ +module.exports.randomNumber = () => { + var n = 0; + var numero; + var uno = 0; + var dos = 0; + var tres = 3; + do { + numero = Math.floor((Math.random() * 50) + 1); + if ((numero != uno) && (numero != dos) && (numero != 3)) { + document.write(numero + "
"); + n++; + if (n == 1) { + uno = numero; + } + if (n == 2) { + dos = numero; + } + if (n == 3) { + tres = numero; + } + } + }while (numero < 3); + + return { + uno, + dos, + tres + } + +} \ No newline at end of file diff --git a/src/Util/validator.js b/src/Util/validator.js index f1fdb78..ba7b4b1 100644 --- a/src/Util/validator.js +++ b/src/Util/validator.js @@ -1,13 +1,9 @@ module.exports.validateRegisterInput = ( - username, email, password, confirmPassword ) => { const errors = {}; - if (username.trim() === '') { - errors.username = 'Username must not be empty'; - } if (email.trim() === '') { errors.email = 'Email must not be empty'; } else {