mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
consolodating date logic
This commit is contained in:
@@ -1 +1 @@
|
|||||||
STORAGE_DIRECTORY="/tmp/canvasManagerStorage"
|
STORAGE_DIRECTORY="./temp/canvasManagerStorage"
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { extractLabelValue } from "../assignmnet/utils/markdownUtils";
|
import { extractLabelValue } from "../assignmnet/utils/markdownUtils";
|
||||||
import { IModuleItem } from "../IModuleItem";
|
import { IModuleItem } from "../IModuleItem";
|
||||||
|
import { verifyDateOrThrow } from "../timeUtils";
|
||||||
|
|
||||||
export interface LocalCoursePage extends IModuleItem {
|
export interface LocalCoursePage extends IModuleItem {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -9,9 +10,7 @@ export interface LocalCoursePage extends IModuleItem {
|
|||||||
|
|
||||||
export const localPageMarkdownUtils = {
|
export const localPageMarkdownUtils = {
|
||||||
toMarkdown: (page: LocalCoursePage) => {
|
toMarkdown: (page: LocalCoursePage) => {
|
||||||
const printableDueDate = new Date(page.dueAt)
|
const printableDueDate = verifyDateOrThrow(page.dueAt, "page DueDateForOrdering")
|
||||||
.toISOString()
|
|
||||||
.replace("\u202F", " ");
|
|
||||||
const settingsMarkdown = `Name: ${page.name}\nDueDateForOrdering: ${printableDueDate}\n---\n`;
|
const settingsMarkdown = `Name: ${page.name}\nDueDateForOrdering: ${printableDueDate}\n---\n`;
|
||||||
return settingsMarkdown + page.text;
|
return settingsMarkdown + page.text;
|
||||||
},
|
},
|
||||||
@@ -20,17 +19,13 @@ export const localPageMarkdownUtils = {
|
|||||||
const rawSettings = pageMarkdown.split("---")[0];
|
const rawSettings = pageMarkdown.split("---")[0];
|
||||||
const name = extractLabelValue(rawSettings, "Name");
|
const name = extractLabelValue(rawSettings, "Name");
|
||||||
const rawDate = extractLabelValue(rawSettings, "DueDateForOrdering");
|
const rawDate = extractLabelValue(rawSettings, "DueDateForOrdering");
|
||||||
|
const dueAt = verifyDateOrThrow(rawDate, "page DueDateForOrdering");
|
||||||
const parsedDate = new Date(rawDate);
|
|
||||||
if (isNaN(parsedDate.getTime())) {
|
|
||||||
throw new Error(`could not parse due date: ${rawDate}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const text = pageMarkdown.split("---\n")[1];
|
const text = pageMarkdown.split("---\n")[1];
|
||||||
|
|
||||||
const page: LocalCoursePage = {
|
const page: LocalCoursePage = {
|
||||||
name,
|
name,
|
||||||
dueAt: parsedDate.toISOString(),
|
dueAt,
|
||||||
text,
|
text,
|
||||||
};
|
};
|
||||||
return page;
|
return page;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
export const getDateFromString = (value: string) => {
|
export const getDateFromString = (value: string) => {
|
||||||
// may need to check for other formats
|
// may need to check for other formats
|
||||||
const validDateRegex =
|
const validDateRegex =
|
||||||
/\d{2}\/\d{2}\/\d{4} [0-2][0-9]|[0-5][0-9]|[0-2][0-9]:[0-5][0-9]:[0-5][0-9]/;
|
/\d{2}\/\d{2}\/\d{4} [0-2][0-9]:[0-5][0-9]:[0-5][0-9]/;
|
||||||
if (!validDateRegex.test(value)) {
|
if (!validDateRegex.test(value)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,21 @@
|
|||||||
import { LocalAssignment, localAssignmentMarkdown } from "@/models/local/assignmnet/localAssignment";
|
import {
|
||||||
import { LocalCourse, LocalCourseSettings, localCourseYamlUtils } from "@/models/local/localCourse";
|
LocalAssignment,
|
||||||
|
localAssignmentMarkdown,
|
||||||
|
} from "@/models/local/assignmnet/localAssignment";
|
||||||
|
import {
|
||||||
|
LocalCourse,
|
||||||
|
LocalCourseSettings,
|
||||||
|
localCourseYamlUtils,
|
||||||
|
} from "@/models/local/localCourse";
|
||||||
import { LocalModule } from "@/models/local/localModules";
|
import { LocalModule } from "@/models/local/localModules";
|
||||||
import { LocalCoursePage, localPageMarkdownUtils } from "@/models/local/page/localCoursePage";
|
import {
|
||||||
import { LocalQuiz, localQuizMarkdownUtils } from "@/models/local/quiz/localQuiz";
|
LocalCoursePage,
|
||||||
|
localPageMarkdownUtils,
|
||||||
|
} from "@/models/local/page/localCoursePage";
|
||||||
|
import {
|
||||||
|
LocalQuiz,
|
||||||
|
localQuizMarkdownUtils,
|
||||||
|
} from "@/models/local/quiz/localQuiz";
|
||||||
import { promises as fs } from "fs";
|
import { promises as fs } from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
@@ -60,7 +73,7 @@ export const courseMarkdownLoader = {
|
|||||||
|
|
||||||
const settingsString = await fs.readFile(settingsPath, "utf-8");
|
const settingsString = await fs.readFile(settingsPath, "utf-8");
|
||||||
const settings = localCourseYamlUtils.parseSettingYaml(settingsString);
|
const settings = localCourseYamlUtils.parseSettingYaml(settingsString);
|
||||||
|
|
||||||
const folderName = path.basename(courseDirectory);
|
const folderName = path.basename(courseDirectory);
|
||||||
return { ...settings, name: folderName };
|
return { ...settings, name: folderName };
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,13 +7,8 @@ import { QuestionType } from "@/models/local/quiz/localQuizQuestion";
|
|||||||
import { fileStorageService } from "../fileStorage/fileStorageService";
|
import { fileStorageService } from "../fileStorage/fileStorageService";
|
||||||
|
|
||||||
describe("FileStorageTests", () => {
|
describe("FileStorageTests", () => {
|
||||||
let storageDirectory: string;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const tempDirectory = path.resolve("./temp");
|
const storageDirectory = process.env.STORAGE_DIRECTORY ?? "/tmp/canvasManagerTests";
|
||||||
storageDirectory = path.join(tempDirectory, "fileStorageTests");
|
|
||||||
console.log(storageDirectory);
|
|
||||||
|
|
||||||
if (fs.existsSync(storageDirectory)) {
|
if (fs.existsSync(storageDirectory)) {
|
||||||
fs.rmdirSync(storageDirectory, { recursive: true });
|
fs.rmdirSync(storageDirectory, { recursive: true });
|
||||||
}
|
}
|
||||||
@@ -121,7 +116,7 @@ describe("FileStorageTests", () => {
|
|||||||
{ points: 4, label: "do task 1" },
|
{ points: 4, label: "do task 1" },
|
||||||
{ points: 2, label: "do task 2" },
|
{ points: 2, label: "do task 2" },
|
||||||
],
|
],
|
||||||
allowedFileUploadExtensions: []
|
allowedFileUploadExtensions: [],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
quizzes: [],
|
quizzes: [],
|
||||||
@@ -171,11 +166,11 @@ describe("FileStorageTests", () => {
|
|||||||
questionType: QuestionType.ESSAY,
|
questionType: QuestionType.ESSAY,
|
||||||
points: 1,
|
points: 1,
|
||||||
answers: [],
|
answers: [],
|
||||||
matchDistractors: []
|
matchDistractors: [],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
showCorrectAnswers: false,
|
showCorrectAnswers: false,
|
||||||
allowedAttempts: 0
|
allowedAttempts: 0,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
pages: [],
|
pages: [],
|
||||||
@@ -220,7 +215,7 @@ describe("FileStorageTests", () => {
|
|||||||
{ points: 4, label: "do task 1" },
|
{ points: 4, label: "do task 1" },
|
||||||
{ points: 2, label: "do task 2" },
|
{ points: 2, label: "do task 2" },
|
||||||
],
|
],
|
||||||
allowedFileUploadExtensions: []
|
allowedFileUploadExtensions: [],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
quizzes: [
|
quizzes: [
|
||||||
@@ -239,10 +234,10 @@ describe("FileStorageTests", () => {
|
|||||||
questionType: QuestionType.SHORT_ANSWER,
|
questionType: QuestionType.SHORT_ANSWER,
|
||||||
points: 1,
|
points: 1,
|
||||||
answers: [],
|
answers: [],
|
||||||
matchDistractors: []
|
matchDistractors: [],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
showCorrectAnswers: false
|
showCorrectAnswers: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
pages: [],
|
pages: [],
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|
import { loadEnvConfig } from "@next/env";
|
||||||
import { defineConfig } from "vitest/config";
|
import { defineConfig } from "vitest/config";
|
||||||
import react from "@vitejs/plugin-react";
|
import react from "@vitejs/plugin-react";
|
||||||
|
|
||||||
|
loadEnvConfig(process.cwd());
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
resolve: {
|
resolve: {
|
||||||
|
|||||||
Reference in New Issue
Block a user