loop in all property of model in typescript and nodejs

i have a generic model for get all items from Schema .

export interface FilterViewModel<T> {
    filters: T
}

now i use that by this model :

GetAllUsersPaging(items: FilterViewModel<GetAllUserFilter>)

and this is items of my models :

   export interface GetAllUserFilter {
    blocked: boolean,
    emailConfirmed: boolean,
    isActive: boolean,
    isDeleted: boolean,
    personalVerified: boolean,
    phoneNumberConfirmed: boolean,
    phoneNumber: string
}

now i want to search in all filters item and push that in the variable . i write this code but it not worked and not go loop in the all items and just once loop .

    async GetAllUsersPaging(items: FilterViewModel<GetAllUserFilter>) {

    let query: any = [];


    [items.filters].forEach((element) => {

        if (!element.phoneNumber) {
            query.push(element);
        } else {
            query.push({ phoneNumber: { $regex: `(.*)${element.phoneNumber}(.*)` } });
        }

    });

}

now whats the problem ? how can i loop in all items in items.filters ???

58 thoughts on “loop in all property of model in typescript and nodejs”

Leave a Comment