This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
generated from KennethTrecy/web_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
intrn(database): sift by slug for tag
- Loading branch information
Angelo Magtoto
committed
Nov 14, 2022
1 parent
6fd7b9c
commit 5ca5b76
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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" | ||
|
||
/** | ||
* Sift user model which matches a certain column. | ||
*/ | ||
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 | ||
} |