mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
more refactoring by feature
This commit is contained in:
110
src/features/local/quizzes/quizRouter.ts
Normal file
110
src/features/local/quizzes/quizRouter.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
import publicProcedure from "../../../services/serverFunctions/procedures/public";
|
||||
import { z } from "zod";
|
||||
import { router } from "../../../services/serverFunctions/trpcSetup";
|
||||
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
||||
import { zodLocalQuiz } from "@/features/local/quizzes/models/localQuiz";
|
||||
|
||||
export const quizRouter = router({
|
||||
getQuiz: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
courseName: z.string(),
|
||||
moduleName: z.string(),
|
||||
quizName: z.string(),
|
||||
})
|
||||
)
|
||||
.query(async ({ input: { courseName, moduleName, quizName } }) => {
|
||||
return await fileStorageService.quizzes.getQuiz(
|
||||
courseName,
|
||||
moduleName,
|
||||
quizName
|
||||
);
|
||||
}),
|
||||
|
||||
getAllQuizzes: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
courseName: z.string(),
|
||||
moduleName: z.string(),
|
||||
})
|
||||
)
|
||||
.query(async ({ input: { courseName, moduleName } }) => {
|
||||
return await fileStorageService.quizzes.getQuizzes(
|
||||
courseName,
|
||||
moduleName
|
||||
);
|
||||
}),
|
||||
createQuiz: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
courseName: z.string(),
|
||||
moduleName: z.string(),
|
||||
quizName: z.string(),
|
||||
quiz: zodLocalQuiz,
|
||||
})
|
||||
)
|
||||
.mutation(async ({ input: { courseName, moduleName, quizName, quiz } }) => {
|
||||
await fileStorageService.quizzes.updateQuiz({
|
||||
courseName,
|
||||
moduleName,
|
||||
quizName,
|
||||
quiz,
|
||||
});
|
||||
}),
|
||||
updateQuiz: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
courseName: z.string(),
|
||||
moduleName: z.string(),
|
||||
previousModuleName: z.string(),
|
||||
previousQuizName: z.string(),
|
||||
quizName: z.string(),
|
||||
quiz: zodLocalQuiz,
|
||||
})
|
||||
)
|
||||
.mutation(
|
||||
async ({
|
||||
input: {
|
||||
courseName,
|
||||
moduleName,
|
||||
quizName,
|
||||
quiz,
|
||||
previousModuleName,
|
||||
previousQuizName,
|
||||
},
|
||||
}) => {
|
||||
await fileStorageService.quizzes.updateQuiz({
|
||||
courseName,
|
||||
moduleName,
|
||||
quizName,
|
||||
quiz,
|
||||
});
|
||||
|
||||
if (
|
||||
quizName !== previousQuizName ||
|
||||
moduleName !== previousModuleName
|
||||
) {
|
||||
await fileStorageService.quizzes.delete({
|
||||
courseName,
|
||||
moduleName: previousModuleName,
|
||||
quizName: previousQuizName,
|
||||
});
|
||||
}
|
||||
}
|
||||
),
|
||||
deleteQuiz: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
courseName: z.string(),
|
||||
moduleName: z.string(),
|
||||
quizName: z.string(),
|
||||
})
|
||||
)
|
||||
.mutation(async ({ input: { courseName, moduleName, quizName } }) => {
|
||||
await fileStorageService.quizzes.delete({
|
||||
courseName,
|
||||
moduleName,
|
||||
quizName,
|
||||
});
|
||||
}),
|
||||
});
|
||||
Reference in New Issue
Block a user