Skip to content

Commit

Permalink
feature(training): added training stat update
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxencee committed Mar 14, 2024
1 parent 2392245 commit 4969280
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 6 additions & 0 deletions client/src/components/game/RunnerGame.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { motion } from "framer-motion";
import { useState, useEffect } from "react";
import { APIHandler } from "../../utils/api/api-handler";
import { useAuth } from "../../hooks/useAuth";

interface Click {
x: number;
y: number;
}

const RunnerGame = () => {
const { token } = useAuth();
const [clicks, setClicks] = useState<Click[]>([]);
const [isStarting, setIsStarting] = useState<boolean>(false);
const [gameOver, setGameOver] = useState<boolean>(false);
Expand Down Expand Up @@ -37,6 +40,9 @@ const RunnerGame = () => {
useEffect(() => {
setTimeout(() => {
setGameOver(true);
APIHandler<any>("/my/flami/training", false, "PATCH", {
worked_stat: "speed"
}, token)
}, 9000);
}, []);

Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/profile/AllBadgesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import TopBar from "../../components/topbar/TopBar";
import { APIHandler } from "../../utils/api/api-handler";
import { useAuth } from "../../hooks/useAuth";
import { Badge } from "../../interfaces/badge.interface";
import { ArrowLeftIcon, CloseIcon } from "react-line-awesome";
import { CloseIcon } from "react-line-awesome";
import BadgeDisplay from "../../components/profile/BadgeDisplay";

const AllBadgesPage = () => {
Expand Down
19 changes: 15 additions & 4 deletions server/controllers/flami.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ const flamiController = {
});
}

if(userdata.shared_flami?.shared_date && userdata.shared_flami.shared_date === new Date().toDateString()) {
if(user_flami.shared_date == new Date().toDateString()) {
return res.status(409).json({
message: `Votre Flami a déjà été échangé aujourd'hui.`,
error: 409
});
}

if(sharer_user.shared_flami?.shared_date && sharer_user.shared_flami.shared_date === new Date().toDateString()) {
if(shared_flami.shared_date == new Date().toDateString()) {
return res.status(409).json({
message: `Le Flami de ${sharer_user.name} a déjà été échangé aujourd'hui.`,
message: `Le ${shared_flami.name} a déjà été échangé aujourd'hui.`,
error: 409
});
}
Expand Down Expand Up @@ -136,8 +136,19 @@ const flamiController = {
competition: (req, res) => {

},
training: (req, res) => {
training: async (req, res) => {
let userdata = res.locals.user;
const { worked_stat } = req.body;

const f = await flamiModel.findOne({ _id: userdata.flami_id });
f["stats"][worked_stat]++;
f.save();

return res.status(202).json({
data: {
message: `Flami a gagner en ${worked_stat} !`
}
});
}
};

Expand Down

0 comments on commit 4969280

Please sign in to comment.