feat: search, sort

This commit is contained in:
opbnq-q
2025-03-15 19:21:27 +07:00
parent c68494e07b
commit d2dedd85f9
2 changed files with 25 additions and 5 deletions

View File

@@ -1,6 +1,8 @@
import { GetAll, Create, Delete, GetById, Update, Count } from "../../bindings/app/internal/services/{{.LowerModelName}}service.ts"
import { GetAll, Create, Delete, GetById, Update, Count, SortedByOrder, SearchByAllTextFields } from "../../bindings/app/internal/services/{{.LowerModelName}}service.ts"
import type { {{.ModelName}} } from "{{.ServicesPath}}"
import type { IService } from "../types/service.type.ts"
import type { SortOptions } from "../types/sort-options.type.ts";
export default class {{.ModelName}}Service implements IService<{{.ModelName}}> {
async read(id: number) {
@@ -26,4 +28,12 @@ export default class {{.ModelName}}Service implements IService<{{.ModelName}}> {
async count() {
return await Count()
}
async search(input: string) {
return await SearchByAllTextFields(input) as {{ .ModelName }}[]
}
async sort(options: SortOptions<{{ .ModelName }}>) {
return await SortedByOrder(Object.entries(options).map(item => ({Name: item[0], Order: item[1]}))) as {{ .ModelName }}[]
}
}