Skip to content

Commit

Permalink
fixed missing .gitignore #182
Browse files Browse the repository at this point in the history
  • Loading branch information
AgusBirman committed Aug 26, 2024
1 parent 79cdfde commit 270c646
Show file tree
Hide file tree
Showing 262 changed files with 17,729 additions and 0 deletions.
1 change: 1 addition & 0 deletions staff/agustin-birman/project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
4 changes: 4 additions & 0 deletions staff/agustin-birman/project/api/.env
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
4 changes: 4 additions & 0 deletions staff/agustin-birman/project/api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.node_modules
.coverage
coverage
node_modules
23 changes: 23 additions & 0 deletions staff/agustin-birman/project/api/data/Activity.js
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
28 changes: 28 additions & 0 deletions staff/agustin-birman/project/api/data/Answer.js
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

69 changes: 69 additions & 0 deletions staff/agustin-birman/project/api/data/Exercise.js
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
39 changes: 39 additions & 0 deletions staff/agustin-birman/project/api/data/User.js
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
11 changes: 11 additions & 0 deletions staff/agustin-birman/project/api/data/index.js
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 staff/agustin-birman/project/api/handlers/addStudentHandler.js
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)
}
}
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)
}
}
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 staff/agustin-birman/project/api/handlers/createActivityHandler.js
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)
}
}
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)
}
}
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)
}
}
Loading

0 comments on commit 270c646

Please sign in to comment.