✅ product admin crud
This commit is contained in:
39
packages/logic/domains/product/usecases.ts
Normal file
39
packages/logic/domains/product/usecases.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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));
|
||||
}
|
||||
Reference in New Issue
Block a user