-
Notifications
You must be signed in to change notification settings - Fork 1
/
hero_service.ts
27 lines (21 loc) · 1015 Bytes
/
hero_service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import {getCustomRepository} from "typeorm";
import type {DeleteResult} from "typeorm";
import {HeroRepository} from "../repository/HeroRepository.ts";
import {Page, Pageable} from "../util/pages.ts";
import {Hero} from "../entity/hero.ts";
async function getHeroById(id: number): Promise<Hero> {
return await getCustomRepository(HeroRepository).findOneOrFail(id);
}
async function getHeroesByPage(pageable: Pageable): Promise<Page<Hero>> {
return await getCustomRepository(HeroRepository).findAll(pageable);
}
async function findHeroesByName(name: string): Promise<Hero[]> {
return await getCustomRepository(HeroRepository).findByName(name);
}
async function saveHero(hero: Hero): Promise<Hero> {
return await getCustomRepository(HeroRepository).save(hero);
}
async function deleteHeroById(id: number): Promise<DeleteResult> {
return await getCustomRepository(HeroRepository).delete(id);
}
export {getHeroById, getHeroesByPage, findHeroesByName, saveHero, deleteHeroById};