Skip to content

Commit

Permalink
add info at nomoney at fonction buyball
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin-Morette committed Jul 27, 2024
1 parent c6d67c0 commit 2a2eda6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions backend/src/controllers/PokeballController.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class PokeballController {
if (rowsTrainer[0].money < rowsBall[0].buyingPrice * quantity) {
res.send({
status: "noMoney",
money: rowsTrainer[0].money,
price: rowsBall[0].buyingPrice * quantity,
});
} else {
models.pokeball_trainer
Expand Down
21 changes: 18 additions & 3 deletions backend/src/controllers/PokemonController.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,29 @@ class PokemonController {

await models.pokemon_wild.updateById(idPokemonWild, 1, 0);

const [resultCatch] = await models.trainer.findHasFirstCatch(idTrainer);
const cacheKeyTrainer = `trainer_${idTrainer}`;

await models.trainer.updateFirstCatch(idTrainer);
let trainerResult = myCache.get(cacheKeyTrainer);

if (!trainerResult) {
const [resultCatch] = await models.trainer.findHasFirstCatch(
idTrainer
);
trainerResult = resultCatch;

if (trainerResult) {
myCache.set(cacheKeyTrainer, trainerResult);
}
}

if (trainerResult[0].hasFirstCatch === 0) {
await models.trainer.updateFirstCatch(idTrainer);
}

return res.status(201).send({
status: "catch",
pokemonName: pokemonResult[0][0].name,
sendTuto: resultCatch[0].hasFirstCatch === 0,
sendTuto: trainerResult[0].hasFirstCatch === 0,
});
}

Expand Down

0 comments on commit 2a2eda6

Please sign in to comment.