mirror of
https://bitbucket.org/tagfer_team/tagfer-server.git
synced 2025-12-25 03:37:38 +00:00
Suggest random contacts
This commit is contained in:
parent
4248e2e870
commit
b4b82d958c
@ -58,6 +58,6 @@
|
||||
"verificationTTL": 300000,
|
||||
"verificationTTLClear": 1800000
|
||||
},
|
||||
"defaultProfileName": "Business Profile"
|
||||
|
||||
"defaultProfileName": "Business Profile",
|
||||
"suggestedUsersCount": 20
|
||||
}
|
||||
@ -10,6 +10,7 @@ module.exports = {
|
||||
AUTH_PHONE_NOT_CACHED: 'auth/phone-number-not-cached',
|
||||
AUTH_VERIFICATION_CODE_MISMATCH: 'auth/phone-verification-code-mismatch',
|
||||
AUTH_INVALID_SESSION_ID: 'auth/invalid-session-id',
|
||||
AUTH_INVALID_PAGE_TOKEN: 'auth/invalid-page-token',
|
||||
AUTH_UNAUTHORIZED_ACCESS: 'auth/unauthorized-access-into-api',
|
||||
AUTH_UNABLE_TO_EXTRACT_SESSION_ID_FROM_AUTH_HEADER: 'auth/unable-to-extract-session-id-from-auth-header',
|
||||
AUTH_TWITTER_REQUEST_TOKEN_FAILURE: 'auth/twitter-request-token-failure',
|
||||
|
||||
@ -19,7 +19,8 @@ function router(app) {
|
||||
app.post('/auth/passwordReset', AuthHandlers.sendPasswordResetEmail);
|
||||
|
||||
// Users Endpoints
|
||||
app.post('/users/by/phone', UserHandlers.findNetworkByPhone);
|
||||
app.post('/users/by/phone', UserHandlers.findUsersByPhone);
|
||||
app.get('/users/suggest', UserHandlers.suggestUsers);
|
||||
|
||||
// Profile Endpoints
|
||||
app.post('/profiles/:profileNumber', ProfileHandlers.updateUserProfile);
|
||||
|
||||
@ -34,6 +34,18 @@ async function filterContactsIntoBatches(contacts) {
|
||||
return {inNetworkBatch, outNetworkBatch, failedBatch};
|
||||
}
|
||||
|
||||
var pageToken = undefined;
|
||||
/**
|
||||
* Returns a list of N users. Used to suggest contacts.
|
||||
* @param {Number} N is the number of contacts you want to get
|
||||
*/
|
||||
function getNextNUsers(N) {
|
||||
return admin.auth().listUsers(N, pageToken).then( result => {
|
||||
pageToken = !result.pageToken? undefined : result.pageToken;
|
||||
return result.users.length === 0? getNextNUsers(N): result.users;
|
||||
}).catch( error => { throw { error: error.code }; });
|
||||
}
|
||||
|
||||
function _getContactStatus(phoneNumber) {
|
||||
return admin.auth().getUserByPhoneNumber(phoneNumber).then( user => {
|
||||
return {inNetwork: true, tagferId: user.uid};
|
||||
@ -43,5 +55,6 @@ function _getContactStatus(phoneNumber) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
filterContactsIntoBatches
|
||||
filterContactsIntoBatches,
|
||||
getNextNUsers
|
||||
};
|
||||
@ -2,6 +2,7 @@ const phone = require('phone');
|
||||
|
||||
const dao = require('./dao');
|
||||
const utils = require('../utils/utils');
|
||||
const appConfig = require('../../config/app.json');
|
||||
|
||||
/**
|
||||
* Endpoint: users/by/phone
|
||||
@ -10,7 +11,7 @@ const utils = require('../utils/utils');
|
||||
* @param {Object} req {contacts: Array<PhoneNumber>}
|
||||
* @param {Object} res {inNetworkBatch : Array<PhoneNumber>, outNetworkBatch: Array<PhoneNumber>, failedBatch: Array<PhoneNumber> }
|
||||
*/
|
||||
async function findNetworkByPhone(req, res) {
|
||||
async function findUsersByPhone(req, res) {
|
||||
const contacts = req.body.contacts;
|
||||
const verifier = () => contacts && Array.isArray(contacts);
|
||||
if (!utils.isAppSecretValid(req,res) || !utils.isBodyValid(verifier, res)) {
|
||||
@ -21,6 +22,25 @@ async function findNetworkByPhone(req, res) {
|
||||
res.json(batches);
|
||||
}
|
||||
|
||||
/**
|
||||
* Endpoint: users/suggest
|
||||
* @param {Object} req {}
|
||||
* @param {Object} res { users: UserObject }
|
||||
*
|
||||
* UserObject = { tagferId: String, displayName: String, photoURL: String }
|
||||
*/
|
||||
function suggestUsers(req, res) {
|
||||
if (!utils.isAppSecretValid(req,res)) {
|
||||
return;
|
||||
}
|
||||
|
||||
dao.getNextNUsers(appConfig.suggestedUsersCount).then( listUsers => {
|
||||
const users = listUsers.map( user => ({ tagferId: user.uid, displayName: user.displayName, photoURL: user.photoURL }) );
|
||||
res.json({ users });
|
||||
}).catch(error => res.json({ error }) );
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
findNetworkByPhone
|
||||
findUsersByPhone,
|
||||
suggestUsers
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user