105 lines
5.0 KiB
JavaScript
105 lines
5.0 KiB
JavaScript
require('../connector');
|
|
const express = require('express');
|
|
const router = express.Router();
|
|
|
|
var routes = function () {
|
|
|
|
router.get('/getAllSorteios', function (req, res) {
|
|
ExecuteQuery(`SELECT idbingosorteios, descricao, rodada, date_format(data_sorteio, '%d/%m/%Y') as data_sorteio, n_max, participantes_max FROM bingosorteios;`, req, res);
|
|
});
|
|
|
|
router.get('/getSorteiosRealizar', function (req, res) {
|
|
ExecuteQuery(`SELECT * FROM bingosorteios where realizado = 0;`, req, res);
|
|
});
|
|
|
|
router.get('/getAllCartelas', function (req, res) {
|
|
ExecuteQuery(`SELECT * FROM bingocartelas;`, req, res);
|
|
});
|
|
|
|
router.get('/getCartelasSorteio/:idbingosorteios', function (req, res) {
|
|
const idbingosorteios = parseInt(req.params.idbingosorteios);
|
|
ExecuteQuery(`SELECT * FROM bingocartelas where idbingosorteios = ? order by canhoto asc;`, req, res, [idbingosorteios]);
|
|
});
|
|
|
|
router.get('/getCartelasVendidasSorteio/:idbingosorteios', function (req, res) {
|
|
const idbingosorteios = parseInt(req.params.idbingosorteios);
|
|
ExecuteQuery(`SELECT *, 1 as 'Acertos' FROM bingocartelas where idbingosorteios = ? and nome is not null order by canhoto asc;`, req, res, [idbingosorteios]);
|
|
});
|
|
|
|
router.post('/insertBingoSorteio', function (req, res) {
|
|
const descricao = req.body.descricao;
|
|
const rodada = parseInt(req.body.rodada);
|
|
const data_sorteio = req.body.data_sorteio;
|
|
const n_max = parseInt(req.body.n_max);
|
|
const participantes_max = parseInt(req.body.participantes_max);
|
|
ExecuteQuery(`insert into bingosorteios (descricao, rodada, data_sorteio, n_max, participantes_max) values (?, ?, ?, ?, ?);`, req, res, [descricao, rodada, data_sorteio, n_max, participantes_max]);
|
|
});
|
|
|
|
router.post('/updateBingoSorteio', function (req, res) {
|
|
const idbingosorteios = parseInt(req.body.idbingosorteios);
|
|
const descricao = req.body.descricao;
|
|
const rodada = parseInt(req.body.rodada);
|
|
const data_sorteio = req.body.data_sorteio;
|
|
const n_max = parseInt(req.body.n_max);
|
|
const participantes_max = parseInt(req.body.participantes_max);
|
|
const realizado = req.body.realizado ? 1 : 0;
|
|
ExecuteQuery(`update bingosorteios set descricao = ?, rodada = ?, data_sorteio = ?, n_max = ?, participantes_max = ?, realizado = ? where idbingosorteios = ?;`, req, res, [descricao, rodada, data_sorteio, n_max, participantes_max, realizado, idbingosorteios]);
|
|
});
|
|
|
|
router.delete('/deleteBingoSorteio/:idbingosorteios', function (req, res) {
|
|
const idbingosorteios = parseInt(req.params.idbingosorteios);
|
|
ExecuteQuery(`delete FROM bingosorteios where idbingosorteios = ${idbingosorteios};`, req, res);
|
|
});
|
|
|
|
router.post('/insertBingoCartela', function (req, res) {
|
|
const idbingosorteios = parseInt(req.body.idbingosorteios);
|
|
const Cartelas = req.body.Cartelas;
|
|
let SQLCartelas = `insert into bingocartelas (canhoto, idbingosorteios, numeros) values `;
|
|
for (let i = 0; i < Cartelas.length; i++) {
|
|
Cartelas[i]['numeros'] = Cartelas[i]['numeros'].toString().replace('passaros.png', 'LIVRE');
|
|
SQLCartelas += `(${Cartelas[i]['canhoto']},${idbingosorteios},'${Cartelas[i]['numeros']}'),`
|
|
}
|
|
SQLCartelas = SQLCartelas.substring(0, SQLCartelas.length - 1);
|
|
//console.log(SQLCartelas);
|
|
ExecuteQuery(SQLCartelas, req, res);
|
|
});
|
|
|
|
router.patch('/updateBingoCartela', function (req, res) {
|
|
const canhoto = req.body.canhoto;
|
|
const nome = req.body.nome;
|
|
const endereco = req.body.endereco;
|
|
const telefone = req.body.telefone;
|
|
const bingo = req.body.bingo ? 1 : 0;
|
|
const cinquina1 = req.body.cinquina1 ? 1 : 0;
|
|
const cinquina2 = req.body.cinquina2 ? 1 : 0;
|
|
const cinquina3 = req.body.cinquina3 ? 1 : 0;
|
|
ExecuteQuery(`update bingocartelas set nome = ?, endereco = ?, telefone = ?, bingo = ?, cinquina1 = ?, cinquina2 = ?, cinquina3 = ? where canhoto = ?;`, req, res, [nome, endereco, telefone, bingo, cinquina1, cinquina2, cinquina3, canhoto]);
|
|
});
|
|
|
|
|
|
router.post('/exportarExcel', function (req, res) {
|
|
const Cartelas = req.body.Cartelas;
|
|
const idbingosorteios = req.body.idbingosorteios;
|
|
let Texto2 = `Canhoto;Numeros;Nome;Endereco;Telefone;\r\n`;
|
|
for (let i = 0; i < Cartelas.length; i++) {
|
|
Texto2 += `${Cartelas[i]['canhoto']};${Cartelas[i]['numeros']};${Cartelas[i]['nome']};${Cartelas[i]['telefone']};\r\n`;
|
|
}
|
|
const fs = require('fs');
|
|
fs.writeFile('/var/www/html/Jogos/Bingo/Gerador/Cartelas/' + idbingosorteios + '.csv', Texto2, 'utf8', function (err) {
|
|
let Sucesso = false;
|
|
if (err) {
|
|
console.log("Erro ao salvar cartelas");
|
|
}
|
|
else {
|
|
console.log("Cartelas salvas com sucesso");
|
|
Sucesso = true;
|
|
}
|
|
res.send(Sucesso);
|
|
});
|
|
});
|
|
|
|
|
|
return router;
|
|
}
|
|
|
|
module.exports = routes; |