Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Create single function for approval checks and another for limit ch…
…ecks. - Refactor movie request logic Signed-off-by: Ricky Grassmuck <rigrassm@gmail.com>
- Loading branch information
1 parent
579883d
commit b343437
Showing
2 changed files
with
93 additions
and
107 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,59 @@ | ||
Meteor.methods({ | ||
// Pretty simple, pass a user and the request type and the function returns true if they need approval | ||
// and false if they don't | ||
'approvalCheck': function (user, requestType) { | ||
var settings = Settings.find({}).fetch() | ||
var movieApproval = settings.movieApproval | ||
var tvApproval = settings.tvApproval | ||
|
||
Label:if (requestType === 'movie') { | ||
if (!movieApproval) { | ||
{ | ||
return false | ||
} | ||
} else { | ||
{ | ||
break Label | ||
} | ||
} | ||
} else if (requestType === 'tv') { | ||
if (!tvApproval) { | ||
{ | ||
return false | ||
} | ||
} else { | ||
{ | ||
break Label | ||
} | ||
} | ||
} | ||
|
||
if (settings.plexAuthenticationENABLED) { | ||
return (Permissions.find({permUSER: user}).fetch()[0].permAPPROVAL) | ||
} else{ | ||
return false | ||
} | ||
}, | ||
|
||
'limitCheck': function (user, requestType) { | ||
var weeklyLimit = Settings.find({}).fetch()[0].movieWeeklyLimit | ||
var userUnlimited = Permissions.find({permUSER: user}).fetch()[0].permLIMIT | ||
if (Meteor.user() || userUnlimited || weeklyLimit) { | ||
return false | ||
} | ||
if (requestType === 'movie') { | ||
var userRequestTotal = Movies.find({ | ||
user: user, | ||
createdAt: {'$gte': Date.now() - 6.048e8} | ||
}).fetch().length | ||
} else if (requestType === 'tv') { | ||
userRequestTotal = TV.find({ | ||
user: user, | ||
createdAt: {'$gte': Date.now() - 6.048e8} | ||
}).fetch().length | ||
} else { | ||
userRequestTotal = 0 | ||
} | ||
return (userRequestTotal >= weeklyLimit) | ||
} | ||
}) |
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