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({
|
@Module({
|
||||||
imports: [DrizzleModule, CredentialsModule],
|
imports: [DrizzleModule, CredentialsModule],
|
||||||
controllers: [ProductsController],
|
controllers: [ProductsController],
|
||||||
providers: [ProductsService]
|
providers: [ProductsService],
|
||||||
|
exports: [ProductsService]
|
||||||
})
|
})
|
||||||
export class ProductsModule {}
|
export class ProductsModule {}
|
||||||
|
@ -3,6 +3,7 @@ import { DrizzleService } from "src/drizzle/drizzle.service";
|
|||||||
import { ProductsTable } from "src/schema";
|
import { ProductsTable } from "src/schema";
|
||||||
import { CreateProductDto, EditProductDto } from "src/products/products.dto";
|
import { CreateProductDto, EditProductDto } from "src/products/products.dto";
|
||||||
import { countDistinct, eq } from "drizzle-orm";
|
import { countDistinct, eq } from "drizzle-orm";
|
||||||
|
import * as console from "node:console";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ProductsService {
|
export class ProductsService {
|
||||||
@ -11,6 +12,17 @@ export class ProductsService {
|
|||||||
private db: DrizzleService,
|
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) {
|
async add(data: CreateProductDto) {
|
||||||
try {
|
try {
|
||||||
const res = await this.db.use()
|
const res = await this.db.use()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user