Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
feat: sextus leaderboard improvement (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianRid authored Oct 24, 2022
1 parent df11001 commit 0d3a150
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
38 changes: 36 additions & 2 deletions back-strapi/api/sextus-history/controllers/sextus-history.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,42 @@
'use strict';
"use strict";
const { parseMultipartData, sanitizeEntity } = require("strapi-utils");

/**
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-controllers)
* to customize this controller
*/

module.exports = {};
module.exports = {
async update(ctx) {
const { id } = ctx.params;

let entity;
if (ctx.is("multipart")) {
const { data, files } = parseMultipartData(ctx);
entity = await strapi.services["sextus-history"].update({ id }, data, {
files,
});
} else {
entity = await strapi.services["sextus-history"].update(
{ id },
ctx.request.body
);
}

const successSextusHistoryCount = await strapi.services[
"sextus-history"
].count({
utilisateurs_mobile: entity.utilisateurs_mobile.id,
status: "success",
});

await strapi.services["utilisateurs-mobile"].update(
{ id: entity.utilisateurs_mobile.id },
{
points: successSextusHistoryCount,
}
);

return sanitizeEntity(entity, { model: strapi.models["sextus-history"] });
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -277,21 +277,6 @@ module.exports = {
}

user.credits = credits - orders_count;

const successSextusHistoryCount = await strapi.services[
"sextus-history"
].count({
utilisateurs_mobile: user.id,
status: "success",
});

await strapi.services["utilisateurs-mobile"].update(
{ id: user.id },
{
points: successSextusHistoryCount,
}
);

return user;
},
async getLeaderBoard() {
Expand Down
4 changes: 3 additions & 1 deletion tumeplayMobile/src/views/Sextus.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import config from '../../config';
import LeaderBoard from '../components/Sextus/LeaderBoard';

const Sextus = ({navigation}) => {
const {user} = useContext(AppContext);
const {user, reloadUser} = useContext(AppContext);

const [fullWords, setFullWords] = useState([]);
const [inputWord, setInputWord] = useState('');
Expand Down Expand Up @@ -84,6 +84,7 @@ const Sextus = ({navigation}) => {
nb_try: currentRow + 1,
duration: duration,
status: 'success',
utilisateurs_mobile: user.id,
},
});
};
Expand All @@ -100,6 +101,7 @@ const Sextus = ({navigation}) => {
setCurrentLetterIndex(0);
setInputWord('');
handleWordAndDefinition();
reloadUser();
setIsAllowedToPlay(true);
}, [wordToGuess]);

Expand Down

0 comments on commit 0d3a150

Please sign in to comment.