Skip to content

Iss05/work on design and functions #8

Merged
merged 5 commits into from Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,27 @@
module.exports = {
"env": {
"browser": true,
"es6": true
},
"extends": [
"plugin:react/recommended",
"airbnb"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018
},
"plugins": [
"react",
"@typescript-eslint"
],
"rules": {
}
};

This file was deleted.

@@ -0,0 +1,49 @@
const sqlite = require('sqlite-async')

const config = require('../config.json')

module.exports = class Answer {
//CONSTRUCTOR FOR THE DB
constructor(dbName = ':memory:'){
return (async() => {
this.db = await sqlite.open(dbName)

const sql = 'CREATE TABLE IF NOT EXISTS user_answer (\
id INTEGER PRIMARY KEY AUTOINCREMENT,\
answer TEXT\
);'
await this.db.run(sql)
return this
})()
}

//INSERT ANSWERS IN DB
async quiz(answers) {
try{
console.log('ADD answer')
const sql = `INSERT INTO user_answer(answer)\
VALUES("${answers.answer}")`
console.log(sql)
await this.db.run(sql)
} catch(err){
console.log(err.message)
throw err
}
}

//SELECT ALL ANSWERS IN DB
async all() {
try{
console.log('ALL answers')
const sql = 'SELECT id, answer FROM user_answer'
console.log(sql)
const answert = await this.db.all(sql)
console.log(answert)
return answert
} catch(err){
console.log(err.message)
throw err
}
}

}
@@ -0,0 +1,66 @@
const sqlite = require('sqlite-async')

const config = require('../config.json')

module.exports = class GitContent {
//CONSTRUCTOR FOR THE DB
constructor(dbName = ':memory:'){
return (async() => {
this.db = await sqlite.open(dbName)

const sql = 'CREATE TABLE IF NOT EXISTS git_content (\
id INTEGER PRIMARY KEY AUTOINCREMENT,\
title_of_content TEXT, block_of_content TEXT\
);'
//STILL need TO INSERT IMAGE HERE
await this.db.run(sql)
return this
})()
}

//INSERT content IN DATABASE
async content(title_of_content, block_of_content) //STILL NEED TO INSERT IMAGE HERE
{
try{
console.log('ADD content')
const sql = `INSERT INTO git_content(title_of_content, block_of_content)\
VALUES("${title_of_content.title_of_content}","${title_of_content.block_of_content}")`
console.log(sql)
await this.db.run(sql)
} catch(err){
console.log(err.message)
throw err
}
}

//SELECT ALL GIT CONTENT
async all() {
try{
console.log('ALL answers')
const sql = 'SELECT id, title_of_content, block_of_content FROM git_content'
console.log(sql)
const gitselected = await this.db.all(sql)
console.log(gitselected)
return gitselected
} catch(err){
console.log(err.message)
throw err
}
}

//GETS THE ID
async getById(id){
try{
console.log('BY ID')
console.log(id)
const sql =`SELECT * FROM git_content WHERE id=${id}`
console.log(sql)
const contentdb = await this.db.get(sql)
return contentdb
} catch(err) {
console.log(err.message)
throw err
}
}

}
@@ -0,0 +1,78 @@
const sqlite = require('sqlite-async')

const config = require('../config.json')

module.exports = class Question {
//CONTRUCTOR FOR THE DB
constructor(dbName = ':memory:'){
return (async() => {
this.db = await sqlite.open(dbName)
//CHECK IF TABLE EXISTS ELSE CREATE
const sql = 'CREATE TABLE IF NOT EXISTS available_questions (\
id INTEGER PRIMARY KEY AUTOINCREMENT,\
question TEXT, possible_answer1 TEXT, possible_answer2 TEXT, possible_answer3 TEXT, correct_answer TEXT, user_answer TEXT\
);'
await this.db.run(sql)
return this
})()
}

//INSERT QUESTIONS IN DB - BACKOFFICE
async questionz(questions) {
try{
console.log('Question Added')
const sql = `INSERT INTO available_questions(question, possible_answer1, possible_answer2, possible_answer3, correct_answer)\
VALUES("${questions.question}","${questions.possible_answer1}","${questions.possible_answer2}","${questions.possible_answer3}","${questions.correct_answer}")`
console.log(sql)
await this.db.run(sql)
} catch(err) {
console.log(err.message)
throw err
}

}

//INSERT USER ANSWER IN DB - QUIZ
async getanswer(user_answer){
try{
console.log(user_answer)
const sql = `INSERT INTO available_questions(user_answer)\
VALUES("${user_answer.user_answer}")`
console.log(sql)
await this.db.run(sql)
} catch(err) {
console.log(err.message)
throw err
}
}

//SELECT MOST QUESTIONS IN DB
async all(){
try {
console.log('ALL questions')
const sql = 'SELECT * FROM available_questions'
console.log(sql)
const questiont = await this.db.all(sql)
console.log(questiont)
return questiont
} catch(err) {
console.log(err.message)
throw err
}
}

//GETS THE ID
async getById(id){
try{
console.log('BY ID')
console.log(id)
const sql =`SELECT * FROM available_questions WHERE id=${id}`
console.log(sql)
const question = await this.db.get(sql)
return question
} catch(err) {
console.log(err.message)
throw err
}
}
}