mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-27 07:58:31 -06:00
refactoring files to be located by feature
This commit is contained in:
116
src/features/local/assignments/assignmentRouter.ts
Normal file
116
src/features/local/assignments/assignmentRouter.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
import publicProcedure from "../../../services/serverFunctions/procedures/public";
|
||||
import { z } from "zod";
|
||||
import { router } from "../../../services/serverFunctions/trpcSetup";
|
||||
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
||||
import { zodLocalAssignment } from "@/features/local/assignments/models/localAssignment";
|
||||
|
||||
export const assignmentRouter = router({
|
||||
getAssignment: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
courseName: z.string(),
|
||||
moduleName: z.string(),
|
||||
assignmentName: z.string(),
|
||||
})
|
||||
)
|
||||
.query(async ({ input: { courseName, moduleName, assignmentName } }) => {
|
||||
const assignment = await fileStorageService.assignments.getAssignment(
|
||||
courseName,
|
||||
moduleName,
|
||||
assignmentName
|
||||
);
|
||||
// console.log(assignment);
|
||||
return assignment;
|
||||
}),
|
||||
getAllAssignments: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
courseName: z.string(),
|
||||
moduleName: z.string(),
|
||||
})
|
||||
)
|
||||
.query(async ({ input: { courseName, moduleName } }) => {
|
||||
const assignments = await fileStorageService.assignments.getAssignments(
|
||||
courseName,
|
||||
moduleName
|
||||
);
|
||||
return assignments;
|
||||
}),
|
||||
createAssignment: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
courseName: z.string(),
|
||||
moduleName: z.string(),
|
||||
assignmentName: z.string(),
|
||||
assignment: zodLocalAssignment,
|
||||
})
|
||||
)
|
||||
.mutation(
|
||||
async ({
|
||||
input: { courseName, moduleName, assignmentName, assignment },
|
||||
}) => {
|
||||
await fileStorageService.assignments.updateOrCreateAssignment({
|
||||
courseName,
|
||||
moduleName,
|
||||
assignmentName,
|
||||
assignment,
|
||||
});
|
||||
}
|
||||
),
|
||||
updateAssignment: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
courseName: z.string(),
|
||||
moduleName: z.string(),
|
||||
previousModuleName: z.string(),
|
||||
previousAssignmentName: z.string(),
|
||||
assignmentName: z.string(),
|
||||
assignment: zodLocalAssignment,
|
||||
})
|
||||
)
|
||||
.mutation(
|
||||
async ({
|
||||
input: {
|
||||
courseName,
|
||||
moduleName,
|
||||
assignmentName,
|
||||
assignment,
|
||||
previousModuleName,
|
||||
previousAssignmentName,
|
||||
},
|
||||
}) => {
|
||||
await fileStorageService.assignments.updateOrCreateAssignment({
|
||||
courseName,
|
||||
moduleName,
|
||||
assignmentName,
|
||||
assignment,
|
||||
});
|
||||
|
||||
if (
|
||||
assignmentName !== previousAssignmentName ||
|
||||
moduleName !== previousModuleName
|
||||
) {
|
||||
await fileStorageService.assignments.delete({
|
||||
courseName,
|
||||
moduleName: previousModuleName,
|
||||
assignmentName: previousAssignmentName,
|
||||
});
|
||||
}
|
||||
}
|
||||
),
|
||||
deleteAssignment: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
courseName: z.string(),
|
||||
moduleName: z.string(),
|
||||
assignmentName: z.string(),
|
||||
})
|
||||
)
|
||||
.mutation(async ({ input: { courseName, moduleName, assignmentName } }) => {
|
||||
await fileStorageService.assignments.delete({
|
||||
courseName,
|
||||
moduleName,
|
||||
assignmentName,
|
||||
});
|
||||
}),
|
||||
});
|
||||
Reference in New Issue
Block a user