Files
domain-wall/packages/logic/domains/product/usecases.ts
2025-10-20 19:16:19 +03:00

40 lines
931 B
TypeScript

import { db } from "@pkg/db";
import type { CreateProductPayload, UpdateProductPayload } from "./data";
import { ProductRepository } from "./repository";
export class ProductUseCases {
private repo: ProductRepository;
constructor(repo: ProductRepository) {
this.repo = repo;
}
async getAllProducts() {
return this.repo.listAllProducts();
}
async getProductById(id: number) {
return this.repo.getProductById(id);
}
async createProduct(payload: CreateProductPayload) {
return this.repo.createProduct(payload);
}
async updateProduct(payload: UpdateProductPayload) {
return this.repo.updateProduct(payload);
}
async deleteProduct(id: number) {
return this.repo.deleteProduct(id);
}
async refreshProductLinkId(id: number) {
return this.repo.refreshProductLinkId(id);
}
}
export function getProductUseCases() {
return new ProductUseCases(new ProductRepository(db));
}