From b62bf792216c22fe24e42fd7b713abcdc30f18ba Mon Sep 17 00:00:00 2001 From: Mathis Date: Mon, 15 Jul 2024 14:35:05 +0200 Subject: [PATCH] feat(products): add find by id method in product service This commit introduces a new `findById` asynchronous method in the `ProductsService`. This aims to fetch specific product details using product ID from the `ProductsTable`. Additionally, `ProductsService` is exported in the products module. --- src/products/products.module.ts | 3 ++- src/products/products.service.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/products/products.module.ts b/src/products/products.module.ts index 0815b30..b2ae522 100644 --- a/src/products/products.module.ts +++ b/src/products/products.module.ts @@ -7,6 +7,7 @@ import { CredentialsModule } from "src/credentials/credentials.module"; @Module({ imports: [DrizzleModule, CredentialsModule], controllers: [ProductsController], - providers: [ProductsService] + providers: [ProductsService], + exports: [ProductsService] }) export class ProductsModule {} diff --git a/src/products/products.service.ts b/src/products/products.service.ts index 80730b5..d2e1ece 100644 --- a/src/products/products.service.ts +++ b/src/products/products.service.ts @@ -3,6 +3,7 @@ import { DrizzleService } from "src/drizzle/drizzle.service"; import { ProductsTable } from "src/schema"; import { CreateProductDto, EditProductDto } from "src/products/products.dto"; import { countDistinct, eq } from "drizzle-orm"; +import * as console from "node:console"; @Injectable() export class ProductsService { @@ -11,6 +12,17 @@ export class ProductsService { private db: DrizzleService, ) {} + async findById(productId:string) { + const res = await this.db.use() + .select() + .from(ProductsTable) + .where(eq(ProductsTable.uuid, productId)) + .prepare("findProductById") + .execute(); + console.log(`Fetching product n°${productId} ...\n`, res) + return res[0]; + } + async add(data: CreateProductDto) { try { const res = await this.db.use()