-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathmodel.js
More file actions
136 lines (127 loc) · 3.55 KB
/
model.js
File metadata and controls
136 lines (127 loc) · 3.55 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
const mongoose = require('mongoose')
const _ = require('lodash')
const { ReviewingMethods } = require('@hackjunction/shared')
const CloudinaryImageSchema = require('@hackjunction/shared/schemas/CloudinaryImage')
const AchievementSchema = require('../../common/schemas/Achievement')
const GavelController = require('../reviewing/gavel/controller')
const WebhookService = require('../../common/services/webhook')
const CustomAnswer = require('@hackjunction/shared/schemas/CustomAnswer')
// const ProjectDefaultFields = require('@hackjunction/shared/constants/project-default-fields')
// const AnswersSchema = require('@hackjunction/shared/schemas/Answers')
const ProjectSchema = new mongoose.Schema({
event: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Event',
required: true,
},
team: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Team',
required: true,
},
name: {
type: String,
required: true,
},
punchline: {
type: String,
// required: true,
},
description: {
type: String,
// required: true,
},
technologies: [String],
source: {
type: String,
},
sourcePublic: {
type: Boolean,
// required: true,
default: true,
},
demo: {
type: String,
},
images: {
type: [CloudinaryImageSchema.mongoose],
},
challenges: {
type: [String],
},
track: {
type: String,
},
location: {
type: String,
},
hiddenMembers: {
type: [String],
default: [],
},
video: {
type: String,
},
status: {
type: String,
},
achievements: [AchievementSchema],
submissionFormAnswers: {
type: [CustomAnswer.mongoose],
},
})
ProjectSchema.set('timestamps', true)
/* Only allow a single project per team per event */
/* ProjectSchema.index(
{
event: 1,
team: 1,
},
{
unique: true,
}
) */
/* We'll commonly query projects by track and event, so create a compound index for that */
ProjectSchema.index({
track: 1,
event: 1,
})
ProjectSchema.methods.getPreview = function () {
return _.omit(this, ['description'])
}
ProjectSchema.methods.getExportData = function () {
return {
name: this.name || '',
punchline: this.punchline || '',
description: this.description || '',
technologies: this.technologies.join(', ') || '',
source: this.source || '',
demo: this.demo || '',
images: this.images.map(image => image.url).join(', ') || '',
challenges: this.challenges.join(', ') || '',
track: this.track || '',
location: this.location || '',
status: this.status || '',
video: this.video || '',
}
}
ProjectSchema.post('save', async function (doc, next) {
const event = await mongoose.model('Event').findById(this.event)
switch (event.reviewMethod) {
/** If using Gavel peer review, make sure a GavelProject exists for each project, and is updated accordingly,
updated to GavelProject only if it has status 'final'
*/
case ReviewingMethods.gavelPeerReview.id: {
GavelController.ensureGavelProject(doc)
console.log('saved as gavel project')
break
}
default: {
/** By default, no action needed */
}
}
WebhookService.triggerWebhooks('Project', 'save', doc, this.event)
next()
})
const Project = mongoose.model('Project', ProjectSchema)
module.exports = Project