Services in Arkos are used to house business logic, acting as an intermediary between Controllers (HTTP layer) and the database or external systems. This separation ensures that logic is testable and reusable across different entry points, such as HTTP handlers, background jobs, or other services.
import postRepository from "./post.repository";
class PostService {
async getFeatured() {
return postRepository.findMany({ where: { featured: true } });
}
async publish(id: string) {
return postRepository.update({
where: { id },
data: { publishedAt: new Date() },
});
}
}
const postService = new PostService();
export default postService;