Skip to content

Commit

Permalink
chore: start export product cron
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusgnreis committed Jan 18, 2024
1 parent 73b06bb commit bdad36f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions functions/lib/integration/export-product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const auth = require('./create-auth')
const { getFirestore, Timestamp } = require('firebase-admin/firestore')

const firestoreColl = 'products_to_add'
module.exports = async () => {

let documentRef, storeId, appData, store, result
if (firestoreColl) {
const db = getFirestore()
const d = new Date(new Date().getTime() - 9000)
const documentSnapshot = await db.collection(firestoreColl)
.where('queuedAt', '<=', d)
.orderBy('queuedAt')
.limit(1)
.get()
const info = documentSnapshot.docs && documentSnapshot.docs[0] && documentSnapshot.docs[0].data()
storeId = info.storeId
appData = info.configObj
store = info.store
result = info.result
documentRef = require('firebase-admin')
.firestore()
.doc(`${firestoreColl}/${storeId}`)
}
}

0 comments on commit bdad36f

Please sign in to comment.