-
-
Notifications
You must be signed in to change notification settings - Fork 1
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 XadrezSuico/develop
Versão Beta 0.0.1
- Loading branch information
Showing
136 changed files
with
9,625 additions
and
434 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,3 +52,4 @@ testem.log | |
Thumbs.db | ||
|
||
*.sqlite | ||
result.txt |
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
Empty file.
Empty file.
Binary file not shown.
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,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); | ||
} | ||
} |
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,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" }; | ||
|
||
} |
Oops, something went wrong.