-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from alexwohlbruck/develop
Develop
- Loading branch information
Showing
7 changed files
with
182 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* This file contains global settings for the app configuration | ||
* Use environment variables for secrets and keys!! | ||
* This file is publicly visible (hello if you're reading this :D ) | ||
*/ | ||
|
||
const unsubscribableDates = [ | ||
{ | ||
start: new Date("August 8, 2017 16:20:00 EDT"), | ||
end: new Date("August 9, 2017 16:20:00 EDT") | ||
} | ||
], | ||
|
||
isBetweenDates = function(target, min, max) { | ||
return (min < target) && (target < max); | ||
}; | ||
|
||
module.exports = { | ||
allowUsersToUnsubscribe: function() { | ||
const now = new Date(); | ||
|
||
return unsubscribableDates | ||
.map(range => { | ||
return isBetweenDates(now, range.start, range.end); | ||
}) | ||
.reduce((sum, value) => sum || value); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,38 @@ | ||
var mongoose = require('mongoose'); | ||
var Schema = mongoose.Schema; | ||
var strings = require.main.require('./app/config/strings'); | ||
const mongoose = require('mongoose'); | ||
const Schema = mongoose.Schema; | ||
const strings = require.main.require('./app/config/strings'); | ||
const mongooseDelete = require('mongoose-delete'); | ||
|
||
var RecipientSchema = new Schema({ | ||
const RecipientSchema = new Schema({ | ||
name: String, | ||
number: {type: String, required: true, validate: validateNumber, unique: true}, | ||
number: { | ||
type: String, | ||
required: true, | ||
unique: true, | ||
validate: [ | ||
function phoneNumber(string) { | ||
return string.length == 10; | ||
} | ||
] | ||
}, | ||
addedBy: {type: Schema.Types.ObjectId, ref: 'User'} | ||
}, { | ||
timestamps: true | ||
}); | ||
|
||
function validateNumber(string) { | ||
return string.length == 10; | ||
} | ||
|
||
RecipientSchema.path('number').validate(function(number, done) { | ||
this.model('Recipient').count({number: number}, function(err, count) { | ||
if (err) return done(err); | ||
done(!count); | ||
}); | ||
}, strings.recipient.exists); | ||
|
||
var Recipient = mongoose.model('Recipient', RecipientSchema); | ||
/** | ||
* Soft delete implementation | ||
* https://github.com/dsanel/mongoose-delete | ||
*/ | ||
RecipientSchema.plugin(mongooseDelete, {overrideMethods: true}); | ||
|
||
const Recipient = mongoose.model('Recipient', RecipientSchema); | ||
|
||
module.exports = Recipient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.