| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- import type { Query as PiniaOrmQuery } from 'pinia-orm'
- import type { ApiFilter } from '~/types/data'
- import ApiResource from '~/models/ApiResource'
- import { SEARCH_STRATEGY } from '~/types/enum/data'
- /**
- *
- */
- export default class Search implements ApiFilter {
- field: string
- value: Ref<string | number>
- private mode: string
- /**
- * @param field
- * @param value
- * @param mode The search strategy (exact [default], partial, start, end, word_start).
- * This strategy is defined API-side, but PiniaOrm needs to know how to handle this.
- * @see https://api-platform.com/docs/core/filters/
- */
- constructor(
- field: string,
- value: Ref<string | number>,
- mode: SEARCH_STRATEGY = SEARCH_STRATEGY.EXACT,
- ) {
- this.field = field
- this.value = value
- this.mode = mode
- }
- public applyToPiniaOrmQuery(
- query: PiniaOrmQuery<ApiResource>,
- ): PiniaOrmQuery<ApiResource> {
- return query.where(this.field, this.value.value)
- }
- public getApiQueryPart(): string {
- return `${this.field}[]=${this.value.value}`
- }
- }
|