mirror of
https://gitea.gofwd.group/dstrawsb/ballistic-builder.git
synced 2025-12-06 02:36:44 -05:00
adding dynamic filters
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { db } from '@db/index';
|
||||
import { psa } from '@schemas/schema';
|
||||
import { bb_products, psa } from '@schemas/schema';
|
||||
import { eq, lt, gte, ne, and, like } from 'drizzle-orm';
|
||||
import CATEGORY from '@src/data/parts_cats.json';
|
||||
|
||||
@@ -69,6 +69,17 @@ export async function getARHandGuards(page = 1) {
|
||||
.offset(offset);
|
||||
}
|
||||
|
||||
export async function getSuppressors(page = 1) {
|
||||
const limit = 40;
|
||||
const offset = (page - 1) * limit;
|
||||
|
||||
return await db.select()
|
||||
.from(bb_products)
|
||||
.limit(limit)
|
||||
.where(and(eq(bb_products.category, "Muzzle Devices"), eq(bb_products.subcategory, 'Suppressors')))
|
||||
.offset(offset);
|
||||
}
|
||||
|
||||
export async function getAKHandGuards(page = 1) {
|
||||
const limit = 40;
|
||||
const offset = (page - 1) * limit;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// db/queries.ts
|
||||
"use server";
|
||||
import { eq, not , asc} from "drizzle-orm";
|
||||
import { products } from '@schemas/schema';
|
||||
import { products, bb_products } from '@schemas/schema';
|
||||
import { db } from '@db/index';
|
||||
|
||||
// Fetch all products
|
||||
@@ -22,4 +22,14 @@ export async function updateProduct( id:number) {
|
||||
// Delete a product
|
||||
export async function deleteProduct(id: number) {
|
||||
return await db.delete(products).where(eq(products.id, id));
|
||||
}
|
||||
|
||||
// Fetch bb_products categories
|
||||
export async function getBBProductsCategories() {
|
||||
return await db.selectDistinct({category:bb_products.category}).from(bb_products).limit(100).orderBy(asc(bb_products.category));
|
||||
}
|
||||
|
||||
// Fetch bb_products subcategories
|
||||
export async function getBBProductsSubCategories(category : string) {
|
||||
return await db.selectDistinct({subcategory:bb_products.subcategory}).from(bb_products).where(eq(bb_products.category, category)).limit(200);
|
||||
}
|
||||
Reference in New Issue
Block a user