Files
nto-cli/generation/templates/service.tmpl
2025-03-16 11:07:30 +07:00

49 lines
1.2 KiB
Cheetah

import { GetAll, Create, Delete, GetById, Update, Count, SortedByOrder, SearchByAllTextFields } from "../../bindings/app/internal/services/{{.LowerModelName}}service"
import type { {{.ModelName}} } from "{{.ServicesPath}}"
import type { IService } from "../types/service.type"
import type { SortOptions } from "../types/sort-options.type";
export default class {{.ModelName}}Service implements IService<{{.ModelName}}> {
async read(id: number) {
return await GetById(id) as {{.ModelName}}
}
async readAll() {
return await GetAll() as {{.ModelName}}[]
}
async create(item: {{.ModelName}}) {
await Create(item)
}
async delete(id: number) {
return await Delete(id)
}
async update(item: {{.ModelName}}) {
await Update(item)
}
async count() {
return await Count()
}
async search(input: string) {
return await SearchByAllTextFields(input) as {{ .ModelName }}[]
}
async sort(options: SortOptions<Task>) {
return (await SortedByOrder(
Object.entries(options).map((item) => {
if (item[1] !== 'NONE') {
return ({
Name: item[0],
Order: item[1],
})
}
}).filter(item => !!item)
)) as Task[];
}
}
}