fix: remove non-existent vendor URL columns, fix text=uuid cast in transceiver lookup
This commit is contained in:
parent
891bd018a8
commit
f940bf2cd4
@ -12,6 +12,7 @@ export interface SearchParams {
|
||||
wdm_type?: string;
|
||||
coherent?: boolean;
|
||||
market_status?: string;
|
||||
vendor?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
}
|
||||
@ -76,6 +77,11 @@ export async function searchTransceivers(params: SearchParams) {
|
||||
values.push(params.market_status);
|
||||
idx++;
|
||||
}
|
||||
if (params.vendor) {
|
||||
conditions.push(`v.name ILIKE $${idx}`);
|
||||
values.push(`%${params.vendor}%`);
|
||||
idx++;
|
||||
}
|
||||
|
||||
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
||||
const limit = params.limit || 50;
|
||||
@ -95,7 +101,7 @@ export async function searchTransceivers(params: SearchParams) {
|
||||
LIMIT ${limit} OFFSET ${offset}
|
||||
`;
|
||||
|
||||
const countQuery = `SELECT COUNT(*) FROM transceivers ${where}`;
|
||||
const countQuery = `SELECT COUNT(*) FROM transceivers t LEFT JOIN vendors v ON t.vendor_id = v.id ${where}`;
|
||||
|
||||
const [dataResult, countResult] = await Promise.all([
|
||||
pool.query(query, values),
|
||||
@ -116,13 +122,22 @@ export async function getTransceiverById(id: string) {
|
||||
FROM transceivers t
|
||||
LEFT JOIN vendors v ON t.vendor_id = v.id
|
||||
LEFT JOIN standards s ON t.standard_id = s.id
|
||||
WHERE t.id = $1 OR t.slug = $1`,
|
||||
WHERE t.id::text = $1::text OR t.slug = $1::text`,
|
||||
[id]
|
||||
);
|
||||
return result.rows[0] || null;
|
||||
}
|
||||
|
||||
export async function searchSwitches(params: SearchParams) {
|
||||
export interface SwitchSearchParams extends SearchParams {
|
||||
whitebox?: boolean;
|
||||
sonic_compatible?: boolean;
|
||||
asic_vendor?: string;
|
||||
nos?: string;
|
||||
ocp?: boolean;
|
||||
max_speed_gbps?: number;
|
||||
}
|
||||
|
||||
export async function searchSwitches(params: SwitchSearchParams) {
|
||||
const conditions: string[] = [];
|
||||
const values: any[] = [];
|
||||
let idx = 1;
|
||||
@ -137,27 +152,72 @@ export async function searchSwitches(params: SearchParams) {
|
||||
values.push(params.category);
|
||||
idx++;
|
||||
}
|
||||
if (params.whitebox !== undefined) {
|
||||
conditions.push(`sw.is_whitebox = $${idx}`);
|
||||
values.push(params.whitebox);
|
||||
idx++;
|
||||
}
|
||||
if (params.sonic_compatible !== undefined) {
|
||||
conditions.push(`sw.sonic_compatible = $${idx}`);
|
||||
values.push(params.sonic_compatible);
|
||||
idx++;
|
||||
}
|
||||
if (params.asic_vendor) {
|
||||
conditions.push(`sw.asic_vendor ILIKE $${idx}`);
|
||||
values.push(`%${params.asic_vendor}%`);
|
||||
idx++;
|
||||
}
|
||||
if (params.nos) {
|
||||
conditions.push(`$${idx} = ANY(sw.supported_nos)`);
|
||||
values.push(params.nos);
|
||||
idx++;
|
||||
}
|
||||
if (params.ocp !== undefined) {
|
||||
conditions.push(`sw.is_ocp_accepted = $${idx}`);
|
||||
values.push(params.ocp);
|
||||
idx++;
|
||||
}
|
||||
if (params.max_speed_gbps) {
|
||||
conditions.push(`sw.max_speed_gbps = $${idx}`);
|
||||
values.push(params.max_speed_gbps);
|
||||
idx++;
|
||||
}
|
||||
|
||||
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
||||
const limit = params.limit || 50;
|
||||
const offset = params.offset || 0;
|
||||
|
||||
const orderBy = params.q
|
||||
? `ORDER BY ts_rank(sw.search_vector, plainto_tsquery('english', $1)) DESC`
|
||||
: `ORDER BY sw.max_speed_gbps DESC NULLS LAST`;
|
||||
|
||||
const query = `
|
||||
SELECT sw.*, v.name as vendor_name
|
||||
FROM switches sw
|
||||
LEFT JOIN vendors v ON sw.vendor_id = v.id
|
||||
${where}
|
||||
ORDER BY sw.max_speed_gbps DESC NULLS LAST
|
||||
${orderBy}
|
||||
LIMIT ${limit} OFFSET ${offset}
|
||||
`;
|
||||
|
||||
const result = await pool.query(query, values);
|
||||
return { data: result.rows, limit, offset };
|
||||
const countQuery = `SELECT COUNT(*) FROM switches sw ${where}`;
|
||||
|
||||
const [dataResult, countResult] = await Promise.all([
|
||||
pool.query(query, values),
|
||||
pool.query(countQuery, values),
|
||||
]);
|
||||
|
||||
return {
|
||||
data: dataResult.rows,
|
||||
total: parseInt(countResult.rows[0].count),
|
||||
limit,
|
||||
offset,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getSwitchById(id: string) {
|
||||
const result = await pool.query(
|
||||
`SELECT sw.*, v.name as vendor_name
|
||||
`SELECT sw.*, v.name as vendor_name, v.website as vendor_website
|
||||
FROM switches sw
|
||||
LEFT JOIN vendors v ON sw.vendor_id = v.id
|
||||
WHERE sw.id = $1`,
|
||||
@ -166,6 +226,18 @@ export async function getSwitchById(id: string) {
|
||||
return result.rows[0] || null;
|
||||
}
|
||||
|
||||
export async function getSwitchDocuments(switchId: string) {
|
||||
const result = await pool.query(
|
||||
`SELECT pd.*, v.name as vendor_name
|
||||
FROM product_documents pd
|
||||
LEFT JOIN vendors v ON pd.vendor_id = v.id
|
||||
WHERE pd.switch_id = $1
|
||||
ORDER BY pd.doc_type, pd.title`,
|
||||
[switchId]
|
||||
);
|
||||
return result.rows;
|
||||
}
|
||||
|
||||
export async function getCompatibleTransceivers(switchId: string) {
|
||||
const result = await pool.query(
|
||||
`SELECT t.*, c.status, c.verified_by, c.notes as compat_notes
|
||||
@ -180,8 +252,14 @@ export async function getCompatibleTransceivers(switchId: string) {
|
||||
|
||||
export async function listVendors(type?: string) {
|
||||
const query = type
|
||||
? `SELECT * FROM vendors WHERE type = $1 ORDER BY name`
|
||||
: `SELECT * FROM vendors ORDER BY name`;
|
||||
? `SELECT v.*,
|
||||
(SELECT COUNT(*) FROM transceivers t WHERE t.vendor_id = v.id) as transceiver_count,
|
||||
(SELECT COUNT(*) FROM switches s WHERE s.vendor_id = v.id) as switch_count
|
||||
FROM vendors v WHERE v.type = $1 ORDER BY v.name`
|
||||
: `SELECT v.*,
|
||||
(SELECT COUNT(*) FROM transceivers t WHERE t.vendor_id = v.id) as transceiver_count,
|
||||
(SELECT COUNT(*) FROM switches s WHERE s.vendor_id = v.id) as switch_count
|
||||
FROM vendors v ORDER BY v.name`;
|
||||
const result = await pool.query(query, type ? [type] : []);
|
||||
return result.rows;
|
||||
}
|
||||
@ -205,7 +283,10 @@ export async function getDbStats() {
|
||||
(SELECT COUNT(*) FROM breakouts) as breakout_count,
|
||||
(SELECT COUNT(*) FROM knowledge_base) as kb_count,
|
||||
(SELECT COUNT(*) FROM documents) as document_count,
|
||||
(SELECT COUNT(*) FROM news_articles) as news_count
|
||||
(SELECT COUNT(*) FROM news_articles) as news_count,
|
||||
(SELECT COUNT(*) FROM product_documents) as product_document_count,
|
||||
(SELECT COUNT(*) FROM switches WHERE image_url IS NOT NULL) as switches_with_images,
|
||||
(SELECT COUNT(*) FROM switches WHERE datasheet_r2_key IS NOT NULL) as switches_with_datasheets
|
||||
`);
|
||||
return result.rows[0];
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user