-
Notifications
You must be signed in to change notification settings - Fork 556
Expand file tree
/
Copy pathgradebookService.js
More file actions
106 lines (96 loc) · 3.84 KB
/
Copy pathgradebookService.js
File metadata and controls
106 lines (96 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import baseService from "./baseService"
const API_BASE = "/gradebook"
export default {
/**
* Fetches gradebook categories for a specific course and session.
* @param {number} courseId The course ID.
* @param {number|null} sessionId The session ID (optional).
* @returns {Promise<Array>} The list of gradebook categories.
*/
async getCategories(courseId, sessionId = null) {
const params = { courseId }
if (sessionId) params.sessionId = sessionId
try {
return await baseService.get(`${API_BASE}/categories`, params)
} catch (error) {
console.error("Error fetching gradebook categories:", error)
throw error
}
},
/**
* Sets a document as the default certificate for a course.
* @param {number|string} courseId
* @param {number|string} certificateId
* @returns {Promise<Object>}
*/
async setDefaultCertificate(courseId, certificateId) {
return await baseService.patch(`${API_BASE}/set_default_certificate/${courseId}/${certificateId}`, {})
},
/**
* Fetches the default certificate for a course.
* @param {number|string} courseId
* @returns {Promise<Object>}
*/
async getDefaultCertificate(courseId) {
return await baseService.get(`${API_BASE}/default_certificate/${courseId}`)
},
/**
* Updates the calculation mode (weighted_average | points_sum) of a gradebook category.
* @param {number|string} categoryId The numeric id of the gradebook category.
* @param {string} calculationMode The target calculation mode.
* @returns {Promise<Object>} The updated category resource.
*/
async updateCalculationMode(categoryId, calculationMode) {
return await baseService.put(`/api/gradebook_categories/${categoryId}`, { calculationMode })
},
/**
* Fetches the gradebook links of a category.
* @param {number|string} categoryId The numeric id of the gradebook category.
* @returns {Promise<Array>} The list of gradebook links.
*/
async getLinks(categoryId) {
return await baseService.getCollection("/api/gradebook_links", {
category: `/api/gradebook_categories/${categoryId}`,
})
},
/**
* Creates a forum participation gradebook item.
* @param {Object} payload The link payload.
* @param {number} payload.threadId The forum thread id used as ref_id.
* @param {number} payload.courseId The course id.
* @param {number|string} payload.categoryId The gradebook category id.
* @param {number} payload.pointsOne Points awarded for exactly one message.
* @param {number} payload.pointsMany Points awarded for two or more messages.
* @returns {Promise<Object>} The created gradebook link resource.
*/
async createForumParticipationLink({ threadId, courseId, categoryId, pointsOne, pointsMany }) {
// 11 = LINK_FORUM_PARTICIPATION. Weight equals pointsMany (the item's max points) so in
// points_sum the contribution equals the earned points.
return await baseService.post("/api/gradebook_links", {
type: 11,
refId: threadId,
course: `/api/courses/${courseId}`,
category: `/api/gradebook_categories/${categoryId}`,
weight: Number(pointsMany),
pointsOne: String(pointsOne),
pointsMany: String(pointsMany),
})
},
/**
* Updates a forum participation gradebook item.
* @param {number|string} linkId The numeric id of the gradebook link.
* @param {Object} payload The fields to update (pointsOne, pointsMany, refId).
* @returns {Promise<Object>} The updated gradebook link resource.
*/
async updateForumParticipationLink(linkId, payload) {
return await baseService.put(`/api/gradebook_links/${linkId}`, payload)
},
/**
* Deletes a gradebook link.
* @param {number|string} linkId The numeric id of the gradebook link.
* @returns {Promise<Object>}
*/
async deleteLink(linkId) {
return await baseService.delete(`/api/gradebook_links/${linkId}`)
},
}