-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy patheventSchema.ts
More file actions
105 lines (99 loc) · 3.57 KB
/
Copy patheventSchema.ts
File metadata and controls
105 lines (99 loc) · 3.57 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
97
98
99
100
101
102
103
104
105
import { deleteModel, models, model, Schema } from "mongoose";
import { EVENT_LOCATION_CITY_OPTIONS, EVENT_LOCATION_GENERAL_OPTIONS } from "@/lib/eventOptions";
// The status of the event
export enum EventStatus {
pending = "pending",
approved = "approved",
rejected = "rejected",
expired = "expired",
}
export interface IEvent {
_id: string;
date: Date;
eventName: string;
time: string;
location: string;
locationLink?: string;
eventLocationGeneral?: string;
eventLocationGeneralOther?: string;
eventLocationCity?: string;
eventLocationCityOther?: string;
description: string;
majorFundraisingEvent?: boolean;
eventLink?: string;
organization: string;
publicContactEmail?: string;
publicContactPhoneNumber?: string;
submitterFirstName?: string;
submitterLastName?: string;
submitterEmail?: string;
submitterPhoneNumber?: string;
eventImage?: string;
organizationIcon?: string;
createdByUserId: string;
eventStatus: string;
approvedDate?: Date;
rejectionMessage?: string;
contactName?: string;
contactEmail?: string;
createdAt?: Date;
updatedAt?: Date;
}
const EventSchema = new Schema<IEvent>(
{
date: { type: Date, required: true },
eventName: { type: String, required: true, trim: true },
time: { type: String, required: false, trim: true, default: "" },
location: { type: String, required: false, trim: true, default: "" },
locationLink: { type: String, required: false, trim: true },
eventLocationGeneral: {
type: String,
required: false,
enum: EVENT_LOCATION_GENERAL_OPTIONS,
trim: true,
},
eventLocationGeneralOther: { type: String, required: false, trim: true },
eventLocationCity: {
type: String,
required: false,
enum: EVENT_LOCATION_CITY_OPTIONS,
trim: true,
},
eventLocationCityOther: { type: String, required: false, trim: true },
description: { type: String, required: true, trim: true },
majorFundraisingEvent: { type: Boolean, required: false },
eventLink: { type: String, required: false, trim: true },
organization: { type: String, required: true, trim: true },
publicContactEmail: { type: String, required: false, trim: true },
publicContactPhoneNumber: { type: String, required: false, trim: true },
submitterFirstName: { type: String, required: false, trim: true },
submitterLastName: { type: String, required: false, trim: true },
submitterEmail: { type: String, required: false, trim: true },
submitterPhoneNumber: { type: String, required: false, trim: true },
eventImage: { type: String, required: false, trim: true },
organizationIcon: { type: String, required: false, trim: true },
createdByUserId: { type: String, required: true },
eventStatus: { type: String, enum: Object.values(EventStatus), required: true, default: "pending" },
approvedDate: { type: Date, required: false },
rejectionMessage: { type: String, required: false },
contactName: { type: String, required: false },
contactEmail: { type: String, required: false },
},
{ timestamps: true },
);
EventSchema.index(
{ createdByUserId: 1, organization: 1, date: 1, eventName: 1, time: 1, location: 1 },
{ unique: true },
);
if (
models.Event &&
(!models.Event.schema.path("eventLink") ||
!models.Event.schema.path("locationLink") ||
!models.Event.schema.path("eventLocationGeneral") ||
!models.Event.schema.path("eventLocationCity") ||
models.Event.schema.path("locationType"))
) {
deleteModel("Event");
}
const Event = models.Event || model("Event", EventSchema, "events");
export default Event;