Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/assignment/createAssignment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { codio, auth } = require('../auth.js')
const { courseId, assignmentData } = require('../data.js')

async function main() {
await auth

const result = await codio.assignment.createAssignment(courseId, assignmentData)
console.log(result)
}

main()
11 changes: 11 additions & 0 deletions examples/course/createCourse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { codio, auth } = require('../auth.js')
const { courseData } = require('../data.js')

async function main() {
await auth

const result = await codio.course.createCourse(courseData)
console.log(result)
}

main()
11 changes: 11 additions & 0 deletions examples/course/createModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { codio, auth } = require('../auth.js')
const { courseId, moduleName } = require('../data.js')

async function main() {
await auth

const result = await codio.course.createModule(courseId, moduleName)
console.log(result)
}

main()
24 changes: 23 additions & 1 deletion examples/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,27 @@ const leanersMapping = [
]
}
]
const moduleName = "New Module Name"
const courseData = {
name: "Introduction to Programming",
description: "This course covers the basics of programming.",
start: "2025-08-29T09:32:55Z",
end: "2027-09-25T09:12:00Z",
timezone: "America/New_York",
tags: [
"programming",
"beginner"
]
}
const assignmentData = {
moduleId: "your module id",
settings: {
name: "My First Assignment",
description: "This assignment covers the basics of programming.",
gigaboxSlot: {
boxType: "1gb"
}
}
}

module.exports = { courseId, courseName, assignmentId, studentId, studentEmail, studentLogin, libraryId, libraryName, projectPath, stackId, stackVersionId, archivePath, yamlMapDir, courseIdToArchive, leanersMapping }
module.exports = { courseId, courseName, assignmentId, studentId, studentEmail, studentLogin, libraryId, libraryName, projectPath, stackId, stackVersionId, archivePath, yamlMapDir, courseIdToArchive, leanersMapping, moduleName, courseData, assignmentData }
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codio-api-js",
"version": "0.15.3",
"version": "0.16.0",
"description": "JS client to Codio API",
"repository": "https://github.com/codio/codio-api-js",
"author": "Max Kraev <maxim.kraev@gmail.com>",
Expand Down
41 changes: 40 additions & 1 deletion src/lib/assignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,44 @@ export async function updateStudentTimeExtension(
}
}

export type ProjectSource = {
type: 'git', url: string, credentials?: {username: string, password: string}
} | {
type: 'zip'
}

export type AssignmentData = {
moduleId: string
settings: {
name: string
description?: string
imageUrl?: string
gigaboxSlot?: {
boxType: string
}
}
}

export async function createAssignment(courseId: string, assignmentData: AssignmentData): Promise<string> {
const api = bent(getApiV1Url(), 'POST', 'json', 200)
try {
const res = await api(`/courses/${courseId}/assignments`, assignmentData, getBearer())
const assignmentId = res['id']
if (!assignmentId) {
throw new Error('assignmentId not found in response')
}
return assignmentId
} catch (error: any) {
if (error.json) {
const message = JSON.stringify(await error.json())
console.log(message)
throw new Error(message)
}
console.log(error)
throw error
}
}

const assignment = {
publish: async (courseId: string, assignmentId: string, projectPath: string,
changelogOrOptions: string | PublishOptions): Promise<void> => {
Expand All @@ -459,7 +497,8 @@ const assignment = {
reducePublish,
updateSettings,
getSettings,
updateStudentTimeExtension
updateStudentTimeExtension,
createAssignment
}

export default assignment
49 changes: 48 additions & 1 deletion src/lib/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,51 @@ export async function filterLearnersForMentors(courseId: string, mapping: Filter
}
}

export type CreateCourseRequest = {
name: string,
description?: string,
start?: string,
end?: string,
timezone?: string,
tags?: string[]
}

export async function createCourse(courseData: CreateCourseRequest): Promise<string> {
const api = bent(getApiV1Url(), 'POST', 'json', 200)
try {
const res = await api(`/courses`, courseData, getBearer())
const courseId = res['id']
if (!courseId) {
throw new Error('courseId not found in response')
}
return courseId
} catch (error: any) {
if (error.json) {
const message = JSON.stringify(await error.json())
throw new Error(message)
}
throw error
}
}

export async function createModule(courseId: string, moduleName: string): Promise<string> {
const api = bent(getApiV1Url(), 'POST', 'json', 200)
try {
const res = await api(`/courses/${courseId}/modules`, { name: moduleName }, getBearer())
const moduleId = res['id']
if (!moduleId) {
throw new Error('moduleId not found in response')
}
return moduleId
} catch (error: any) {
if (error.json) {
const message = JSON.stringify(await error.json())
throw new Error(message)
}
throw error
}
}

const course = {
assignmentStudentsProgress,
info,
Expand Down Expand Up @@ -607,7 +652,9 @@ const course = {
archive,
exportCoachData,
exportLLMProxyData,
filterLearnersForMentors
filterLearnersForMentors,
createCourse,
createModule
}

export default course