Files
ballistic-builder/src/db/queries/PSA/index.ts

180 lines
4.3 KiB
TypeScript
Raw Normal View History

2024-12-18 15:59:44 -05:00
import { db } from '@db/index';
2025-02-01 23:47:45 -05:00
import { bb_products, psa } from '@schemas/schema';
2024-12-13 00:31:17 -05:00
import { eq, lt, gte, ne, and, like } from 'drizzle-orm';
2024-12-12 16:23:05 -05:00
import CATEGORY from '@src/data/parts_cats.json';
export async function getPSA(page = 1) {
2024-12-12 00:04:14 -05:00
const limit = 20;
const offset = (page - 1) * limit;
return await db.select()
.from(psa)
.limit(limit)
2024-12-12 00:04:14 -05:00
.where(eq(psa.fineline, "Lower Build Kits"))
.offset(offset);
2024-12-12 00:04:14 -05:00
}
export async function getLowerBuildKits(page = 1) {
const limit = 20;
const offset = (page - 1) * limit;
return await db.select()
.from(psa)
.limit(limit)
.where(eq(psa.fineline, "Lower Build Kits"))
.offset(offset);
}
export async function getARCompleteLowers(page = 1) {
2024-12-18 13:51:12 -05:00
const limit = 240;
2024-12-12 00:04:14 -05:00
const offset = (page - 1) * limit;
return await db.select()
.from(psa)
.limit(limit)
.where(eq(psa.fineline, "AR Complete Lowers"))
.offset(offset);
}
2024-12-12 16:23:05 -05:00
export async function getProductType(productType : any, page = 1) {
const limit = 40;
const offset = (page - 1) * limit;
2024-12-18 13:51:12 -05:00
await new Promise((resolve) => setTimeout(resolve,1000));
2024-12-12 16:23:05 -05:00
return await db.select()
.from(psa)
.limit(limit)
2024-12-13 00:31:17 -05:00
.where(eq(psa.fineline, (typeof(productType) !== 'string' ? productType.name : productType)))
2024-12-12 16:23:05 -05:00
.offset(offset);
}
2024-12-13 00:31:17 -05:00
export async function getGrips(page = 1) {
const limit = 40;
const offset = (page - 1) * limit;
return await db.select()
.from(psa)
.limit(limit)
.where(eq(psa.fineline, "Grips"))
.offset(offset);
}
export async function getARHandGuards(page = 1) {
const limit = 40;
const offset = (page - 1) * limit;
return await db.select()
.from(psa)
.limit(limit)
.where(and(eq(psa.fineline, "Handguards & Rail Systems"), eq(psa.category, 'Ar Parts')))
.offset(offset);
}
2025-02-01 23:47:45 -05:00
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);
}
2024-12-13 00:31:17 -05:00
export async function getAKHandGuards(page = 1) {
const limit = 40;
const offset = (page - 1) * limit;
return await db.select()
.from(psa)
.limit(limit)
.where(and(eq(psa.fineline, "Handguards & Rail Systems"), eq(psa.category, 'Ak Parts')))
.offset(offset);
}
export async function getMuzzleDevices(page = 1) {
const limit = 40;
const offset = (page - 1) * limit;
return await db.select()
.from(psa)
.limit(limit)
.where(eq(psa.fineline, "Muzzle Brakes"))
.offset(offset);
}
export async function getStocks(page = 1) {
const limit = 40;
const offset = (page - 1) * limit;
return await db.select()
.from(psa)
.limit(limit)
.where(eq(psa.fineline, "Stocks"))
.offset(offset);
}
2025-01-19 23:49:48 -05:00
export async function getOptics(page = 1) {
const limit = 40;
const offset = (page - 1) * limit;
return await db.select()
.from(psa)
.limit(limit)
.where(and(like(psa.fineline, "%Optics%")))
.offset(offset);
}
2024-12-13 00:31:17 -05:00
export async function getStocksParts(page = 1) {
const limit = 40;
const offset = (page - 1) * limit;
return await db.select()
.from(psa)
.limit(limit)
.where(eq(psa.fineline, "Stocks"))
.offset(offset);
}
2024-12-16 00:25:35 -05:00
2024-12-13 00:31:17 -05:00
export async function getUpperReciever(page = 1) {
const limit = 40;
const offset = (page - 1) * limit;
return await db.select()
.from(psa)
.limit(limit)
.where(like(psa.fineline, "%Upper Receivers"))
.offset(offset);
}
export async function getARTriggers(page = 1) {
const limit = 40;
const offset = (page - 1) * limit;
2024-12-13 14:22:24 -05:00
return await db.select()
.from(psa)
.limit(limit)
.where(and(like(psa.fineline, "%Trigger%"), like(psa.category, "Ar Parts")))
.offset(offset);
}
2024-12-16 00:25:35 -05:00
2024-12-13 14:22:24 -05:00
export async function getARParts(page = 1) {
const limit = 40;
const offset = (page - 1) * limit;
2024-12-13 00:31:17 -05:00
return await db.select()
.from(psa)
.limit(limit)
.where(and(like(psa.fineline, "%Trigger%"), like(psa.category, "Ar Parts")))
.offset(offset);
2024-12-15 23:39:56 -05:00
}
2024-12-16 00:25:35 -05:00
2024-12-15 23:39:56 -05:00
export async function getMags(page = 1) {
const limit = 40;
const offset = (page - 1) * limit;
return await db.select()
.from(psa)
.limit(limit)
2024-12-16 00:25:35 -05:00
.where(like(psa.superfineline, "%AR Magazines%"))
2024-12-15 23:39:56 -05:00
.offset(offset);
2024-12-13 00:31:17 -05:00
}