All files / server/src/features/program-item programItemSchema.ts

100% Statements 8/8
100% Branches 0/0
100% Functions 5/5
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110                                      60x             12535x             12535x                           312x                   60x                 12535x                     12535x                                                       60x        
// Registers the global mongoose plugins, which are applied when a model is
// compiled below, so it has to stay above the other imports
import "server/db/mongoosePlugins";
import mongoose from "mongoose";
import { z } from "zod";
import {
  AgeGroup,
  Gamestyle,
  Genre,
  InclusivityValue,
  Language,
  Popularity,
  ProgramItemSignupStrategy,
  ProgramType,
  SignupType,
  State,
  Tag,
} from "shared/types/models/programItem";
 
export const ProgramItemSchemaDb = z
  .object({
    programItemId: z.string(),
    parentId: z.string(),
    title: z.string(),
    description: z.string(),
    location: z.string(),
    startTime: z.date().transform((date) => date.toISOString()),
    mins: z.number(),
    tags: z.array(z.enum(Tag)),
    ageGroups: z.array(z.enum(AgeGroup)),
    genres: z.array(z.enum(Genre)),
    styles: z.array(z.enum(Gamestyle)),
    languages: z.array(z.enum(Language)),
    endTime: z.date().transform((date) => date.toISOString()),
    people: z.string(),
    minAttendance: z.number(),
    maxAttendance: z.number(),
    gameSystem: z.string(),
    popularity: z.enum(Popularity),
    shortDescription: z.string(),
    revolvingDoor: z.boolean(),
    programType: z.enum(ProgramType),
    contentWarnings: z.string(),
    otherAuthor: z.string(),
    accessibilityValues: z.array(z.enum(InclusivityValue)),
    signupStrategy: z.optional(z.enum(ProgramItemSignupStrategy)),
    lotteryRanForStartTime: z.optional(
      z.date().transform((date) => date.toISOString()),
    ),
    passedOverForLottery: z.optional(z.boolean()),
    otherAccessibilityInformation: z.string(),
    entryFee: z.string(),
    signupType: z.enum(SignupType),
    state: z.enum(State),
  })
  .strip();
 
const programItemSchema = new mongoose.Schema(
  {
    programItemId: { type: String, required: true },
    parentId: { type: String, required: true },
    title: { type: String, required: true },
    description: { type: String, required: true },
    location: { type: String, required: true },
    startTime: {
      type: Date,
      get: (value: Date) => new Date(value),
      required: true,
    },
    mins: { type: Number, required: true },
    tags: { type: [String], required: true },
    ageGroups: { type: [String], required: true },
    genres: { type: [String], required: true },
    styles: { type: [String], required: true },
    languages: { type: [String], required: true },
    endTime: {
      type: Date,
      get: (value: Date) => new Date(value),
      required: true,
    },
    people: { type: String, required: true },
    minAttendance: { type: Number, required: true },
    maxAttendance: { type: Number, required: true },
    gameSystem: { type: String, required: true },
    shortDescription: { type: String, required: true },
    revolvingDoor: { type: Boolean, required: true },
    popularity: { type: String, default: Popularity.NULL },
    // Server-owned like popularity: written by the assignment, and left out of the program
    // item import so a Kompassi update doesn't clear it. No getter, because it is absent on
    // every program item no lottery has run for and one would read that absence as an
    // Invalid Date.
    lotteryRanForStartTime: { type: Date },
    passedOverForLottery: { type: Boolean },
    programType: { type: String, required: true },
    contentWarnings: { type: String, required: true },
    otherAuthor: { type: String, required: true },
    accessibilityValues: { type: [String], required: true },
    otherAccessibilityInformation: { type: String, required: true },
    entryFee: { type: String, required: true },
    signupType: { type: String, required: true },
    state: { type: String, required: true },
  },
  { timestamps: true },
);
 
export const ProgramItemModel = mongoose.model(
  "program-item",
  programItemSchema,
);