Skip to content

Commit

Permalink
remvoe all useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin-Morette committed May 22, 2024
1 parent d928318 commit f54566e
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 829 deletions.
102 changes: 102 additions & 0 deletions backend/src/controllers/ExempleController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
const models = require("../models");

class PokeballController {
static browse = (req, res) => {
models.pokeball
.findAll()
.then(([rows]) => {
res.send(rows);
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};

static read = (req, res) => {
models.pokeball
.find(req.params.id)
.then(([rows]) => {
if (rows[0] == null) {
res.sendStatus(404);
} else {
res.send(rows[0]);
}
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};

static readByTrainer = (req, res) => {
models.pokeball
.findByTrainer(req.params.id)
.then(([rows]) => {
res.send(rows);
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};

static buy = (req, res) => {
const { idBall } = req.body;
const { idDiscord } = req.body;
const { quantity } = req.body;
models.pokeball
.find(idBall)
.then(([rowsBall]) => {
if (rowsBall[0] == null) {
res.send({
status: "noExistBall",
});
} else {
models.trainer
.find(idDiscord)
.then(([rowsTrainer]) => {
if (rowsTrainer[0].money < rowsBall[0].buyingPrice * quantity) {
res.send({
status: "noMoney",
});
} else {
models.pokeball_trainer
.insertMany(idBall, idDiscord, quantity)
.then(() => {
models.trainer
.updateMoney(
idDiscord,
-rowsBall[0].buyingPrice * quantity
)
.then(() => {
res.send({
status: "buy",
price: rowsBall[0].buyingPrice * quantity,
});
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
}
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
}
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};
}

module.exports = PokeballController;
46 changes: 0 additions & 46 deletions backend/src/controllers/PokeballController.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,6 @@ class PokeballController {
});
};

static edit = (req, res) => {
const pokeball = req.body;

pokeball.id = parseInt(req.params.id, 10);

models.pokeball
.update(pokeball)
.then(([result]) => {
if (result.affectedRows === 0) {
res.sendStatus(404);
} else {
res.sendStatus(204);
}
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};

static add = (req, res) => {
const pokeball = req.body;

models.pokeball
.insert(pokeball)
.then(([result]) => {
res.status(201).send({ ...pokeball, id: result.insertId });
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};

static buy = (req, res) => {
const { idBall } = req.body;
const { idDiscord } = req.body;
Expand Down Expand Up @@ -131,18 +97,6 @@ class PokeballController {
res.sendStatus(500);
});
};

static delete = (req, res) => {
models.pokeball
.delete(req.params.id)
.then(() => {
res.sendStatus(204);
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};
}

module.exports = PokeballController;
80 changes: 1 addition & 79 deletions backend/src/controllers/PokeballTrainerController.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,3 @@
const models = require("../models");

class PokeballTrainerController {
static browse = (req, res) => {
models.pokeballTrainer
.findAll()
.then(([rows]) => {
res.send(rows);
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};

static read = (req, res) => {
models.pokeballTrainer
.find(req.params.id)
.then(([rows]) => {
if (rows[0] == null) {
res.sendStatus(404);
} else {
res.send(rows[0]);
}
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};

static edit = (req, res) => {
const pokeballTrainer = req.body;

pokeballTrainer.id = parseInt(req.params.id, 10);

models.pokeballTrainer
.update(pokeballTrainer)
.then(([result]) => {
if (result.affectedRows === 0) {
res.sendStatus(404);
} else {
res.sendStatus(204);
}
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};

static add = (req, res) => {
const pokeballTrainer = req.body;

// TODO validations (length, format...)

models.pokeballTrainer
.insert(pokeballTrainer)
.then(([result]) => {
res.status(201).send({ ...pokeballTrainer, id: result.insertId });
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};

static delete = (req, res) => {
models.pokeballTrainer
.delete(req.params.id)
.then(() => {
res.sendStatus(204);
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};
}
class PokeballTrainerController {}

module.exports = PokeballTrainerController;
60 changes: 0 additions & 60 deletions backend/src/controllers/PokemonController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,6 @@
const models = require("../models");

class PokemonController {
static browse = (req, res) => {
models.pokemon
.findAll()
.then(([rows]) => {
res.send(rows);
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};

static read = (req, res) => {
models.pokemon
.find(req.params.id)
.then(([rows]) => {
if (rows[0] == null) {
res.sendStatus(404);
} else {
res.send(rows[0]);
}
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};

static readByTrainer = (req, res) => {
const isShiny = req.params.type === "shiny" ? 1 : 0;
let countPokemon = 0;
Expand All @@ -51,26 +23,6 @@ class PokemonController {
});
};

static edit = (req, res) => {
const pokemon = req.body;

pokemon.id = parseInt(req.params.id, 10);

models.pokemon
.update(pokemon)
.then(([result]) => {
if (result.affectedRows === 0) {
res.sendStatus(404);
} else {
res.sendStatus(204);
}
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};

static add = (req, res) => {
const pokemon = req.body;
models.pokemon
Expand Down Expand Up @@ -425,18 +377,6 @@ class PokemonController {
});
});
};

static delete = (req, res) => {
models.pokemon
.delete(req.params.id)
.then(() => {
res.sendStatus(204);
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};
}

module.exports = PokemonController;
Loading

0 comments on commit f54566e

Please sign in to comment.