import { pool } from '../db'; import { MarketplaceListing } from '../../../typings/marketplace'; export class _MarketplaceDB { async addListing( identifier: string, username: string, name: string, number: any, listing: MarketplaceListing, ): Promise { const query = 'INSERT INTO npwd_marketplace_listings (identifier, username, name, number, title, url, description) VALUES (?, ?, ?, ?, ?, ?, ?)'; await pool.query(query, [ identifier, username, name, number, listing.title, listing.url, listing.description, ]); } async fetchListings(): Promise { const query = 'SELECT * FROM npwd_marketplace_listings ORDER BY id DESC'; const [results] = await pool.query(query); return results; } async deleteListing(listingId: number, identifier: string): Promise { const query = 'DELETE FROM npwd_marketplace_listings WHERE id = ? AND identifier = ?'; await pool.query(query, [listingId, identifier]); } async getListing(listingId: number): Promise { const query = `SELECT * FROM npwd_marketplace_listings WHERE id = ?`; const [results] = await pool.query(query, [listingId]); const listings = results; return listings[0]; } async reportListing(listingId: number, profile: string): Promise { const query = `INSERT INTO npwd_marketplace_reports (listing_id, profile) VALUES (?, ?)`; await pool.query(query, [listingId, profile]); } async doesReportExist(listingId: number, profile: string): Promise { const query = `SELECT * FROM npwd_marketplace_reports WHERE listing_id = ? AND profile = ?`; const [results] = await pool.query(query, [listingId, profile]); const result = results; return result.length > 0; } } const MarketplaceDB = new _MarketplaceDB(); export default MarketplaceDB;