Я не могу заставить свой запрос работать при запуске его в Firebase Functions.Он отлично работает на стороне клиента, но не в функциях.Интересно, есть ли способ заставить его работать и с Admin SDK?Я делаю что-то ужасно неправильно с моим запросом?
Параметры:
searchQuery = {
start:
"[native Date Fri Feb 08 2019 00:00:00 GMT+0200 (Itä-Euroopan normaaliaika)]",
end:
"[native Date Fri Feb 08 2019 23:59:59 GMT+0200 (Itä-Euroopan normaaliaika)]",
cafeIds: ["LI088001"],
textSearch: "",
time: { time: "00-24", label: "Kokopäivä" }
}
sort = {
"column": "created",
"value": "asc"
}
Запрос:
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()
При помещении этого кода в функции, написанные на машинописном тексте, я получаю следующие ошибки:
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')