Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
360macky committed Nov 6, 2021
2 parents 9af6fb7 + 05b7ef9 commit 5bf6628
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 25 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/codesee-arch-diagram.yml
Original file line number Diff line number Diff line change
@@ -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 }}
25 changes: 23 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
node_modules
.env
# 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*
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"arrowParens": "always",
"useTabs": false,
"tabWidth": 4
}
34 changes: 33 additions & 1 deletion src/Graphql/Resolvers/courses.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Course = require('../../Models/Courses');
const User = require('../../Models/Users');
const checkAuth = require('../../Util/check_auth');

module.exports = {

Expand Down Expand Up @@ -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: {
Expand All @@ -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,
}

});

Expand Down
18 changes: 17 additions & 1 deletion src/Graphql/Resolvers/homeworks.js
Original file line number Diff line number Diff line change
@@ -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 = {

Expand Down Expand Up @@ -33,7 +36,7 @@ module.exports = {

Mutation: {

async createHomework(_, { courseId, title, content }, context) {
async createHomework(_, { courseId, title, content, endDate }, context) {

const user = checkAuth(context);

Expand All @@ -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;

},
Expand Down
7 changes: 2 additions & 5 deletions src/Graphql/Resolvers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function generateToken(user) {
lastname: user.lastname,
email: user.email,
cellphone: user.cellphone,
username: user.username
},
SECRET_KEY,
{
Expand Down Expand Up @@ -102,16 +101,15 @@ module.exports = {

async registerUser(_, {
name,
lastname,
username,
lastname,
cellphone,
email,
rol,
password,
confirmPassword
}) {

const { valid, errors } = validateRegisterInput(username, email, password, confirmPassword);
const { valid, errors } = validateRegisterInput(email, password, confirmPassword);

if(!valid) {
throw new UserInputError('Errors', {errors});
Expand All @@ -130,7 +128,6 @@ module.exports = {
const newUser = new User({
name,
lastname,
username,
cellphone,
email,
rol,
Expand Down
12 changes: 10 additions & 2 deletions src/Graphql/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!]
}
Expand Down Expand Up @@ -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]
Expand All @@ -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!
Expand Down
11 changes: 7 additions & 4 deletions src/Models/Courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
20 changes: 20 additions & 0 deletions src/Models/Reminders.js
Original file line number Diff line number Diff line change
@@ -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);
6 changes: 0 additions & 6 deletions src/Models/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions src/Util/random_number.js
Original file line number Diff line number Diff line change
@@ -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 + "<br>");
n++;
if (n == 1) {
uno = numero;
}
if (n == 2) {
dos = numero;
}
if (n == 3) {
tres = numero;
}
}
}while (numero < 3);

return {
uno,
dos,
tres
}

}
4 changes: 0 additions & 4 deletions src/Util/validator.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 5bf6628

Please sign in to comment.