functions working nicely as index created

This commit is contained in:
Arjun Patel
2022-02-01 13:52:38 -08:00
parent c86d8566ac
commit 1239014c15
4 changed files with 10 additions and 9 deletions
+1
View File
@@ -4,6 +4,7 @@
"indexes": "firestore.indexes.json"
},
"functions": {
"runtime": "nodejs16",
"predeploy": [
"npm --prefix functions run build",
"npm --prefix \"$RESOURCE_DIR\" run lint",
@@ -1,9 +1,9 @@
{
"env": {
"algolia": {
"ALGOLIA_APP_ID": "1RAMCAU1FW",
"ALGOLIA_API_KEY": "c44a7dda47bfb69527b061b7b5994d56",
"ALGOLIA_USERS_INDEX_NAME": "test_USERS"
"ALGOLIA_USERS_INDEX_NAME": "test_USERS",
"ALGOLIA_APP_ID": "1RAMCAU1FW"
}
}
}
+4 -5
View File
@@ -3,10 +3,10 @@
"version": "1.0.0",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "npm run lint && tsc",
"serve": "npm run build && firebase functions:config:get > .runtimeconfig.json && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"build": "yarn lint && tsc",
"serve": "yarn build && firebase functions:config:get > .runtimeconfig.json && firebase emulators:start --only functions",
"shell": "yarn build && firebase functions:shell",
"start": "yarn shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"hotReload": "tsc --watch",
@@ -15,7 +15,6 @@
},
"main": "lib/index.js",
"dependencies": {
"@nirvana/common": "*",
"@sendgrid/mail": "^7.6.0",
"@types/algoliasearch": "^4.0.0",
"agora-access-token": "^2.0.4",
+3 -2
View File
@@ -1,10 +1,11 @@
import * as functions from "firebase-functions";
const config = functions.config().env;
const config = functions.config().env.algolia;
import algoliasearch from "algoliasearch";
const client = algoliasearch(config.ALGOLIA_APP_ID, config.ALGOLIA_API_KEY);
// setting up indices
const USERS_INDEX_NAME: string = config.ALGOLIA_USERS_INDEX_NAME;
const usersIndex = client.initIndex(USERS_INDEX_NAME);
@@ -22,5 +23,5 @@ export const manageUserIndex = functions.firestore
}
// otherwise, just update the index with new user information
return usersIndex.saveObject({ objectId, ...document });
return usersIndex.saveObject({ objectID: objectId, ...document });
});