Skip to content

Commit

Permalink
Merge pull request #4 from XadrezSuico/develop
Browse files Browse the repository at this point in the history
Versão Beta 0.0.1
  • Loading branch information
jppcel authored Nov 4, 2022
2 parents 23e583b + b675231 commit 01e77b2
Show file tree
Hide file tree
Showing 136 changed files with 9,625 additions and 434 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ testem.log
Thumbs.db

*.sqlite
result.txt
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"request": "attach",
"port": 9876,
"url": "http://localhost:4200",
"sourceMaps": true,
"sourceMaps": true,
"timeout": 10000,
"trace": "verbose",
"sourceMapPathOverrides": {
Expand All @@ -35,12 +35,12 @@
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
},
"preLaunchTask": "Build.Main"
}
},
],
"compounds": [
{
"name": "Application Debug",
"configurations": [ "Renderer", "Main" ]
}
]
}
}
Empty file added __temp_reports/.gitignore
Empty file.
Empty file added app/__temp_reports/.gitignore
Empty file.
Binary file added app/__temp_reports/report.pdf
Binary file not shown.
178 changes: 178 additions & 0 deletions app/controllers/category.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
const database = require('../db/db');
const Categories = require('../models/category.model');
const { ipcMain } = require('electron');

const { uuid } = require('uuidv4');

const dateHelper = require("../helpers/date.helper");

module.exports.setEvents = (ipcMain) => {
database.sync();

ipcMain.handle('controller.categories.listAll', listAll)
ipcMain.handle('controller.categories.listFromTournament', listFromTournament)
ipcMain.handle('controller.categories.create', create)
ipcMain.handle('controller.categories.get', get)
ipcMain.handle('controller.categories.update', update)
ipcMain.handle('controller.categories.remove', remove)

ipcMain.addListener("controller.categories.need_export", need_export);
}

module.exports.create = create;
module.exports.import = Import;
module.exports.listAll = listAll;
module.exports.listFromTournament = listFromTournament;
module.exports.get = get;
module.exports.update = update;
module.exports.remove = remove;

async function need_export(category_uuid){
let category_request = await get(null,category_uuid);
if (category_request.ok === 1) {
ipcMain.emit("controller.tournaments.need_export", category_request.category.tournament_uuid);
}
}

async function create(event, tournament_uuid, category, is_import = false){
try {
let resultadoCreate = await Categories.create({
name: category.name,
abbr: category.abbr,

tournamentUuid: tournament_uuid,
})
// console.log(resultadoCreate);

need_export(resultadoCreate.uuid);
return {ok:1,error:0,data:{uuid:resultadoCreate.uuid}};
} catch (error) {
console.log(error);
}
}

async function Import(event, tournament_uuid, category) {
try {
let resultadoCreate = await Categories.create({
uuid: (category.uuid) ? category.uuid : uuid(),
name: category.name,
abbr: category.abbr,

tournamentUuid: tournament_uuid,
})
// console.log(resultadoCreate);

return { ok: 1, error: 0, data: { uuid: resultadoCreate.uuid } };
} catch (error) {
console.log(error);
}
}

async function listAll() {
try {
let categories = await Categories.findAll();
let categories_return = [];
let i = 0;
for(let category of categories){
let category_return = {
uuid: category.uuid,
name: category.name,
abbr: category.abbr,

tournament_uuid: category.tournamentUuid,
};

categories_return[i++] = category_return;
}
return {ok:1,error:0,categories:categories_return};
} catch (error) {
console.log(error);
}
}

async function listFromTournament(event,tournament_uuid) {
try {
let categories = await Categories.findAll({
where: {
tournamentUuid: tournament_uuid
}
});
let categories_return = [];
let i = 0;
for(let category of categories){
let category_return = {
uuid: category.uuid,
name: category.name,
abbr: category.abbr,

tournament_uuid: category.tournamentUuid,
};

categories_return[i++] = category_return;
}
return {ok:1,error:0,categories:categories_return};
} catch (error) {
console.log(error);
}
}


async function get(e,uuid) {
try {
let category = await Categories.findByPk(uuid);

if (category) {
let category_return = {
uuid: category.uuid,
name: category.name,
abbr: category.abbr,

tournament_uuid: category.tournamentUuid,
};

return { ok: 1, error: 0, category: category_return };
}
return { ok: 0, error: 1, message: "Categoria não encontrada" }
} catch (error) {
console.log(error);
}
}

async function update(e,category){
try {
let resultado = await Categories.update({
name: category.name,
abbr: category.abbr,
},{
where:{
uuid:category.uuid
}
})
// console.log(resultado);
need_export(category.uuid);
return {ok:1,error:0};
} catch (error) {
console.log(error);
}

}
async function remove(e, uuid, is_delete_event = false) {
try {
let category = await Categories.findByPk(uuid);

if(category){
Categories.destroy({
where: {
uuid: uuid
}
});
if (!is_delete_event) ipcMain.emit("controller.tournaments.need_export", category.tournamentUuid);
return {ok:1,error:0};
}else{
return {ok:0,error:1,message:"Categoria não encontrada"};
}

} catch (error) {
console.log(error);
}
}
75 changes: 75 additions & 0 deletions app/controllers/event-delete.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const TournamentsController = require("./tournament.controller")
const CategoriesController = require("./category.controller")
const PlayersController = require("./player.controller")
const RoundsController = require("./round.controller")
const StandingsController = require("./standing.controller")
const PairingsController = require("./pairing.controller")

const Events = require('../models/event.model');

module.exports.remove = remove;

async function remove(uuid) {
try {
let event = await Events.findByPk(uuid);
let tournaments_request = await TournamentsController.listFromEvent(null,uuid);
if(tournaments_request.ok === 1){
for (let tournament of tournaments_request.tournaments){

let rounds_request = await RoundsController.listByTournament(null,tournament.uuid);
if(rounds_request.ok === 1){
for (let round of rounds_request.rounds) {

let standings_request = await StandingsController.listFromRound(null, tournament.uuid, round.uuid);
if (standings_request.ok === 1) {
for (let standing of standings_request.standings) {
console.log("standing-d-".concat(standing.uuid));
await StandingsController.remove(standing.uuid);
}
}

let pairings_request = await PairingsController.listByRound(null, round.uuid);
if(pairings_request.ok === 1){
for (let pairing of pairings_request.pairings) {
console.log("pairing-d-".concat(pairing.uuid));
await PairingsController.remove(pairing.uuid);
}
}
console.log("round-d-".concat(round.uuid));
await RoundsController.remove(round.uuid)
}
}

let players_request = await PlayersController.listByTournament(null,tournament.uuid);
if(players_request.ok === 1){
for (let player of players_request.players) {
console.log("player-d-".concat(player.uuid));
await PlayersController.remove(null,player.uuid,true);
}
}

let categories_request = await CategoriesController.listFromTournament(null,tournament.uuid);
if(categories_request.ok === 1){
for (let category of categories_request.categories) {
console.log("category-d-".concat(category.uuid));
await CategoriesController.remove(null,category.uuid,true);
}
}

console.log("tournament-d-".concat(tournament.uuid));
await TournamentsController.remove(null, tournament.uuid);
}
}
await Events.destroy({
where:{
uuid: uuid
}
});

return {ok:1,error:0};
}catch(error){
console.log(error);
}
return { ok: 0, error: 1, message: "Erro ainda desconhecido" };

}
Loading

0 comments on commit 01e77b2

Please sign in to comment.