Skip to content

Commit

Permalink
Merge pull request #243 from UoaWDCC/VPS-60/reset-button-fix
Browse files Browse the repository at this point in the history
VPS-60/Reset wasnt working
  • Loading branch information
codecreator127 authored Sep 23, 2024
2 parents 8c54b4a + 640afff commit 570d7f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 31 deletions.
35 changes: 5 additions & 30 deletions backend/src/routes/api/navigate/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,6 @@ const deleteAllNotes = async (groupData) => {
return true;
};

const deleteAllFlags = async (groupData) => {
const groupId = groupData._id;
const group = await Group.findById(groupId).lean();
if (!group) {
throw new HttpError("Group not found", STATUS.NOT_FOUND);
}

await Group.updateOne(
{ _id: groupId },
{ $set: { currentFlags: [] } }
).exec();
return true;
};

const deleteAllPaths = async (groupData) => {
const groupId = groupData._id;
const group = await Group.findById(groupId).lean();
if (!group) {
throw new HttpError("Group not found", STATUS.NOT_FOUND);
}

await Group.updateOne({ _id: groupId }, { $set: { path: [] } }).exec();
return true;
};

export const getScenarioFirstScene = async (scenarioId) => {
const scenario = await Scenario.findById(scenarioId, {
scenes: { $slice: 1 },
Expand Down Expand Up @@ -213,6 +188,7 @@ export const groupNavigate = async (req) => {

export const groupReset = async (req) => {
const { uid, currentScene } = req.body;

const group = await getGroupByIdAndUser(req.params.groupId, uid);
if (!group) {
throw new HttpError("Group not found", STATUS.NOT_FOUND);
Expand All @@ -233,11 +209,10 @@ export const groupReset = async (req) => {
const hasReset = scene.components.some((c) => c.type === "RESET_BUTTON");
if (!hasReset) throw new HttpError("Invalid reset", STATUS.FORBIDDEN);

if (!(await deleteAllFlags(group)))
throw new HttpError("Failed to delete flags", STATUS.INTERNAL_SERVER_ERROR);

if (!(await deleteAllPaths(group)))
throw new HttpError("Failed to delete paths", STATUS.INTERNAL_SERVER_ERROR);
await Group.updateOne(
{ _id: req.params.groupId },
{ $set: { path: [], currentFlags: [] } }
).exec();

return { status: STATUS.OK };
};
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/features/playScenario/PlayScenarioPageMulti.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ export default function PlayScenarioPageMulti({ group }) {

const reset = async () => {
try {
const res = await usePost(
await usePost(
`api/navigate/group/reset/${group._id}`,
{ currentScene: sceneId },
user.getIdToken.bind(user)
);

setAddFlags([]);
setRemoveFlags([]);
setPrevious(null);
history.replace(`/play/${scenarioId}/multiplayer`);
} catch (error) {
Expand Down

0 comments on commit 570d7f5

Please sign in to comment.