Last active
August 22, 2020 00:21
-
-
Save Megajjks/9419db095b85f8ca6326827a4c86d1e7 to your computer and use it in GitHub Desktop.
Helpers and Filters in JS.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//function that filters a commitment by one or more types of status | |
//filterWithStatus({...},["query1"...]) | |
export const filterWithStatus = (data, query) => { | |
const filteredData = data.filter((item) => { | |
for (let key in query) { | |
if (item.status === undefined) { | |
return false; | |
} else if (query[key].includes(item.status)) { | |
return true; | |
} | |
} | |
return false; | |
}); | |
return filteredData; | |
}; | |
//function that filters an users by one or more types of rol | |
//filterWithRol({...},["query1"...]) | |
export const filterWithRol = (data, query) => { | |
const filteredData = data.filter((item) => { | |
for (let key in query) { | |
if (item.roleId === undefined) { | |
return false; | |
} else if (query[key].includes(item.roleId)) { | |
return true; | |
} | |
} | |
return false; | |
}); | |
return filteredData; | |
}; | |
//function that filters a commitment by Id collaborator | |
//filterWithIdCollaboratorAndStatus({...},id,["query1"...]) | |
export const filterWithIdCollaboratorAndStatus = ( | |
commitments, | |
idCollaborator, | |
status | |
) => { | |
const commitmensFilter = filterWithStatus(commitments, status); | |
const filterData = commitmensFilter.filter(({ collaborators }) => { | |
return collaborators.some(({ id }) => id === idCollaborator); | |
}); | |
return filterData; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment