Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: correct wording in criteria util #525

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions libs/angular-accelerator/src/lib/utils/criteria.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { QueryList } from '@angular/core'
import { FormGroup } from '@angular/forms'
import { getUTCDateWithoutTimezoneIssues, isValidDate } from '@onecx/accelerator'
import { Calendar } from 'primeng/calendar'

Expand All @@ -21,22 +20,22 @@ function _hasShowTime(calendars: QueryList<Calendar>, formKey: string): boolean

/**
* Safely builds the search criteria based on form values
* @param formValues the form values to use
* @param formRawValue the raw value of the form to use
* @param calendars a list of primeng calendars of the form (use `@ViewChildren(Calendar) calendars!: QueryList<Calendar>;`)
* @param parameters {@link BuildSearchCriteriaParameters} to use when building the search criteria
* @returns the search criteria as partial of T (T = type of the search criteria)
* @returns the search criteria as a partial of T (T = type of the search criteria)
*/
export function buildSearchCriteria<T>(
formValues: FormGroup<any>,
formRawValue: any,
calendars: QueryList<Calendar>,
{ removeNullValues = false }: BuildSearchCriteriaParameters
) {
return Object.entries(formValues).reduce((acc: Partial<T>, [key, value]) => {
return Object.entries(formRawValue).reduce((acc: Partial<T>, [key, value]) => {
if (value == null && removeNullValues) {
return acc
}
if (isValidDate(value) && !_hasShowTime(calendars, key)) {
value = getUTCDateWithoutTimezoneIssues(value);
value = getUTCDateWithoutTimezoneIssues(value)
}
return {
...acc,
Expand Down
Loading