diff --git a/README.md b/README.md index b45a6ed..bc4ed1a 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ API keys. - zstd ## How to build -- Run `yarn` -- Run `yarn build` +- Run `npm install` +- Run `npm run build` ## Authentication @@ -525,6 +525,12 @@ Returns `Date` of archivation await codio.course.archive() ``` +#### Delete course + +``` +await codio.course.deleteCourse({id: , removeOutdatedStudents: }) +``` + #### Filter Learners For Mentors Specify mentors for LTI-base course diff --git a/examples/course/deleteCourse.js b/examples/course/deleteCourse.js new file mode 100644 index 0000000..e91748f --- /dev/null +++ b/examples/course/deleteCourse.js @@ -0,0 +1,13 @@ +const { codio, auth } = require('../auth.js') + +async function main() { + await auth + try { + await codio.course.deleteCourse({id: "your course id", removeOutdatedStudents: false}) + console.log("Course deleted successfully.") + } catch (error) { + console.error("Error deleting course:", error) + } +} + +main() diff --git a/package.json b/package.json index 896e640..51b0b1e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codio-api-js", - "version": "0.18.0", + "version": "0.19.1", "description": "JS client to Codio API", "repository": { "type": "git", diff --git a/src/lib/course.ts b/src/lib/course.ts index d77321e..b6a230b 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/${data.id}${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 { @@ -685,7 +705,8 @@ const course = { filterLearnersForMentors, createCourse, createModule, - addTeacher + addTeacher, + deleteCourse } export default course