-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79cdfde
commit 270c646
Showing
262 changed files
with
17,729 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
PORT = 8080 | ||
JWT_SECRET = hola | ||
MONGODB_URL = mongodb://localhost:27017/project | ||
MONGODB_URL_TEST = mongodb://localhost:27017/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.node_modules | ||
.coverage | ||
coverage | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Schema, model, Types } from 'mongoose' | ||
|
||
const { ObjectId } = Types | ||
|
||
const activity = new Schema({ | ||
teacher: { | ||
type: ObjectId, | ||
required: true, | ||
ref: 'User' | ||
}, | ||
title: { | ||
type: String, | ||
required: true | ||
}, | ||
description: { | ||
type: String, | ||
required: false | ||
} | ||
}) | ||
|
||
const Activity = model('Activity', activity) | ||
|
||
export default Activity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Schema, model, Types } from 'mongoose' | ||
|
||
const { ObjectId } = Types | ||
|
||
const answer = new Schema({ | ||
student: { | ||
type: ObjectId, | ||
required: true | ||
}, | ||
exercise: { | ||
type: ObjectId, | ||
required: true, | ||
unique: true | ||
}, | ||
activity: { | ||
type: ObjectId, | ||
required: true | ||
}, | ||
answer: { | ||
type: String, | ||
required: true | ||
} | ||
}) | ||
|
||
const Answer = model('Answer', answer) | ||
|
||
export default Answer | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Schema, model, Types } from 'mongoose' | ||
|
||
const { ObjectId } = Types | ||
|
||
const exercise = new Schema({ | ||
activity: { | ||
type: ObjectId, | ||
required: true, | ||
ref: 'Activity' | ||
}, | ||
index: { | ||
type: Number, | ||
required: true | ||
}, | ||
type: { | ||
type: String, | ||
enum: ['completeSentence', 'orderSentence', 'vocabulary'] | ||
} | ||
}, { discriminatorKey: 'type' }) | ||
|
||
const Exercise = model('Exercise', exercise) | ||
|
||
const completeSentenceSchema = new Schema({ | ||
sentence: { | ||
type: String, | ||
required: true | ||
}, | ||
answer: { | ||
type: String, | ||
required: true | ||
} | ||
}); | ||
|
||
const CompleteSentenceExercise = Exercise.discriminator('completeSentence', completeSentenceSchema); | ||
|
||
const orderSentenceSchema = new Schema({ | ||
sentence: { | ||
type: String, | ||
required: true | ||
}, | ||
translate: { | ||
type: String, | ||
required: true | ||
}, | ||
}); | ||
|
||
const OrderSentenceExercise = Exercise.discriminator('orderSentence', orderSentenceSchema); | ||
|
||
const vocabularyExerciseSchema = new Schema({ | ||
word: { | ||
type: String, | ||
required: true | ||
}, | ||
answer: { | ||
type: [String], | ||
required: true | ||
} | ||
}); | ||
|
||
const VocabularyExercise = Exercise.discriminator('vocabulary', vocabularyExerciseSchema); | ||
|
||
export { | ||
Exercise, | ||
CompleteSentenceExercise, | ||
OrderSentenceExercise, | ||
VocabularyExercise | ||
} | ||
|
||
export default Exercise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Schema, Types, model } from 'mongoose' | ||
const { ObjectId } = Types | ||
|
||
const user = new Schema({ | ||
name: { | ||
type: String, | ||
required: true | ||
}, | ||
surname: { | ||
type: String, | ||
required: true | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
unique: true | ||
}, | ||
username: { | ||
type: String, | ||
required: true, | ||
unique: true | ||
}, | ||
password: { | ||
type: String, | ||
required: true | ||
}, | ||
userType: { | ||
type: String, | ||
required: true | ||
}, | ||
student: [{ | ||
type: ObjectId, | ||
ref: "User" | ||
}] | ||
}) | ||
|
||
const User = model('User', user) | ||
|
||
export default User |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import User from './User.js' | ||
import Activity from './Activity.js' | ||
import Exercise from './Exercise.js' | ||
import Answer from './Answer.js' | ||
|
||
export { | ||
User, | ||
Activity, | ||
Answer, | ||
Exercise, | ||
} |
31 changes: 31 additions & 0 deletions
31
staff/agustin-birman/project/api/handlers/addStudentHandler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import logic from '../logic/index.js' | ||
import jwt from '../util/jsonwebtoken-promised.js' | ||
import { CredentialsError } from 'com/errors.js' | ||
|
||
const { JWT_SECRET } = process.env | ||
|
||
export default (req, res, next) => { | ||
try { | ||
const token = req.headers.authorization.slice(7) | ||
|
||
jwt.verify(token, JWT_SECRET) | ||
.then(payload => { | ||
|
||
const { sub: userId } = payload | ||
|
||
const { studentId } = req.body | ||
|
||
try { | ||
logic.addStudent(userId, studentId) | ||
.then(() => res.status(201).send()) | ||
.catch(error => next(error)) | ||
} catch (error) { | ||
next(error) | ||
} | ||
}) | ||
.catch(error => next(new CredentialsError(error.message))) | ||
|
||
} catch (error) { | ||
next(error) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
staff/agustin-birman/project/api/handlers/authenticateUserHandler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import jwt from '../util/jsonwebtoken-promised.js' | ||
|
||
import logic from '../logic/index.js' | ||
|
||
import { SystemError } from 'com/errors.js' | ||
|
||
const { JWT_SECRET } = process.env | ||
|
||
export default (req, res, next) => { | ||
const { username, password } = req.body | ||
|
||
try { | ||
logic.authenticateUser(username, password) | ||
.then(user => { | ||
const { id: userId, role } = user | ||
|
||
jwt.sign({ sub: userId, role }, JWT_SECRET, { expiresIn: '1h' }) | ||
.then(token => res.json(token)) | ||
.catch(error => { | ||
next(new SystemError(error.message)) | ||
}) | ||
}) | ||
.catch(error => next(error)) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
staff/agustin-birman/project/api/handlers/checkCompleteActivityHandler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import jwt from '../util/jsonwebtoken-promised.js' | ||
|
||
import logic from '../logic/index.js' | ||
|
||
import { CredentialsError } from 'com/errors.js' | ||
|
||
const { JWT_SECRET } = process.env | ||
|
||
export default (req, res, next) => { | ||
try { | ||
const token = req.headers.authorization.slice(7) | ||
|
||
jwt.verify(token, JWT_SECRET) | ||
.then(payload => { | ||
const { sub: userId } = payload | ||
|
||
const { activityId } = req.params | ||
|
||
try { | ||
logic.checkCompleteActivity(userId, activityId) | ||
.then(result => res.json(result)) | ||
.catch(error => next(error)) | ||
} catch (error) { | ||
next(error) | ||
} | ||
}) | ||
.catch(error => next(new CredentialsError(error.message))) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
staff/agustin-birman/project/api/handlers/createActivityHandler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import jwt from '../util/jsonwebtoken-promised.js' | ||
|
||
import logic from '../logic/index.js' | ||
|
||
import { CredentialsError } from 'com/errors.js' | ||
|
||
const { JWT_SECRET } = process.env | ||
|
||
export default (req, res, next) => { | ||
try { | ||
const token = req.headers.authorization.slice(7) | ||
|
||
jwt.verify(token, JWT_SECRET) | ||
.then(payload => { | ||
const { sub: userId } = payload | ||
|
||
const { title, description } = req.body | ||
try { | ||
logic.createActivity(userId, title, description) | ||
.then(activityId => res.status(201).send({ activityId })) | ||
.catch(error => next(error)) | ||
} catch (error) { | ||
next(error) | ||
} | ||
}) | ||
.catch(error => next(new CredentialsError(error.message))) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
staff/agustin-birman/project/api/handlers/createCompleteSentenceExerciseHandler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import jwt from '../util/jsonwebtoken-promised.js' | ||
|
||
import logic from '../logic/index.js' | ||
|
||
import { CredentialsError } from 'com/errors.js' | ||
|
||
const { JWT_SECRET } = process.env | ||
|
||
export default (req, res, next) => { | ||
try { | ||
const token = req.headers.authorization.slice(7) | ||
|
||
jwt.verify(token, JWT_SECRET) | ||
.then(payload => { | ||
const { sub: userId } = payload | ||
|
||
|
||
const { activityId, sentence } = req.body | ||
try { | ||
logic.createCompleteSentenceExercise(userId, activityId, sentence) | ||
.then(() => res.status(201).send()) | ||
.catch(error => next(error)) | ||
} catch (error) { | ||
next(error) | ||
} | ||
}) | ||
.catch(error => next(new CredentialsError(error.message))) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
staff/agustin-birman/project/api/handlers/createOrderSentenceHandler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import jwt from '../util/jsonwebtoken-promised.js' | ||
|
||
import logic from '../logic/index.js' | ||
|
||
import { CredentialsError } from 'com/errors.js' | ||
|
||
const { JWT_SECRET } = process.env | ||
|
||
export default (req, res, next) => { | ||
try { | ||
const token = req.headers.authorization.slice(7) | ||
|
||
jwt.verify(token, JWT_SECRET) | ||
.then(payload => { | ||
const { sub: userId } = payload | ||
|
||
|
||
const { activityId, sentence, translate } = req.body | ||
try { | ||
logic.createOrderSentence(userId, activityId, sentence, translate) | ||
.then(() => res.status(201).send()) | ||
.catch(error => next(error)) | ||
} catch (error) { | ||
next(error) | ||
} | ||
}) | ||
.catch(error => next(new CredentialsError(error.message))) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} |
Oops, something went wrong.