Merge pull request #6278 from overleaf/ab-login-registration-cleanup

[web] Login/registration cleanup

GitOrigin-RevId: 02bb2fa04a504f42b7594def3cec03ab883c64f5
This commit is contained in:
Alexandre Bourdin 2022-04-06 14:33:08 +02:00 committed by Copybot
parent 5e9af2c15c
commit d0c4c8b24f

View file

@ -1,51 +1,63 @@
const OError = require('@overleaf/o-error') const OError = require('@overleaf/o-error')
const { User } = require('../../models/User') const { User } = require('../../models/User')
const FeaturesUpdater = require('../Subscription/FeaturesUpdater') const FeaturesUpdater = require('../Subscription/FeaturesUpdater')
const { promisify } = require('../../util/promises')
module.exports = { function allocate(
allocate(referalId, newUserId, referalSource, referalMedium, callback) { referalId,
if (callback == null) { newUserId,
callback = function () {} referalSource,
referalMedium,
callback
) {
if (callback == null) {
callback = function () {}
}
if (referalId == null) {
return callback(null)
}
const query = { referal_id: referalId }
return User.findOne(query, { _id: 1 }, function (error, user) {
if (error != null) {
return callback(error)
} }
if (referalId == null) { if (user == null || user._id == null) {
return callback(null) return callback(null)
} }
const query = { referal_id: referalId } if (referalSource === 'bonus') {
return User.findOne(query, { _id: 1 }, function (error, user) { User.updateOne(
if (error != null) { query,
return callback(error) {
} $push: {
if (user == null || user._id == null) { refered_users: newUserId,
return callback(null)
}
if (referalSource === 'bonus') {
User.updateOne(
query,
{
$push: {
refered_users: newUserId,
},
$inc: {
refered_user_count: 1,
},
}, },
{}, $inc: {
function (err) { refered_user_count: 1,
if (err != null) { },
OError.tag(err, 'something went wrong allocating referal', { },
referalId, {},
newUserId, function (err) {
}) if (err != null) {
return callback(err) OError.tag(err, 'something went wrong allocating referal', {
} referalId,
FeaturesUpdater.refreshFeatures(user._id, 'referral', callback) newUserId,
})
return callback(err)
} }
) FeaturesUpdater.refreshFeatures(user._id, 'referral', callback)
} else { }
callback() )
} } else {
}) callback()
}
})
}
module.exports = {
allocate,
promises: {
allocate: promisify(allocate),
}, },
} }