Skip to content

Commit

Permalink
Merge pull request #119 from Carifio24/delete-stage-state
Browse files Browse the repository at this point in the history
Allow deleting stage state
  • Loading branch information
Carifio24 authored Jul 8, 2024
2 parents fe30ad8 + 2cce247 commit e823076
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,16 @@ export async function updateStageState(studentID: number, storyName: string, sta
return result?.state ?? null;
}

export async function deleteStageState(studentID: number, storyName: string, stageName: string): Promise<number> {
return StageState.destroy({
where: {
student_id: studentID,
story_name: storyName,
stage_name: stageName,
}
});
}

export async function getClassesForEducator(educatorID: number): Promise<Class[]> {
return Class.findAll({
where: {
Expand Down
26 changes: 25 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
getDashboardGroupClasses,
getStageState,
updateStageState,
deleteStageState,
} from "./database";

import { getAPIKey, hasPermission } from "./authorization";
Expand All @@ -42,7 +43,7 @@ import {
VerificationResult,
} from "./request_results";

import { CosmicDSSession } from "./models";
import { CosmicDSSession, StageState } from "./models";

import { ParsedQs } from "qs";
import express, { Request, Response as ExpressResponse, NextFunction } from "express";
Expand Down Expand Up @@ -474,6 +475,29 @@ app.put("/stage-state/:studentID/:storyName/:stageName", async (req, res) => {
});
});

app.delete("/stage-state/:studentID/:storyName/:stageName", async (req, res) => {
const params = req.params;
const studentID = Number(params.studentID);
const storyName = params.storyName;
const stageName = params.stageName;
const state = await getStageState(studentID, storyName, stageName);
if (state != null) {
res.status(200);
const count = await deleteStageState(studentID, storyName, stageName);
const success = count > 0;
res.json({
success,
});
} else {
res.status(400);
const message = "No such (student, story, stage) combination found";
res.statusMessage = message;
res.json({
message,
});
}
});

app.get("/educator-classes/:educatorID", async (req, res) => {
const params = req.params;
const educatorID = Number(params.educatorID);
Expand Down

0 comments on commit e823076

Please sign in to comment.