questions-api-shema.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { z } from "zod";
  2. import { DbShema } from "../db-shema.js";
  3. class QuestionsApiShema {
  4. public ZCreateNewQuestion = {
  5. req: {
  6. data: z.object({
  7. text: DbShema.ZQuestions.shape.q_text,
  8. answers: DbShema.ZQuestions.shape.answers,
  9. difficulty: DbShema.ZQuestions.shape.difficulty,
  10. categories: z.array(DbShema.ZCategories.shape.category_id),
  11. }),
  12. questionId: z.number().optional(),
  13. },
  14. };
  15. //
  16. public ZCategory = z.object({
  17. category_id: DbShema.ZCategories.shape.category_id,
  18. name: DbShema.ZCategories.shape.name,
  19. description: DbShema.ZCategories.shape.description,
  20. category_questions_count:
  21. DbShema.ZRemainingCategoryQuestions.shape.category_questions_count,
  22. max_used_category_questions:
  23. DbShema.ZRemainingCategoryQuestions.shape.max_used_category_questions,
  24. questions_remained:
  25. DbShema.ZRemainingCategoryQuestions.shape.questions_remained,
  26. is_shortage: z.boolean(),
  27. });
  28. public ZGetCategories = {
  29. res: z.array(this.ZCategory),
  30. };
  31. //
  32. public ZCreateNewCategory = {
  33. req: z.object({
  34. name: DbShema.ZCategories.shape.name,
  35. description: DbShema.ZCategories.shape.description,
  36. }),
  37. };
  38. public ZGetQuestionsByCategory = {
  39. req: z.object({
  40. categoryId: DbShema.ZCategories.shape.category_id,
  41. }),
  42. res: z.object({
  43. questions: z.array(DbShema.ZQuestions),
  44. }),
  45. };
  46. public ZGetQuestionCategories = {
  47. req: z.object({
  48. questionId: DbShema.ZQuestions.shape.question_id,
  49. }),
  50. res: z.object({
  51. categories: z.array(z.number()),
  52. }),
  53. };
  54. public ZDeleteQuestion = {
  55. req: z.object({
  56. questionId: DbShema.ZQuestions.shape.question_id,
  57. }),
  58. };
  59. }
  60. export default new QuestionsApiShema();