DEV Community

Mark Cleverdon
Mark Cleverdon

Posted on

AngularFirestore when clause

I am trying to create an app wide service for access to Firestore and it works very well , I am impressed with AFS as with one simple service I can access all of my data across the app.

My problem is making a when clause for my data searches and trying to use a single variable/array where the clause needs 3 parameters.

this is my code in the service:

`getRows(clientID: string, collID: string, order = 'name', pageStart = '', where = ['id', '>', ''])
{
const field: string = where[0];
const opStr: WhereFilterOp = where[1];
const value: string = where[2];

return this.afs.collection(clientID + '/tables/' + collID,
ref => ref
.orderBy(order, 'asc')
.limit(50)
.startAfter(pageStart)
.where(field, opStr, value) // TODO fix where clause
).valueChanges({ idField: 'id'});
}
`
Here I have opted for separating the array into the three parameters and it works OK but:

My question, is there a way in typescript to use one variable and expand it to give the three parameters needed in the where clause itself?

Mark

Discussion (0)