jeudi 18 juin 2020

Only return parameters if they are not empty

I have a method to generate filters like below:

_generateFilters() {
    const status = get(this, 'controller.status');
    const type = get(this, 'controller.type');
    const name = get(this, 'controller.name');

    const statusFilter = isEmpty(status) ? [] : generateFilter(status);
    const typeFilter = isEmpty(type) ? [] : generateFilter(type);
    const nameFilter = isEmpty(name) ? [] : generateFilter(name);

    return {
       statusFilter,
       typeFilter,
       nameFilter,
    };
}

For now it will return all parameters, but I want to return the parameters only with not empty value. like if status is empty, type and name is non empty, then return { tyepFilter, nameFilter }. Does someone know how to do it in this method? Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire