mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-06 04:31:50 +02:00
First Commit
This commit is contained in:
commit
2630cc237a
527 changed files with 104273 additions and 0 deletions
59
api/event/event.model.js
Normal file
59
api/event/event.model.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
var mongoose = require('mongoose');
|
||||
var Schema = mongoose.Schema;
|
||||
var debug = require('debug')('event.model');
|
||||
var ShortId = require('mongoose-shortid');
|
||||
|
||||
var EventSchema = new Schema({
|
||||
_id : ShortId,
|
||||
description : String,
|
||||
creator : {
|
||||
name : String,
|
||||
email : String
|
||||
},
|
||||
title : String,
|
||||
dates : [Date],
|
||||
emails : [String],
|
||||
participants : [{
|
||||
id : Schema.Types.ObjectId,
|
||||
name : String,
|
||||
dates : [Boolean]
|
||||
}],
|
||||
comments : [{
|
||||
id : Schema.Types.ObjectId,
|
||||
author : String,
|
||||
comment : String,
|
||||
}]
|
||||
});
|
||||
|
||||
var model = mongoose.model('Event', EventSchema);
|
||||
|
||||
model.schema
|
||||
.path('title')
|
||||
.required('You need to give your event a title');
|
||||
model.schema
|
||||
.path('creator.name')
|
||||
.required('You need to type in your name')
|
||||
model.schema
|
||||
.path('creator.email')
|
||||
.required('You need to type in your email')
|
||||
.validate(function(email) {
|
||||
debug("email: " + email);
|
||||
var emailRegex = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
|
||||
return emailRegex.test(email);
|
||||
}, 'You need to type in a valid email')
|
||||
model.schema
|
||||
.path('dates')
|
||||
.validate(function(dates){
|
||||
return dates.length
|
||||
}, 'You didn\'t select any dates');
|
||||
model.schema
|
||||
.path('participants')
|
||||
.validate(function(participants){
|
||||
for (var i = 0; i < participants.length; i++){
|
||||
if (!participants[i].name){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}, 'Participants must have a name')
|
||||
module.exports = model
|
Loading…
Add table
Add a link
Reference in a new issue