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.
This commit is contained in:
parent
e2f7ae8b88
commit
b62bf79221
@ -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 {}
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user