|
|
|
@ -16,14 +16,62 @@ function disconnect(){
|
|
|
|
con.end();
|
|
|
|
con.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getCards(additionalData){
|
|
|
|
// Is calling a promise in a promise the best way to do this?
|
|
|
|
|
|
|
|
// Keeping because this is how I've figured to call other funcs from database
|
|
|
|
|
|
|
|
function getCardById(cardId){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const dPromise = new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getCards(' card.id = '+cardId).then(cards => {
|
|
|
|
|
|
|
|
resolve(cards);
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch(err => {
|
|
|
|
|
|
|
|
throw err; reject(new Error(err));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return dPromise;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getCards(whereClause){
|
|
|
|
const cPromise = new Promise((resolve, reject) => {
|
|
|
|
const cPromise = new Promise((resolve, reject) => {
|
|
|
|
let sql = 'SELECT * FROM card';
|
|
|
|
let cards = [];
|
|
|
|
if(additionalData){ sql = sql + " WHERE "+additionalData; }
|
|
|
|
let sql = `SELECT
|
|
|
|
|
|
|
|
card.id AS cardId -- TEMP UNTIL UID
|
|
|
|
|
|
|
|
,cardName
|
|
|
|
|
|
|
|
,cardCost
|
|
|
|
|
|
|
|
,typeName
|
|
|
|
|
|
|
|
,cardAttack
|
|
|
|
|
|
|
|
,rarityName
|
|
|
|
|
|
|
|
FROM card
|
|
|
|
|
|
|
|
LEFT JOIN type ON type.id = card.id
|
|
|
|
|
|
|
|
LEFT JOIN rarity ON rarity.id = card.cardRarity
|
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
// TODO: Rewrite this so it's not so insecure!!!!
|
|
|
|
|
|
|
|
if(whereClause){ sql = sql + " WHERE "+whereClause; }
|
|
|
|
|
|
|
|
|
|
|
|
con.query(sql, function (err, result, fields) {
|
|
|
|
con.query(sql, function (err, result, fields) {
|
|
|
|
if (err) { throw err; reject(new Error(err)); }
|
|
|
|
if (err) { throw err; reject(new Error(err)); }
|
|
|
|
resolve(result);
|
|
|
|
result.forEach((card) => {
|
|
|
|
|
|
|
|
let tempCard = {};
|
|
|
|
|
|
|
|
tempCard.id = card.cardId;
|
|
|
|
|
|
|
|
tempCard.name = card.cardName;
|
|
|
|
|
|
|
|
tempCard.colour = 'temp';
|
|
|
|
|
|
|
|
tempCard.cost = card.cardCost;
|
|
|
|
|
|
|
|
tempCard.type = card.typeName;
|
|
|
|
|
|
|
|
tempCard.atk = card.cardAttack;
|
|
|
|
|
|
|
|
tempCard.rarity = card.rarityName;
|
|
|
|
|
|
|
|
tempCard.effect = 'temp effect';
|
|
|
|
|
|
|
|
// TODO: Will need more SQL statements, or some function/procedure
|
|
|
|
|
|
|
|
// class
|
|
|
|
|
|
|
|
// colour requirements
|
|
|
|
|
|
|
|
// card effects
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cards.push(tempCard);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//console.log(cards);
|
|
|
|
|
|
|
|
resolve(cards);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return cPromise;
|
|
|
|
return cPromise;
|
|
|
|
@ -32,4 +80,5 @@ function getCards(additionalData){
|
|
|
|
module.exports = {
|
|
|
|
module.exports = {
|
|
|
|
connect, disconnect
|
|
|
|
connect, disconnect
|
|
|
|
, getCards
|
|
|
|
, getCards
|
|
|
|
|
|
|
|
, getCardById
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|