angular / angular/angularfire

Error passing queryconstraint in a function call

Đang mở
#3,253 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
7.8k
Fork
2.2k
Merge trung bình
22 giờ 28 phút
Pull request đã merge (30 ngày)
6

Mô tả

### Version info

**Angular:**
"@angular/core": "^14.0.2",
**Firebase:**
Firebase 9
**AngularFire:**
"^7.4.1"
"rxjs": "~7.4.0",
**Other (e.g. Ionic/Cordova, Node, browser, operating system):**

### How to reproduce these conditions

**Failing test unit, Stackblitz demonstrating the problem**

const constraints1 =[];
constraints1.push(where('read', '==', false));
constraints1.push(orderBy('createdAt', 'desc'));
constraints1.push(limit(1));
dataQuery = query(colRef, ...constraints1);

console.log on constraints1
Constraints1:::[{"fa":{"segments":["read"],"offset":0,"len":1},"da":"==","_a":false,"type":"where"},{"fa":{"segments":["createdAt"],"offset":0,"len":1},"wa":"desc","type":"orderBy"},{"type":"limit","ma":1,"ga":"F"}]

This works fine but passing these constraints to a function
export interface FirestoreQuery{
[x: string]: any;
property:string;
value:any;};

async collectionPA(
ref: CollectionPredicate,
options : FirestoreQuery[]
): Promise {

let wherelist:FirestoreQuery[] = options.filter(x => x.property === 'where');
let orderByList:FirestoreQuery[] = options.filter(x => x.property === 'orderBy');
let limitList:FirestoreQuery[] = options.filter(x => x.property === 'limit');
if (wherelist instanceof Array) {
for (let w of wherelist) {
constraints.push(w.value);
}
}
if (orderByList[0] instanceof Array) {
// It's an array of array
for (let o of orderByList) {
constraints.push(o.value);
}

**dataQuery = query(colRef, ...constraints);**

}

_Console.log on constraints has the following data..._
Constraints:::["where('read', '==', false)","limit(3)"]

The line give an error
ERROR TypeError: n._apply is not a function
at Uh (index.esm2017.js:18542:30)
at angular-fire.js:227:48
at angular-fire.js:160:59
at _ZoneDelegate.invoke (zone.js:372:26)
at Zone.run (zone.js:134:43)
at NgZone.runOutsideAngular (core.mjs:26414:28)
at runOutsideAngular (angular-fire.js:160:35)
at angular-fire.js:227:21
at firebasehelper.service.ts:202:22
at Generator.next ()
**Steps to set up and reproduce**

**Sample data and security rules**
let options : FirestoreQuery[] =[];
options = [
{property:"where", value: "where('read', '==', false)"},
{property:"orderBy",value:"OrderBy('createdAt', 'desc')"},
{property:"limit", value:"limit(3)"},
];

const promiseNotify: Observable = fromPromise(this._firebasehelperService.collectionPA('notifications',options));

### Debug output

** Errors in the JavaScript console **

** Output from `firebase.database().enableLogging(true);` **

** Screenshots **
![image](https://user-images.githubusercontent.com/39094436/183267403-67962346-05f4-4341-a387-920e7a6c0810.png)

### Expected behavior

### Actual behavior

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Lệnh gọi được báo cáo nằm tại firebasehelper.service.ts:202; hãy tái hiện lệnh gọi đó với Angular 14, Firebase 9 và AngularFire 7.4.1 bằng các tùy chọn đã cho. So sánh query(colRef, ...constraints) với ví dụ constraints1 trực tiếp và xác minh những giá trị nào được truyền tới lệnh gọi. Được xem là hoàn tất khi có một bản tái hiện tối thiểu đã được xác nhận với kết quả kỳ vọng so với thực tế rõ ràng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
angular, firebase, typescript
Lĩnh vực
database
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.