From 652a3cf0a72e6ff6a4ac2af6594cbe29b0c90720 Mon Sep 17 00:00:00 2001 From: Sergei Bronnikov Date: Fri, 17 Jul 2026 09:55:16 +0100 Subject: [PATCH] delete course --- examples/course/deleteCourse.js | 8 ++++++++ package.json | 2 +- src/lib/course.ts | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 examples/course/deleteCourse.js diff --git a/examples/course/deleteCourse.js b/examples/course/deleteCourse.js new file mode 100644 index 0000000..4862c46 --- /dev/null +++ b/examples/course/deleteCourse.js @@ -0,0 +1,8 @@ +const { codio, auth } = require('../auth.js') + +async function main() { + await auth + await codio.course.createCourse({id: "your course id", removeOutdatedStudents: false}) +} + +main() diff --git a/package.json b/package.json index 896e640..5af7c89 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codio-api-js", - "version": "0.18.0", + "version": "0.19.0", "description": "JS client to Codio API", "repository": { "type": "git", diff --git a/src/lib/course.ts b/src/lib/course.ts index d77321e..4f36dc6 100644 --- a/src/lib/course.ts +++ b/src/lib/course.ts @@ -636,6 +636,26 @@ export async function createModule(courseId: string, moduleName: string): Promis } } +export type DeleteCourseRequest = { + id: string, + removeOutdatedStudents?: boolean +} + +export async function deleteCourse(data: DeleteCourseRequest): Promise { + const api = bent(getApiV1Url(), 'DELETE', 'json', 200) + try { + const paramString = data.removeOutdatedStudents ? `?removeOutdatedStudents=${data.removeOutdatedStudents}` : '' + await api(`/courses${paramString}`, data, getBearer()) + return + } catch (error: any) { + if (error.json) { + const message = JSON.stringify(await error.json()) + throw new Error(message) + } + throw error + } +} + export async function addTeacher(courseId: string, userId: string, readOnly = false): Promise { const api = bent(getApiV1Url(), 'POST', 'json', 200) try {