Files
2025-10-21 13:11:31 +03:00

44 lines
1.0 KiB
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 getProductByLinkId(linkId: string) {
return this.repo.getProductById(linkId);
}
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));
}