mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
c14467b87a
GitOrigin-RevId: c5abb64729530baecbee0eb589eaed39faa2ac56
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
import logger from '@overleaf/logger'
|
|
import * as ContactManager from './ContactManager.js'
|
|
import { buildContactIds } from './contacts.js'
|
|
|
|
const CONTACT_LIMIT = 50
|
|
|
|
export function addContact(req, res, next) {
|
|
const { user_id: userId } = req.params
|
|
const { contact_id: contactId } = req.body
|
|
|
|
if (contactId == null || contactId === '') {
|
|
res.status(400).send('contact_id should be a non-blank string')
|
|
return
|
|
}
|
|
|
|
logger.debug({ user_id: userId, contact_id: contactId }, 'adding contact')
|
|
|
|
Promise.all([
|
|
ContactManager.touchContact(userId, contactId),
|
|
ContactManager.touchContact(contactId, userId),
|
|
])
|
|
.then(() => {
|
|
res.sendStatus(204)
|
|
})
|
|
.catch(error => {
|
|
next(error)
|
|
})
|
|
}
|
|
|
|
export function getContacts(req, res, next) {
|
|
const { user_id: userId } = req.params
|
|
const { limit } = req.query
|
|
|
|
const contactLimit =
|
|
limit == null ? CONTACT_LIMIT : Math.min(parseInt(limit, 10), CONTACT_LIMIT)
|
|
|
|
logger.debug({ user_id: userId }, 'getting contacts')
|
|
|
|
ContactManager.getContacts(userId)
|
|
.then(contacts => {
|
|
res.json({
|
|
contact_ids: buildContactIds(contacts, contactLimit),
|
|
})
|
|
})
|
|
.catch(error => {
|
|
next(error)
|
|
})
|
|
}
|