This repository has been archived by the owner on Dec 13, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from MattIPv4/feat/db
Removed Files
- Loading branch information
Showing
18 changed files
with
668 additions
and
441 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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
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
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,25 @@ | ||
module.exports = async (db, id) => { | ||
const allFeatures = await db.select().from('features'); | ||
const listFeatures = await db.select().from('feature_map').where({ list: id }); | ||
const map = listFeatures.reduce((obj, item) => { | ||
obj[item.feature] = item.value; | ||
return obj | ||
}, {}); | ||
return allFeatures.map(feature => { | ||
return { | ||
name: feature.name, | ||
id: feature.id, | ||
display: feature.display, | ||
type: feature.type, | ||
value: feature.id in map ? map[feature.id] : 0 | ||
} | ||
}).sort((a, b) => { | ||
if (a.value === b.value) { | ||
if (a.display === b.display) { | ||
return a.name > b.name ? 1 : -1; | ||
} | ||
return b.display - a.display | ||
} | ||
return b.value - a.value | ||
}); | ||
}; |
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
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,20 @@ | ||
// Credit: https://github.com/Daplie/knuth-shuffle/blob/master/index.js | ||
module.exports = array => { | ||
let currentIndex = array.length; | ||
let temporaryValue, randomIndex; | ||
|
||
// While there remain elements to shuffle... | ||
while (0 !== currentIndex) { | ||
|
||
// Pick a remaining element... | ||
randomIndex = Math.floor(Math.random() * currentIndex); | ||
currentIndex -= 1; | ||
|
||
// And swap it with the current element. | ||
temporaryValue = array[currentIndex]; | ||
array[currentIndex] = array[randomIndex]; | ||
array[randomIndex] = temporaryValue; | ||
} | ||
|
||
return array; | ||
}; |
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
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
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 |
---|---|---|
@@ -1,16 +1,14 @@ | ||
const config = require('../config'); | ||
const Website = require('./Website'); | ||
const Database = require('./Structure/Database'); | ||
const db = require('../db/db'); | ||
|
||
return new Promise(async () => { | ||
const db = new Database(config.database); | ||
try { | ||
await db.connect(); | ||
const knex = db(); | ||
console.log('[Database] Successfully connected to MySQL database.'); | ||
new Website({ | ||
db: db | ||
db: knex | ||
}).start(); | ||
} catch (e) { | ||
console.error('[Website] Failed to start Website.', e); | ||
} | ||
}) | ||
}); |
Oops, something went wrong.