Removed .js from all imports to smooth ts migration
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import { getUserTier } from '/imports/api/users/patreon/tiers.js';
|
||||
import { getUserTier } from '/imports/api/users/patreon/tiers';
|
||||
|
||||
let Invites= new Mongo.Collection('invites');
|
||||
let Invites = new Mongo.Collection('invites');
|
||||
|
||||
let InviteSchema = new SimpleSchema({
|
||||
inviter: {
|
||||
@@ -34,13 +34,13 @@ let InviteSchema = new SimpleSchema({
|
||||
},
|
||||
});
|
||||
|
||||
if (Meteor.isServer){
|
||||
Accounts.onLogin(function({user}){
|
||||
if (Meteor.isServer) {
|
||||
Accounts.onLogin(function ({ user }) {
|
||||
alignInvitesWithPatreonTier(user);
|
||||
});
|
||||
}
|
||||
|
||||
function alignInvitesWithPatreonTier(user){
|
||||
function alignInvitesWithPatreonTier(user) {
|
||||
const tier = getUserTier(user);
|
||||
let availableInvites = tier.invites;
|
||||
let currentlyFundedInvites = [];
|
||||
@@ -48,7 +48,7 @@ function alignInvitesWithPatreonTier(user){
|
||||
Invites.find({
|
||||
inviter: user._id
|
||||
}).forEach(invite => {
|
||||
if (invite.isFunded){
|
||||
if (invite.isFunded) {
|
||||
currentlyFundedInvites.push(invite);
|
||||
} else {
|
||||
currenltyUnfundedInvites.push(invite);
|
||||
@@ -63,23 +63,23 @@ function alignInvitesWithPatreonTier(user){
|
||||
currenltyUnfundedInvites.sort((a, b) => b.dateConfirmed - a.dateConfirmed);
|
||||
|
||||
// Defund or delete excess invites
|
||||
while (currentlyFundedInvites.length > availableInvites){
|
||||
while (currentlyFundedInvites.length > availableInvites) {
|
||||
let inviteToDefund = currentlyFundedInvites.pop();
|
||||
if (inviteToDefund.invitee){
|
||||
Invites.update(inviteToDefund._id, {$set: {isFunded: false}});
|
||||
if (inviteToDefund.invitee) {
|
||||
Invites.update(inviteToDefund._id, { $set: { isFunded: false } });
|
||||
} else {
|
||||
Invites.remove(inviteToDefund._id);
|
||||
}
|
||||
}
|
||||
// Fund unfunded invites or insert new ones
|
||||
while (currentlyFundedInvites.length < availableInvites){
|
||||
if (currenltyUnfundedInvites.length){
|
||||
while (currentlyFundedInvites.length < availableInvites) {
|
||||
if (currenltyUnfundedInvites.length) {
|
||||
let inviteToFund = currenltyUnfundedInvites.pop();
|
||||
currentlyFundedInvites.push(inviteToFund);
|
||||
Invites.update(inviteToFund._id, {$set: {isFunded: true}});
|
||||
Invites.update(inviteToFund._id, { $set: { isFunded: true } });
|
||||
} else {
|
||||
let inviteId = Invites.insert({inviter: user._id, isFunded: true});
|
||||
currentlyFundedInvites.push({_id: inviteId});
|
||||
let inviteId = Invites.insert({ inviter: user._id, isFunded: true });
|
||||
currentlyFundedInvites.push({ _id: inviteId });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,17 +97,17 @@ const getInviteToken = new ValidatedMethod({
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({inviteId}) {
|
||||
run({ inviteId }) {
|
||||
let invite = Invites.findOne(inviteId);
|
||||
if (this.userId !== invite.inviter) {
|
||||
throw new Meteor.Error('Invites.methods.getToken.denied',
|
||||
'You need to be the inviter of the invite to create a token');
|
||||
'You need to be the inviter of the invite to create a token');
|
||||
}
|
||||
if (invite.inviteToken){
|
||||
if (invite.inviteToken) {
|
||||
return invite.inviteToken;
|
||||
} else {
|
||||
let inviteToken = Random.id(5);
|
||||
Invites.update(inviteId, {$set: {inviteToken}})
|
||||
Invites.update(inviteId, { $set: { inviteToken } })
|
||||
return inviteToken;
|
||||
}
|
||||
},
|
||||
@@ -125,32 +125,32 @@ const acceptInviteToken = new ValidatedMethod({
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({inviteToken}) {
|
||||
run({ inviteToken }) {
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('Invites.methods.acceptToken.denied',
|
||||
'You need to be the logged in to accept a token');
|
||||
'You need to be the logged in to accept a token');
|
||||
}
|
||||
if (Meteor.isClient) return;
|
||||
let invite = Invites.findOne({inviteToken});
|
||||
if (!invite){
|
||||
let invite = Invites.findOne({ inviteToken });
|
||||
if (!invite) {
|
||||
throw new Meteor.Error('Invites.methods.acceptToken.notFound',
|
||||
'No invite could be found for this link, maybe it has already been claimed');
|
||||
'No invite could be found for this link, maybe it has already been claimed');
|
||||
}
|
||||
// If the invitee is already filled, fix unexpected case by deleting the token
|
||||
if (invite.invitee){
|
||||
if (invite.invitee) {
|
||||
Invites.update(invite._id, {
|
||||
$unset: {inviteToken: 1}
|
||||
$unset: { inviteToken: 1 }
|
||||
});
|
||||
throw new Meteor.Error('Invites.methods.acceptToken.alreadyAccepted',
|
||||
'This invite has already been claimed');
|
||||
'This invite has already been claimed');
|
||||
}
|
||||
if (this.userId === invite.inviter){
|
||||
if (this.userId === invite.inviter) {
|
||||
throw new Meteor.Error('Invites.methods.acceptToken.ownToken',
|
||||
'You can\'t accept your own invite');
|
||||
'You can\'t accept your own invite');
|
||||
}
|
||||
Invites.update(invite._id, {
|
||||
$set: {invitee: this.userId},
|
||||
$unset: {inviteToken: 1},
|
||||
$set: { invitee: this.userId },
|
||||
$unset: { inviteToken: 1 },
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -168,28 +168,28 @@ const revokeInvite = new ValidatedMethod({
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({inviteId}) {
|
||||
run({ inviteId }) {
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('Invites.methods.revokeInvite.denied',
|
||||
'You need to be the logged in to revoke a token');
|
||||
'You need to be the logged in to revoke a token');
|
||||
}
|
||||
if (Meteor.isClient) return;
|
||||
let invite = Invites.findOne(inviteId);
|
||||
if (!invite){
|
||||
if (!invite) {
|
||||
throw new Meteor.Error('Invites.methods.revokeInvite.notFound',
|
||||
'No invite could be found for this id');
|
||||
'No invite could be found for this id');
|
||||
}
|
||||
if (this.userId !== invite.inviter) {
|
||||
throw new Meteor.Error('Invites.methods.revokeInvite.denied',
|
||||
'You are not the owner of this invite');
|
||||
'You are not the owner of this invite');
|
||||
}
|
||||
|
||||
// If the invitee is empty, the token has already been revoked
|
||||
if (!invite.invitee){
|
||||
if (!invite.invitee) {
|
||||
return;
|
||||
}
|
||||
Invites.update(invite._id, {
|
||||
$unset: {invitee: 1, dateConfirmed: 1},
|
||||
$unset: { invitee: 1, dateConfirmed: 1 },
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import Libraries from '/imports/api/library/Libraries.js';
|
||||
import LibraryCollections from '/imports/api/library/LibraryCollections.js';
|
||||
import '/imports/api/users/methods/deleteMyAccount.js';
|
||||
import '/imports/api/users/methods/addEmail.js';
|
||||
import '/imports/api/users/methods/removeEmail.js';
|
||||
import '/imports/api/users/methods/updateFileStorageUsed.js';
|
||||
import Libraries from '/imports/api/library/Libraries';
|
||||
import LibraryCollections from '/imports/api/library/LibraryCollections';
|
||||
import '/imports/api/users/methods/deleteMyAccount';
|
||||
import '/imports/api/users/methods/addEmail';
|
||||
import '/imports/api/users/methods/removeEmail';
|
||||
import '/imports/api/users/methods/updateFileStorageUsed';
|
||||
import { some } from 'lodash';
|
||||
const defaultLibraries = process.env.DEFAULT_LIBRARIES && process.env.DEFAULT_LIBRARIES.split(',') || [];
|
||||
const defaultLibraryCollections = process.env.DEFAULT_LIBRARY_COLLECTIONS && process.env.DEFAULT_LIBRARY_COLLECTIONS.split(',') || [];
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import Libraries, { removeLibaryWork } from '/imports/api/library/Libraries.js';
|
||||
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||
import { removeCreatureWork } from '/imports/api/creature/creatures/methods/removeCreature.js';
|
||||
import Libraries, { removeLibaryWork } from '/imports/api/library/Libraries';
|
||||
import Creatures from '/imports/api/creature/creatures/Creatures';
|
||||
import { removeCreatureWork } from '/imports/api/creature/creatures/methods/removeCreature';
|
||||
|
||||
Meteor.users.deleteMyAccount = new ValidatedMethod({
|
||||
name: 'users.deleteMyAccount',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import ArchiveCreatureFiles from '/imports/api/creature/archive/ArchiveCreatureFiles.js';
|
||||
import UserImages from '/imports/api/files/UserImages.js';
|
||||
import ArchiveCreatureFiles from '/imports/api/creature/archive/ArchiveCreatureFiles';
|
||||
import UserImages from '/imports/api/files/UserImages';
|
||||
const fileCollections = [ArchiveCreatureFiles, UserImages];
|
||||
|
||||
const updateFileStorageUsed = new ValidatedMethod({
|
||||
@@ -29,7 +29,7 @@ export default updateFileStorageUsed;
|
||||
export function updateFileStorageUsedWork(userId) {
|
||||
if (!userId) {
|
||||
throw new Meteor.Error('idRequired',
|
||||
'No user ID was provided to update file storage used')
|
||||
'No user ID was provided to update file storage used')
|
||||
}
|
||||
|
||||
let sum = 0;
|
||||
@@ -51,7 +51,7 @@ export function incrementFileStorageUsed(userId, amount) {
|
||||
throw new Meteor.Error('idRequired',
|
||||
'No user ID was provided to update file storage used')
|
||||
}
|
||||
|
||||
|
||||
const user = Meteor.users.findOne(userId);
|
||||
if (!user) {
|
||||
throw new Meteor.Error('noUser', 'User not found');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { findLast } from 'lodash';
|
||||
import getEntitledCents from '/imports/api/users/patreon/getEntitledCents.js';
|
||||
import Invites from '/imports/api/users/Invites.js';
|
||||
import getEntitledCents from '/imports/api/users/patreon/getEntitledCents';
|
||||
import Invites from '/imports/api/users/Invites';
|
||||
const patreonDisabled = !!Meteor.settings?.public?.disablePatreon;
|
||||
|
||||
const TIERS = Object.freeze([
|
||||
@@ -80,14 +80,14 @@ const PATREON_DISABLED_TIER = Object.freeze({
|
||||
paidBenefits: true,
|
||||
});
|
||||
|
||||
export function getTierByEntitledCents(entitledCents = 0){
|
||||
export function getTierByEntitledCents(entitledCents = 0) {
|
||||
if (patreonDisabled) return PATREON_DISABLED_TIER;
|
||||
return findLast(TIERS, tier => entitledCents >= tier.minimumEntitledCents);
|
||||
}
|
||||
|
||||
export function getUserTier(user){
|
||||
export function getUserTier(user) {
|
||||
if (!user) throw 'user must be provided';
|
||||
if (typeof user === 'string'){
|
||||
if (typeof user === 'string') {
|
||||
user = Meteor.users.findOne(user, {
|
||||
fields: {
|
||||
'services.patreon': 1,
|
||||
@@ -99,19 +99,19 @@ export function getUserTier(user){
|
||||
const entitledCents = getEntitledCents(user);
|
||||
const tier = getTierByEntitledCents(entitledCents);
|
||||
if (tier.paidBenefits) return tier;
|
||||
let invite = Invites.findOne({invitee: user._id, isFunded: true});
|
||||
if (invite){
|
||||
let invite = Invites.findOne({ invitee: user._id, isFunded: true });
|
||||
if (invite) {
|
||||
return GUEST_TIER;
|
||||
} else {
|
||||
return tier;
|
||||
}
|
||||
}
|
||||
|
||||
export function assertUserHasPaidBenefits(user){
|
||||
export function assertUserHasPaidBenefits(user) {
|
||||
let tier = getUserTier(user);
|
||||
if (!tier.paidBenefits){
|
||||
if (!tier.paidBenefits) {
|
||||
throw new Meteor.Error('no paid benefits',
|
||||
`The ${tier.name} tier does not have the required benefits`);
|
||||
`The ${tier.name} tier does not have the required benefits`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import updatePatreonDetails from '/imports/api/users/patreon/updatePatreonDetails.js';
|
||||
import updatePatreonDetails from '/imports/api/users/patreon/updatePatreonDetails';
|
||||
const ONE_DAY = 24 * 60 * 60 * 1000;
|
||||
|
||||
Accounts.onLogin(({user}) => {
|
||||
Accounts.onLogin(({ user }) => {
|
||||
let patreon = user.services && user.services.patreon;
|
||||
if (patreon){
|
||||
if (patreon) {
|
||||
const timeSinceIdentityUpdate = new Date() - patreon.lastUpdatedIdentity;
|
||||
if (timeSinceIdentityUpdate > ONE_DAY){
|
||||
if (timeSinceIdentityUpdate > ONE_DAY) {
|
||||
updatePatreonDetails(user);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user