mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
client vs server render issues
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import { canvasServiceUtils } from "./canvasServiceUtils";
|
||||
import { baseCanvasUrl, canvasServiceUtils } from "./canvasServiceUtils";
|
||||
import { axiosClient } from "../axiosUtils";
|
||||
import { CanvasAssignmentGroup } from "@/models/canvas/assignments/canvasAssignmentGroup";
|
||||
import { LocalAssignmentGroup } from "@/models/local/assignment/localAssignmentGroup";
|
||||
import { rateLimitAwareDelete } from "./canvasWebRequestor";
|
||||
|
||||
const baseCanvasUrl = "https://snow.instructure.com/api/v1";
|
||||
|
||||
export const canvasAssignmentGroupService = {
|
||||
async getAll(courseId: number): Promise<CanvasAssignmentGroup[]> {
|
||||
|
||||
65
nextjs/src/services/canvas/canvasModuleService.ts
Normal file
65
nextjs/src/services/canvas/canvasModuleService.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { CanvasModuleItem } from "@/models/canvas/modules/canvasModuleItems";
|
||||
import { CanvasPage } from "@/models/canvas/pages/canvasPageModel";
|
||||
import { axiosClient } from "../axiosUtils";
|
||||
import { baseCanvasUrl } from "./canvasServiceUtils";
|
||||
import { CanvasModule } from "@/models/canvas/modules/canvasModule";
|
||||
|
||||
export const canvasModuleService = {
|
||||
async updateModuleItem(
|
||||
canvasCourseId: number,
|
||||
canvasModuleId: number,
|
||||
item: CanvasModuleItem
|
||||
) {
|
||||
console.log(`Updating module item ${item.title}`);
|
||||
const url = `${baseCanvasUrl}/courses/${canvasCourseId}/modules/${canvasModuleId}/items/${item.id}`;
|
||||
const body = {
|
||||
module_item: { title: item.title, position: item.position },
|
||||
};
|
||||
const { data } = await axiosClient.put<CanvasModuleItem>(url, body);
|
||||
|
||||
if (!data) throw new Error("Something went wrong updating module item");
|
||||
},
|
||||
|
||||
async createModuleItem(
|
||||
canvasCourseId: number,
|
||||
canvasModuleId: number,
|
||||
title: string,
|
||||
type: string,
|
||||
contentId: number | string
|
||||
): Promise<void> {
|
||||
console.log(`Creating new module item ${title}`);
|
||||
const url = `${baseCanvasUrl}/courses/${canvasCourseId}/modules/${canvasModuleId}/items`;
|
||||
const body = { module_item: { title, type, content_id: contentId } };
|
||||
await axiosClient.post(url, body);
|
||||
},
|
||||
|
||||
async createPageModuleItem(
|
||||
canvasCourseId: number,
|
||||
canvasModuleId: number,
|
||||
title: string,
|
||||
canvasPage: CanvasPage
|
||||
): Promise<void> {
|
||||
console.log(`Creating new module item ${title}`);
|
||||
const url = `${baseCanvasUrl}/courses/${canvasCourseId}/modules/${canvasModuleId}/items`;
|
||||
const body = {
|
||||
module_item: { title, type: "Page", page_url: canvasPage.url },
|
||||
};
|
||||
await axiosClient.post<CanvasModuleItem>(url, body);
|
||||
},
|
||||
|
||||
async getCourseModules(canvasCourseId: number) {
|
||||
const url = `${baseCanvasUrl}/courses/${canvasCourseId}/modules`;
|
||||
const response = await axiosClient.get<CanvasModule[]>(url);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async createModule(canvasCourseId: number, moduleName: string) {
|
||||
const url = `${baseCanvasUrl}/courses/${canvasCourseId}/modules`;
|
||||
const body = {
|
||||
module: {
|
||||
name: moduleName,
|
||||
},
|
||||
};
|
||||
await axiosClient.post(url, body);
|
||||
},
|
||||
};
|
||||
@@ -1,11 +1,10 @@
|
||||
import { CanvasPage } from "@/models/canvas/pages/canvasPageModel";
|
||||
import { LocalCoursePage } from "@/models/local/page/localCoursePage";
|
||||
import { canvasServiceUtils } from "./canvasServiceUtils";
|
||||
import { baseCanvasUrl, canvasServiceUtils } from "./canvasServiceUtils";
|
||||
import { markdownToHTMLSafe } from "../htmlMarkdownUtils";
|
||||
import { axiosClient } from "../axiosUtils";
|
||||
import { rateLimitAwareDelete } from "./canvasWebRequestor";
|
||||
|
||||
const baseCanvasUrl = "https://snow.instructure.com/api/v1";
|
||||
|
||||
export const canvasPageService = {
|
||||
async getAll(courseId: number): Promise<CanvasPage[]> {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { CanvasEnrollmentTermModel } from "@/models/canvas/enrollmentTerms/canvasEnrollmentTermModel";
|
||||
import { canvasServiceUtils } from "./canvasServiceUtils";
|
||||
import { baseCanvasUrl, canvasServiceUtils } from "./canvasServiceUtils";
|
||||
import { CanvasCourseModel } from "@/models/canvas/courses/canvasCourseModel";
|
||||
import { CanvasModuleItem } from "@/models/canvas/modules/canvasModuleItems";
|
||||
import { CanvasPage } from "@/models/canvas/pages/canvasPageModel";
|
||||
import { CanvasEnrollmentModel } from "@/models/canvas/enrollments/canvasEnrollmentModel";
|
||||
import { axiosClient } from "../axiosUtils";
|
||||
|
||||
const baseCanvasUrl = "https://snow.instructure.com/api/v1";
|
||||
|
||||
const getAllTerms = async () => {
|
||||
const url = `${baseCanvasUrl}/accounts/10/terms`;
|
||||
@@ -23,7 +22,7 @@ export const canvasService = {
|
||||
getAllTerms,
|
||||
async getCourses(termId: number) {
|
||||
const url = `${baseCanvasUrl}/courses`;
|
||||
const response = await axiosClient.get<CanvasCourseModel[][]>(url);
|
||||
const response = await axiosClient.get<CanvasCourseModel[]>(url);
|
||||
const allCourses = response.data;
|
||||
const coursesInTerm = allCourses
|
||||
.flatMap((l) => l)
|
||||
@@ -57,47 +56,6 @@ export const canvasService = {
|
||||
return currentTerms;
|
||||
},
|
||||
|
||||
async updateModuleItem(
|
||||
canvasCourseId: number,
|
||||
canvasModuleId: number,
|
||||
item: CanvasModuleItem
|
||||
) {
|
||||
console.log(`Updating module item ${item.title}`);
|
||||
const url = `${baseCanvasUrl}/courses/${canvasCourseId}/modules/${canvasModuleId}/items/${item.id}`;
|
||||
const body = {
|
||||
module_item: { title: item.title, position: item.position },
|
||||
};
|
||||
const { data } = await axiosClient.put<CanvasModuleItem>(url, body);
|
||||
|
||||
if (!data) throw new Error("Something went wrong updating module item");
|
||||
},
|
||||
|
||||
async createModuleItem(
|
||||
canvasCourseId: number,
|
||||
canvasModuleId: number,
|
||||
title: string,
|
||||
type: string,
|
||||
contentId: number | string
|
||||
): Promise<void> {
|
||||
console.log(`Creating new module item ${title}`);
|
||||
const url = `${baseCanvasUrl}/courses/${canvasCourseId}/modules/${canvasModuleId}/items`;
|
||||
const body = { module_item: { title, type, content_id: contentId } };
|
||||
const response = await axiosClient.post(url, body);
|
||||
},
|
||||
|
||||
async createPageModuleItem(
|
||||
canvasCourseId: number,
|
||||
canvasModuleId: number,
|
||||
title: string,
|
||||
canvasPage: CanvasPage
|
||||
): Promise<void> {
|
||||
console.log(`Creating new module item ${title}`);
|
||||
const url = `${baseCanvasUrl}/courses/${canvasCourseId}/modules/${canvasModuleId}/items`;
|
||||
const body = {
|
||||
module_item: { title, type: "Page", page_url: canvasPage.url },
|
||||
};
|
||||
await axiosClient.post<CanvasModuleItem>(url, body);
|
||||
},
|
||||
|
||||
async getEnrolledStudents(canvasCourseId: number) {
|
||||
console.log(`Getting students for course ${canvasCourseId}`);
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
import { AxiosResponseHeaders, RawAxiosResponseHeaders } from "axios";
|
||||
import { axiosClient } from "../axiosUtils";
|
||||
|
||||
|
||||
export const baseCanvasUrl = "https://snow.instructure.com/api/v1";
|
||||
|
||||
const getNextUrl = (
|
||||
headers: AxiosResponseHeaders | RawAxiosResponseHeaders
|
||||
): string | undefined => {
|
||||
|
||||
Reference in New Issue
Block a user