Merge pull request #3495 from overleaf/ae-prettier-2
Upgrade Prettier to v2 GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
@@ -22,58 +22,63 @@ const Modules = require('../../infrastructure/Modules')
|
||||
module.exports = ContactsController = {
|
||||
getContacts(req, res, next) {
|
||||
const user_id = AuthenticationController.getLoggedInUserId(req)
|
||||
return ContactManager.getContactIds(user_id, { limit: 50 }, function(
|
||||
error,
|
||||
contact_ids
|
||||
) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
return UserGetter.getUsers(
|
||||
contact_ids,
|
||||
{
|
||||
email: 1,
|
||||
first_name: 1,
|
||||
last_name: 1,
|
||||
holdingAccount: 1
|
||||
},
|
||||
function(error, contacts) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
|
||||
// UserGetter.getUsers may not preserve order so put them back in order
|
||||
const positions = {}
|
||||
for (let i = 0; i < contact_ids.length; i++) {
|
||||
const contact_id = contact_ids[i]
|
||||
positions[contact_id] = i
|
||||
}
|
||||
contacts.sort(
|
||||
(a, b) =>
|
||||
positions[a._id != null ? a._id.toString() : undefined] -
|
||||
positions[b._id != null ? b._id.toString() : undefined]
|
||||
)
|
||||
|
||||
// Don't count holding accounts to discourage users from repeating mistakes (mistyped or wrong emails, etc)
|
||||
contacts = contacts.filter(c => !c.holdingAccount)
|
||||
|
||||
contacts = contacts.map(ContactsController._formatContact)
|
||||
|
||||
return Modules.hooks.fire('getContacts', user_id, contacts, function(
|
||||
error,
|
||||
additional_contacts
|
||||
) {
|
||||
return ContactManager.getContactIds(
|
||||
user_id,
|
||||
{ limit: 50 },
|
||||
function (error, contact_ids) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
return UserGetter.getUsers(
|
||||
contact_ids,
|
||||
{
|
||||
email: 1,
|
||||
first_name: 1,
|
||||
last_name: 1,
|
||||
holdingAccount: 1
|
||||
},
|
||||
function (error, contacts) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
contacts = contacts.concat(...Array.from(additional_contacts || []))
|
||||
return res.send({
|
||||
contacts
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
// UserGetter.getUsers may not preserve order so put them back in order
|
||||
const positions = {}
|
||||
for (let i = 0; i < contact_ids.length; i++) {
|
||||
const contact_id = contact_ids[i]
|
||||
positions[contact_id] = i
|
||||
}
|
||||
contacts.sort(
|
||||
(a, b) =>
|
||||
positions[a._id != null ? a._id.toString() : undefined] -
|
||||
positions[b._id != null ? b._id.toString() : undefined]
|
||||
)
|
||||
|
||||
// Don't count holding accounts to discourage users from repeating mistakes (mistyped or wrong emails, etc)
|
||||
contacts = contacts.filter(c => !c.holdingAccount)
|
||||
|
||||
contacts = contacts.map(ContactsController._formatContact)
|
||||
|
||||
return Modules.hooks.fire(
|
||||
'getContacts',
|
||||
user_id,
|
||||
contacts,
|
||||
function (error, additional_contacts) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
contacts = contacts.concat(
|
||||
...Array.from(additional_contacts || [])
|
||||
)
|
||||
return res.send({
|
||||
contacts
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
_formatContact(contact) {
|
||||
|
||||
@@ -23,7 +23,7 @@ module.exports = ContactManager = {
|
||||
options = { limits: 50 }
|
||||
}
|
||||
if (callback == null) {
|
||||
callback = function(error, contacts) {}
|
||||
callback = function (error, contacts) {}
|
||||
}
|
||||
const url = `${settings.apis.contacts.url}/user/${user_id}/contacts`
|
||||
return request.get(
|
||||
@@ -33,7 +33,7 @@ module.exports = ContactManager = {
|
||||
json: true,
|
||||
jar: false
|
||||
},
|
||||
function(error, res, data) {
|
||||
function (error, res, data) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
@@ -55,7 +55,7 @@ module.exports = ContactManager = {
|
||||
|
||||
addContact(user_id, contact_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error) {}
|
||||
callback = function (error) {}
|
||||
}
|
||||
const url = `${settings.apis.contacts.url}/user/${user_id}/contacts`
|
||||
return request.post(
|
||||
@@ -66,7 +66,7 @@ module.exports = ContactManager = {
|
||||
},
|
||||
jar: false
|
||||
},
|
||||
function(error, res, data) {
|
||||
function (error, res, data) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user