-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.js
24 lines (20 loc) · 858 Bytes
/
sync.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import 'firebase/database';
import 'firebase/storage';
import admin from 'firebase-admin';
import axios from 'axios';
var serviceAccount = require('../admin-sdk.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://naanii.firebaseio.com"
});
const db = admin.firestore();
axios.get('https://jsonplaceholder.typicode.com/users').then((res) => {
res.data.map(async ({ name, username, email, phone, website, company }) => {
await db.collection('users').doc(cur.id + '').set({ name, username, email, phone, website, company })
})
})
axios.get('https://jsonplaceholder.typicode.com/posts').then((res) => {
res.data.map(async ({ title, body, id, userId }) => {
await db.collection('users').doc(userId + '').collection('user-posts').doc(id + '').set({ title, body })
})
})