I am encountering difficulties with my query while running it in Firebase Functions. It functions perfectly on the client side, but fails to work in Functions. I am curious if there is a way to modify it to function with Admin SDK as well. Am I making any critical errors in my query?
Parameters:
searchQuery = {
start:
"[native Date Fri Feb 08 2019 00:00:00 GMT+0200 (Eastern European Standard Time)]",
end:
"[native Date Fri Feb 08 2019 23:59:59 GMT+0200 (Eastern European Standard Time)]",
cafeIds: ["LI088001"],
textSearch: "",
time: { time: "00-24", label: "Full day" }
}
sort = {
"column": "created",
"value": "asc"
}
Query:
let ref = firestoreDB.collection('events')
ref = ref.where('created', '>=', searchQuery.start).where('created', '<=', searchQuery.end)
for (const cafe of searchQuery.cafeIds) {
ref = ref.where('cafeId', '==', cafe)
}
ref = ref.where(`time.${searchQuery.time.time}`, '==', true)
if (searchQuery.textSearch !== '') {
ref = ref.where(
'products.',
'array-contains',
lowerCase(searchQuery.textSearch)
)
}
if (sort.field === 'created') {
ref = ref.orderBy('created', sort.value)
} else if (sort.field === 'productCount') {
ref = ref
.orderBy('created', 'asc')
.orderBy('productCount', sort.value)
} else if (sort.field === 'total') {
ref = ref
.orderBy('created', 'asc')
.orderBy('total', sort.value)
} else {
ref = ref.orderBy('created', 'asc').orderBy('eventId', 'asc')
}
const query = await ref.limit(10).get()
When I try to implement this exact code in TypeScript functions, I encounter the following errors:
src/storage/exportCsv.f.ts:25:5 - error TS2322: Type 'Query' is not assignable to type 'CollectionReference'.
Property 'id' is missing in type 'Query'.
25 ref = ref.where('created', '>=', searchQuery.start).where('created', '<=', searchQuery.end)
~~~
src/storage/exportCsv.f.ts:28:7 - error TS2322: Type 'Query' is not assignable to type 'CollectionReference'.
28 ref = ref.where('cafeId', '==', cafe)
~~~
src/storage/exportCsv.f.ts:31:5 - error TS2322: Type 'Query' is not assignable to type 'CollectionReference'.
31 ref = ref.where(`time.${searchQuery.time.time}`, '==', true)
~~~
src/storage/exportCsv.f.ts:34:7 - error TS2322: Type 'Query' is not assignable to type 'CollectionReference'.
34 ref = ref.where(
~~~
src/storage/exportCsv.f.ts:42:7 - error TS2322: Type 'Query' is not assignable to type 'CollectionReference'.
42 ref = ref.orderBy('created', sort.value)
~~~
src/storage/exportCsv.f.ts:44:7 - error TS2322: Type 'Query' is not assignable to type 'CollectionReference'.
44 ref = ref
~~~
src/storage/exportCsv.f.ts:48:7 - error TS2322: Type 'Query' is not assignable to type 'CollectionReference'.
48 ref = ref
~~~
src/storage/exportCsv.f.ts:52:7 - error TS2322: Type 'Query' is not assignable to type 'CollectionReference'.
52 ref = ref.orderBy('created', 'asc').orderBy('eventId', 'asc')