11import type { Product } from '@base/server/types/models'
2- import { ProductType } from '../db/schemas'
2+ import { ProductStatus , ProductType } from '../db/schemas'
33
44export function useProduct ( ) {
55 function getProducts ( ) : Promise < Product [ ] > {
66 return db . query . productTable . findMany ( {
7+ where ( schema , { eq } ) {
8+ return eq ( schema . status , ProductStatus . ACTIVE )
9+ } ,
710 orderBy ( schema , { asc } ) {
811 return [
912 asc ( schema . position ) ,
@@ -14,8 +17,11 @@ export function useProduct() {
1417
1518 function getCreditPackages ( ) : Promise < Product [ ] > {
1619 return db . query . productTable . findMany ( {
17- where ( schema , { eq } ) {
18- return eq ( schema . type , ProductType . CREDIT )
20+ where ( schema , { eq, and } ) {
21+ return and (
22+ eq ( schema . type , ProductType . CREDIT ) ,
23+ eq ( schema . status , ProductStatus . ACTIVE ) ,
24+ )
1925 } ,
2026 orderBy ( schema , { asc } ) {
2127 return [
@@ -27,8 +33,11 @@ export function useProduct() {
2733
2834 function getProductByProductId ( productId : string ) : Promise < Pick < Product , 'id' | 'price' | 'amount' > | undefined > {
2935 return db . query . productTable . findFirst ( {
30- where ( schema , { eq } ) {
31- return eq ( schema . id , productId )
36+ where ( schema , { eq, and } ) {
37+ return and (
38+ eq ( schema . id , productId ) ,
39+ eq ( schema . status , ProductStatus . ACTIVE ) ,
40+ )
3241 } ,
3342 columns : {
3443 id : true ,
0 commit comments