Skip to content

Commit

Permalink
change for tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin-Morette committed May 21, 2024
1 parent b348e2c commit d928318
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 232 deletions.
6 changes: 2 additions & 4 deletions backend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ const router = require("./router");

const app = express();

// Middleware pour vérifier la clé API
const apiKeyMiddleware = (req, res, next) => {
const apiKey = req.get("X-API-KEY"); // Obtient la clé API de l'en-tête de la requête
const apiKey = req.get("X-API-KEY");
if (apiKey && apiKey === process.env.API_KEY) {
next(); // Si la clé API est correcte, continue vers le prochain middleware
next();
} else {
res
.status(401)
.json({ error: "Accès non autorisé. Clé API invalide ou manquante." });
}
};

// use some application-level middlewares
app.use(
cors({
origin: process.env.FRONTEND_URL ?? "http://localhost:3000",
Expand Down
15 changes: 10 additions & 5 deletions backend/src/controllers/PokemonController.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ class PokemonController {
if (catchChance < 0) {
catchChance = 1;
}

const randomCatch = Math.floor(Math.random() * 100);
if (randomCatch <= catchChance) {
models.pokemon_trainer.insert({
Expand All @@ -341,10 +340,16 @@ class PokemonController {
models.pokemon_wild
.updateById(idPokemonWild, 1, 0)
.then(() => {
res.status(201).send({
status: "catch",
pokemonName: pokemonResult[0][0].name,
});
models.trainer
.findHasFirstCatch(idTrainer)
.then(([resultCatch]) => {
models.trainer.updateFirstCatch(idTrainer);
res.status(201).send({
status: "catch",
pokemonName: pokemonResult[0][0].name,
sendTuto: resultCatch[0].hasFirstCatch === 0,
});
});
})
.catch((err) => {
console.error(err);
Expand Down
33 changes: 0 additions & 33 deletions backend/src/controllers/TrainerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,8 @@ class TrainerController {
});
};

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

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

models.trainer
.update(trainer)
.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 payload = req.body;

models.trainer
.insert(payload.trainer)
.then(([result]) => {
Expand All @@ -70,18 +49,6 @@ class TrainerController {
});
};

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

static verifyIdDiscord = (req, res) => {
models.trainer
.verifyIdDiscord(req.params.idDiscord)
Expand Down
93 changes: 93 additions & 0 deletions backend/src/controllers/TutorialCommandTrainerController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
const models = require("../models");

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

static read = (req, res) => {
models.tutorial_command_trainer
.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.tutorial_command_trainer
.findByTrainer(req.params.id)
.then(([rows]) => {
res.send(rows);
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};

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

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

models.tutorial_command_trainer
.update(tutorialCommandTrainer)
.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 tutorialCommandTrainer = req.body;

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

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

module.exports = TutorialCommandTrainerController;
173 changes: 4 additions & 169 deletions backend/src/database/pokemon_zone.sql
Original file line number Diff line number Diff line change
@@ -1,169 +1,4 @@
-- Route 1
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('19', '2'); -- Rattata
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('16', '2'); -- Roucool

-- Route 2
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('19', '4'); -- Rattata
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('16', '4'); -- Roucool

-- Forêt de Jade
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('13', '5'); -- Aspicot
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('10', '5'); -- Chenipan
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('11', '5'); -- Chrysacier (Uniquement dans Pokémon Bleu)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('14', '5'); -- Coconfort (Uniquement dans Pokémon Rouge)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('21', '5'); -- Piafabec (Uniquement dans Pokémon Rouge)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('16', '5'); -- Roucool
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('12', '5'); -- Papilusion (Très rare dans Pokémon Bleu)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('15', '5'); -- Dardagnan (Très rare dans Pokémon Rouge)

-- Route 22
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('19', '6'); -- Rattata
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('21', '6'); -- Piafabec
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('27', '6'); -- Sabelette (Uniquement dans Pokémon Bleu)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('56', '6'); -- Férosinge (Uniquement dans Pokémon Rouge)

-- Plateau Indigo
-- Pas de Pokémon sauvages spécifiques à capturer ici (ce sont des combats contre d'autres dresseurs).

-- Route 3
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('19', '8'); -- Rattata
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('21', '8'); -- Piafabec
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('23', '8'); -- Abo
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('29', '8'); -- Nidoran♀
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('32', '8'); -- Nidoran♂

-- Mont Sélénite
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('41', '9'); -- Nosferapti
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('74', '9'); -- Racaillou

-- Azuria
-- Pas de Pokémon sauvages spécifiques à capturer ici.

-- Route 4
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('19', '11'); -- Rattata
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('23', '11'); -- Abo

-- Parmanie
-- Pas de Pokémon sauvages spécifiques à capturer ici.

-- Route 5
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('16', '13'); -- Roucool
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('19', '13'); -- Rattata
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('39', '13'); -- Mélofée (Très rare)

-- Lavanville
-- Pas de Pokémon sauvages spécifiques à capturer ici.

-- Route 8
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('16', '15'); -- Roucool
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('19', '15'); -- Rattata
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('37', '15'); -- Goupix (Uniquement dans Pokémon Bleu)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('58', '15'); -- Caninos (Uniquement dans Pokémon Rouge)

-- Route 10
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('21', '16'); -- Piafabec
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('81', '16'); -- Magnéti
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('100', '16'); -- Voltorbe

-- Route 9
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('19', '17'); -- Rattata
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('21', '17'); -- Piafabec
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('23', '17'); -- Abo
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('27', '17'); -- Sabelette (Uniquement dans Pokémon Bleu)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('56', '17'); -- Férosinge (Uniquement dans Pokémon Rouge)

-- Route 6
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('16', '18'); -- Roucool
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('19', '18'); -- Rattata
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('43', '18'); -- Mystherbe

-- Route 11
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('19', '19'); -- Rattata
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('23', '19'); -- Abo
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('27', '19'); -- Sabelette (Uniquement dans Pokémon Bleu)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('56', '19'); -- Férosinge (Uniquement dans Pokémon Rouge)

-- Caverne Azurée
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('41', '20'); -- Nosferapti
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('42', '20'); -- Nosferalto
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('74', '20'); -- Racaillou
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('75', '20'); -- Gravalanch

-- Route 7
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('37', '21'); -- Goupix (Uniquement dans Pokémon Bleu)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('58', '21'); -- Caninos (Uniquement dans Pokémon Rouge)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('43', '21'); -- Mystherbe

-- Route 16
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('16', '22'); -- Roucool
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('19', '22'); -- Rattata
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('84', '22'); -- Doduo

-- Route 17 (Piste Cyclable)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('16', '23'); -- Roucool
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('19', '23'); -- Rattata
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('84', '23'); -- Doduo

-- Route 18
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('16', '24'); -- Roucool
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('19', '24'); -- Rattata
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('84', '24'); -- Doduo

-- Safrania
-- Pas de Pokémon sauvages spécifiques à capturer ici.

-- Parc Safari
-- Il y a de nombreux Pokémon dans le Parc Safari, et cela dépend de la zone spécifique à l'intérieur du parc. Si vous voulez une liste complète pour le Parc Safari, faites-le moi savoir.

-- Cramois'île
-- Pas de Pokémon sauvages spécifiques à capturer ici.

-- Route 21
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('16', '28'); -- Roucool
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('19', '28'); -- Rattata
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('72', '28'); -- Tentacool
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('73', '28'); -- Tentacruel

-- Route 20 (Surfing)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('72', '29'); -- Tentacool
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('73', '29'); -- Tentacruel

-- Îles Écume
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('54', '30'); -- Psykokwak
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('55', '30'); -- Akwakwak
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('72', '30'); -- Tentacool
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('73', '30'); -- Tentacruel
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('79', '30'); -- Ramoloss
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('80', '30'); -- Flagadoss
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('86', '30'); -- Otaria
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('87', '30'); -- Lamantine
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('90', '30'); -- Kokiyas
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('91', '30'); -- Crustabri
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('98', '30'); -- Krabby
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('99', '30'); -- Krabboss
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('120', '30'); -- Stari
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('121', '30'); -- Staross

-- Route 19 (Surfing)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('72', '31'); -- Tentacool
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('73', '31'); -- Tentacruel

-- Manoir Pokémon (Cramois'Île)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('37', '32'); -- Goupix (Uniquement dans Pokémon Bleu)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('58', '32'); -- Caninos (Uniquement dans Pokémon Rouge)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('109', '32'); -- Smogo
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('110', '32'); -- Smogogo

-- Centrale Pokémon (Power Plant)
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('81', '33'); -- Magnéti
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('82', '33'); -- Magnéton
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('100', '33'); -- Voltorbe
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('101', '33'); -- Électrode
INSERT INTO pokemon_zone (idPokemon, idZone) VALUES ('125', '33'); -- Élektek

-- Grotte Inconnue (Cave de Cerulean)
-- Ici, vous pourrez trouver le Pokémon légendaire Mewtwo, mais c'est après avoir battu la Ligue Pokémon.




ALTER TABLE tutorial_command_trainer ADD UNIQUE KEY unique_trainer_command (idTrainer, commandName);
ALTER TABLE trainer DROP COLUMN point;
ALTER TABLE trainer DROP COLUMN level;
ALTER TABLE `trainer` ADD `hasFirstCatch` TINYINT NOT NULL AFTER `money`;
Loading

0 comments on commit d928318

Please sign in to comment.