Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
intrn(query): sift tags by slug
Browse files Browse the repository at this point in the history
Co-authored-by: Kenneth Trecy Tobias <19201.tobias.kennethtrecy.c@gmail.com>
  • Loading branch information
lemredd and KennethTrecy committed Nov 6, 2022
1 parent cda2f2c commit 8528d62
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions database/queries/tag/sift_by_slug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { SlugFilter } from "$/types/query"
import type { FindOptions } from "%/types/dependent"

import Log from "$!/singletons/log"

import Condition from "%/helpers/condition"
import isUndefined from "$/type_guards/is_undefined"

/**
* Sifts tag model which matches a certain name.
*/
export default function<T>(
currentState: FindOptions<T>,
constraints: SlugFilter
): FindOptions<T> {
const newState = { ...currentState }

switch (constraints.filter.slug) {
case "":
// Do nothing
break
default: {
const condition = new Condition()
condition.or(
new Condition().search("name", constraints.filter.slug)
)

if (isUndefined(newState.where)) {
newState.where = {}
}

newState.where = {
...newState.where,
...condition.build()
}
break
}
}

Log.trace("pipeline", "sift by slug")

return newState
}

0 comments on commit 8528d62

Please sign in to comment.