endpoint to index all users, but need to make sure I protect this route later
This commit is contained in:
@@ -17,5 +17,6 @@ exports.agoraToken = agoraToken;
|
|||||||
import { inviteUserToTeam } from "./notifications";
|
import { inviteUserToTeam } from "./notifications";
|
||||||
exports.inviteUserToTeam = inviteUserToTeam;
|
exports.inviteUserToTeam = inviteUserToTeam;
|
||||||
|
|
||||||
import { manageUserIndex } from "./search";
|
import { manageUserIndex, updateUsersIndexWithAllUsers } from "./search";
|
||||||
exports.manageUserIndex = manageUserIndex;
|
exports.manageUserIndex = manageUserIndex;
|
||||||
|
exports.updateUsersIndexWithAllUsers = updateUsersIndexWithAllUsers;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import * as functions from "firebase-functions";
|
import * as functions from "firebase-functions";
|
||||||
|
import * as admin from "firebase-admin";
|
||||||
const config = functions.config().env.algolia;
|
const config = functions.config().env.algolia;
|
||||||
|
|
||||||
import algoliasearch from "algoliasearch";
|
import algoliasearch from "algoliasearch";
|
||||||
@@ -25,3 +26,21 @@ export const manageUserIndex = functions.firestore
|
|||||||
// otherwise, just update the index with new user information
|
// otherwise, just update the index with new user information
|
||||||
return usersIndex.saveObject({ objectID: objectId, ...document });
|
return usersIndex.saveObject({ objectID: objectId, ...document });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: protect this endpoint to avoid infiltratros if they know the endpoint name
|
||||||
|
export const updateUsersIndexWithAllUsers = functions.https.onRequest(
|
||||||
|
async (request, response) => {
|
||||||
|
const snapshot = await admin.firestore().collection("users").get();
|
||||||
|
|
||||||
|
var users: {}[] = [];
|
||||||
|
|
||||||
|
snapshot.forEach((doc) => {
|
||||||
|
const currUser = doc.data();
|
||||||
|
users.push({ objectID: doc.id, ...currUser });
|
||||||
|
});
|
||||||
|
|
||||||
|
await usersIndex.saveObjects(users);
|
||||||
|
|
||||||
|
response.send("Completed index all users!");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user