-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.ts
More file actions
96 lines (90 loc) · 1.99 KB
/
event.ts
File metadata and controls
96 lines (90 loc) · 1.99 KB
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
import { AccessibleRecordModel, accessibleRecordsPlugin } from "@casl/mongoose";
import mongoose, { Schema, model, Types } from "mongoose";
import mongooseAutopopulate from "mongoose-autopopulate";
import { AutoPopulatedDoc } from "@api/common";
import { HexathonModel } from "./hexathon";
import { Location, LocationModel } from "./location";
import { Tag, TagModel } from "./tag";
export enum EventType {
FOOD = "food",
WORKSHOP = "workshop",
CEREMONY = "ceremony",
TECH_TALK = "tech-talk",
MINI_EVENT = "mini-event",
IMPORTANT = "important",
SPEAKER = "speaker",
MINI_CHALLENGE = "mini-challenge",
}
export interface Event extends mongoose.Document {
hexathon: Types.ObjectId;
name: string;
type: EventType;
description: string;
startDate: Date;
endDate: Date;
location: AutoPopulatedDoc<Location>[];
tags: AutoPopulatedDoc<Tag>[];
checkIns: number;
}
const eventSchema = new Schema<Event>({
hexathon: {
type: Schema.Types.ObjectId,
required: true,
ref: HexathonModel,
index: true,
},
name: {
type: String,
required: true,
},
type: {
type: String,
enum: Object.values(EventType),
required: true,
index: true,
},
description: {
type: String,
required: true,
default: " ",
},
startDate: {
type: Date,
required: true,
},
endDate: {
type: Date,
required: true,
},
location: {
type: [
{
type: Schema.Types.ObjectId,
required: true,
ref: LocationModel,
autopopulate: true,
index: true,
},
],
default: [],
},
tags: {
type: [
{
type: Schema.Types.ObjectId,
ref: TagModel,
autopopulate: true,
index: true,
},
],
default: [],
},
checkIns: {
type: Number,
required: false,
default: 0,
},
});
eventSchema.plugin(mongooseAutopopulate);
eventSchema.plugin(accessibleRecordsPlugin);
export const EventModel = model<Event, AccessibleRecordModel<Event>>("Event", eventSchema);