-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Easy Dev] Add a script to upload a partner from partners.json to fir…
…estore.
- Loading branch information
Showing
5 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"esModuleInterop": true, | ||
"lib": ["es2019"], | ||
"module": "commonjs", | ||
"noImplicitReturns": true, | ||
"noUnusedLocals": true, | ||
"outDir": "lib", | ||
"resolveJsonModule": true, | ||
"sourceMap": true, | ||
"strict": true, | ||
"target": "es2017" | ||
}, | ||
"compileOnSave": true, | ||
"include": [ | ||
"src" | ||
"src", | ||
"upload_parters.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* A script to upload a partner info to firestore. | ||
* | ||
* First, get a service account key in https://console.firebase.google.com/u/0/project/ma-voie/settings/serviceaccounts/adminsdk | ||
* and save it as credentials/serviceAccountKey.json | ||
* | ||
* Then run `npm run upload -- partner-id` | ||
* | ||
* This will upload the partner with the given ID as a document in firestore in production. | ||
* The newly created document has its partnerId as ID. | ||
* | ||
* To upload to demo or dev, simply use a relevant serviceAccountKey.json. | ||
*/ | ||
/* eslint-disable no-console */ | ||
import admin from 'firebase-admin' | ||
|
||
import partners from './partners.json' | ||
|
||
const partnerId = process.argv[2] | ||
console.log(`Starting to upload ${partnerId}...`) | ||
if (!partnerId) { | ||
console.error('You must specify a partner to upload') | ||
// eslint-disable-next-line unicorn/no-process-exit | ||
process.exit(1) | ||
} | ||
|
||
admin.initializeApp({ | ||
credential: admin.credential.applicationDefault(), | ||
}) | ||
|
||
console.log('App initialized'); | ||
|
||
(async (): Promise<void> => { | ||
const partner = partners.find(({partnerId: pId}: {partnerId: string}) => pId === partnerId) | ||
if (!partner) { | ||
console.error( | ||
`Could not find a partner with ID ${partnerId}. Choose one from`, | ||
partners.map(({partnerId}) => partnerId), | ||
) | ||
return | ||
} | ||
const db = admin.firestore() | ||
try { | ||
await db.collection('staticPartners').doc(partnerId).set(partner) | ||
console.log(`Partner ${partnerId} has been uploaded to firestore.`) | ||
} catch (error) { | ||
console.error(`An error occurred while uploading partner ${partnerId}`, error) | ||
} | ||
})() |