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 { IModuleItem } from "../IModuleItem";
|
||||
import { verifyDateOrThrow } from "../timeUtils";
|
||||
|
||||
export interface LocalCoursePage extends IModuleItem {
|
||||
name: string;
|
||||
@@ -9,9 +10,7 @@ export interface LocalCoursePage extends IModuleItem {
|
||||
|
||||
export const localPageMarkdownUtils = {
|
||||
toMarkdown: (page: LocalCoursePage) => {
|
||||
const printableDueDate = new Date(page.dueAt)
|
||||
.toISOString()
|
||||
.replace("\u202F", " ");
|
||||
const printableDueDate = verifyDateOrThrow(page.dueAt, "page DueDateForOrdering")
|
||||
const settingsMarkdown = `Name: ${page.name}\nDueDateForOrdering: ${printableDueDate}\n---\n`;
|
||||
return settingsMarkdown + page.text;
|
||||
},
|
||||
@@ -20,17 +19,13 @@ export const localPageMarkdownUtils = {
|
||||
const rawSettings = pageMarkdown.split("---")[0];
|
||||
const name = extractLabelValue(rawSettings, "Name");
|
||||
const rawDate = extractLabelValue(rawSettings, "DueDateForOrdering");
|
||||
|
||||
const parsedDate = new Date(rawDate);
|
||||
if (isNaN(parsedDate.getTime())) {
|
||||
throw new Error(`could not parse due date: ${rawDate}`);
|
||||
}
|
||||
const dueAt = verifyDateOrThrow(rawDate, "page DueDateForOrdering");
|
||||
|
||||
const text = pageMarkdown.split("---\n")[1];
|
||||
|
||||
const page: LocalCoursePage = {
|
||||
name,
|
||||
dueAt: parsedDate.toISOString(),
|
||||
dueAt,
|
||||
text,
|
||||
};
|
||||
return page;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
export const getDateFromString = (value: string) => {
|
||||
// may need to check for other formats
|
||||
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)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,21 @@
|
||||
import { LocalAssignment, localAssignmentMarkdown } from "@/models/local/assignmnet/localAssignment";
|
||||
import { LocalCourse, LocalCourseSettings, localCourseYamlUtils } from "@/models/local/localCourse";
|
||||
import {
|
||||
LocalAssignment,
|
||||
localAssignmentMarkdown,
|
||||
} from "@/models/local/assignmnet/localAssignment";
|
||||
import {
|
||||
LocalCourse,
|
||||
LocalCourseSettings,
|
||||
localCourseYamlUtils,
|
||||
} from "@/models/local/localCourse";
|
||||
import { LocalModule } from "@/models/local/localModules";
|
||||
import { LocalCoursePage, localPageMarkdownUtils } from "@/models/local/page/localCoursePage";
|
||||
import { LocalQuiz, localQuizMarkdownUtils } from "@/models/local/quiz/localQuiz";
|
||||
import {
|
||||
LocalCoursePage,
|
||||
localPageMarkdownUtils,
|
||||
} from "@/models/local/page/localCoursePage";
|
||||
import {
|
||||
LocalQuiz,
|
||||
localQuizMarkdownUtils,
|
||||
} from "@/models/local/quiz/localQuiz";
|
||||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
|
||||
|
||||
@@ -7,13 +7,8 @@ import { QuestionType } from "@/models/local/quiz/localQuizQuestion";
|
||||
import { fileStorageService } from "../fileStorage/fileStorageService";
|
||||
|
||||
describe("FileStorageTests", () => {
|
||||
let storageDirectory: string;
|
||||
|
||||
beforeEach(() => {
|
||||
const tempDirectory = path.resolve("./temp");
|
||||
storageDirectory = path.join(tempDirectory, "fileStorageTests");
|
||||
console.log(storageDirectory);
|
||||
|
||||
const storageDirectory = process.env.STORAGE_DIRECTORY ?? "/tmp/canvasManagerTests";
|
||||
if (fs.existsSync(storageDirectory)) {
|
||||
fs.rmdirSync(storageDirectory, { recursive: true });
|
||||
}
|
||||
@@ -121,7 +116,7 @@ describe("FileStorageTests", () => {
|
||||
{ points: 4, label: "do task 1" },
|
||||
{ points: 2, label: "do task 2" },
|
||||
],
|
||||
allowedFileUploadExtensions: []
|
||||
allowedFileUploadExtensions: [],
|
||||
},
|
||||
],
|
||||
quizzes: [],
|
||||
@@ -171,11 +166,11 @@ describe("FileStorageTests", () => {
|
||||
questionType: QuestionType.ESSAY,
|
||||
points: 1,
|
||||
answers: [],
|
||||
matchDistractors: []
|
||||
matchDistractors: [],
|
||||
},
|
||||
],
|
||||
showCorrectAnswers: false,
|
||||
allowedAttempts: 0
|
||||
allowedAttempts: 0,
|
||||
},
|
||||
],
|
||||
pages: [],
|
||||
@@ -220,7 +215,7 @@ describe("FileStorageTests", () => {
|
||||
{ points: 4, label: "do task 1" },
|
||||
{ points: 2, label: "do task 2" },
|
||||
],
|
||||
allowedFileUploadExtensions: []
|
||||
allowedFileUploadExtensions: [],
|
||||
},
|
||||
],
|
||||
quizzes: [
|
||||
@@ -239,10 +234,10 @@ describe("FileStorageTests", () => {
|
||||
questionType: QuestionType.SHORT_ANSWER,
|
||||
points: 1,
|
||||
answers: [],
|
||||
matchDistractors: []
|
||||
matchDistractors: [],
|
||||
},
|
||||
],
|
||||
showCorrectAnswers: false
|
||||
showCorrectAnswers: false,
|
||||
},
|
||||
],
|
||||
pages: [],
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { loadEnvConfig } from "@next/env";
|
||||
import { defineConfig } from "vitest/config";
|
||||
import react from "@vitejs/plugin-react";
|
||||
|
||||
loadEnvConfig(process.cwd());
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
|
||||
Reference in New Issue
Block a user