mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
cleanup(server/marketplace): General cleanup of marketplace
Tweaked SQL tables to reference 'marketplace' and not 'sellout' Removed if/else in favor of if/return
This commit is contained in:
1 parent
23ef9b8cd6
commit
3031e650e3
2 files changed
+18
-28
No files matched your search
+2
-11
@@ -63,7 +63,7 @@ CREATE TABLE IF NOT EXISTS npwd_notes (
|
|||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS npwd_sellout_listings (
|
CREATE TABLE IF NOT EXISTS npwd_marketplace_listings (
|
||||||
id int(11) NOT NULL AUTO_INCREMENT,
|
id int(11) NOT NULL AUTO_INCREMENT,
|
||||||
identifier varchar(255) DEFAULT NULL,
|
identifier varchar(255) DEFAULT NULL,
|
||||||
username varchar(255) DEFAULT NULL,
|
username varchar(255) DEFAULT NULL,
|
||||||
@@ -75,12 +75,6 @@ CREATE TABLE IF NOT EXISTS npwd_sellout_listings (
|
|||||||
createdAt timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
createdAt timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
updatedAt timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
updatedAt timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id)
|
||||||
)
|
|
||||||
ENGINE = INNODB,
|
|
||||||
AUTO_INCREMENT = 31,
|
|
||||||
AVG_ROW_LENGTH = 2048,
|
|
||||||
CHARACTER SET utf8mb4,
|
|
||||||
COLLATE utf8mb4_general_ci;
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS npwd_marketplace_reports (
|
CREATE TABLE IF NOT EXISTS npwd_marketplace_reports (
|
||||||
@@ -88,10 +82,7 @@ CREATE TABLE IF NOT EXISTS npwd_marketplace_reports (
|
|||||||
listing_id int(11) DEFAULT NULL,
|
listing_id int(11) DEFAULT NULL,
|
||||||
profile varchar(255) DEFAULT NULL,
|
profile varchar(255) DEFAULT NULL,
|
||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id)
|
||||||
)
|
);
|
||||||
ENGINE = INNODB,
|
|
||||||
CHARACTER SET utf8mb4,
|
|
||||||
COLLATE utf8mb4_general_ci;
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `npwd_twitter_reports` (
|
CREATE TABLE IF NOT EXISTS `npwd_twitter_reports` (
|
||||||
`id` int NOT NULL AUTO_INCREMENT,
|
`id` int NOT NULL AUTO_INCREMENT,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import events from '../utils/events';
|
import events from '../utils/events';
|
||||||
import { getIdentifier, getPlayer, getSource } from './functions';
|
import { getIdentifier, getPlayer, getSource } from './functions';
|
||||||
|
import { ESX } from './server';
|
||||||
import { pool } from './db';
|
import { pool } from './db';
|
||||||
import { mainLogger } from './sv_logger';
|
import { mainLogger } from './sv_logger';
|
||||||
import { MarketplaceListing } from '../../typings/marketplace';
|
import { MarketplaceListing } from '../../typings/marketplace';
|
||||||
@@ -8,12 +9,10 @@ import { reportListingToDiscord } from './discord';
|
|||||||
const selloutLogger = mainLogger.child({ module: 'sellout' });
|
const selloutLogger = mainLogger.child({ module: 'sellout' });
|
||||||
|
|
||||||
async function fetchAllListings(): Promise<MarketplaceListing[]> {
|
async function fetchAllListings(): Promise<MarketplaceListing[]> {
|
||||||
const query = 'SELECT * FROM npwd_sellout_listings ORDER BY id DESC';
|
const query = 'SELECT * FROM npwd_marketplace_listings ORDER BY id DESC';
|
||||||
|
|
||||||
const [results] = await pool.query(query);
|
const [results] = await pool.query(query);
|
||||||
const listings = <MarketplaceListing[]>results;
|
return <MarketplaceListing[]>results;
|
||||||
|
|
||||||
return listings;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addListing(
|
async function addListing(
|
||||||
@@ -24,7 +23,7 @@ async function addListing(
|
|||||||
listing: MarketplaceListing,
|
listing: MarketplaceListing,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const query =
|
const query =
|
||||||
'INSERT INTO npwd_sellout_listings (identifier, username, name, number, title, url, description) VALUES (?, ?, ?, ?, ?, ?, ?)';
|
'INSERT INTO npwd_marketplace_listings (identifier, username, name, number, title, url, description) VALUES (?, ?, ?, ?, ?, ?, ?)';
|
||||||
await pool.query(query, [
|
await pool.query(query, [
|
||||||
identifier,
|
identifier,
|
||||||
username,
|
username,
|
||||||
@@ -37,17 +36,16 @@ async function addListing(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function deleteListing(listingId: number, identifier: string): Promise<void> {
|
async function deleteListing(listingId: number, identifier: string): Promise<void> {
|
||||||
const query = 'DELETE FROM npwd_sellout_listings WHERE id = ? AND identifier = ?';
|
const query = 'DELETE FROM npwd_marketplace_listings WHERE id = ? AND identifier = ?';
|
||||||
|
|
||||||
await pool.query(query, [listingId, identifier]);
|
await pool.query(query, [listingId, identifier]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getListing(listingId: number): Promise<MarketplaceListing> {
|
async function getListing(listingId: number): Promise<MarketplaceListing> {
|
||||||
const query = `SELECT * FROM npwd_sellout_listings WHERE id = ?`;
|
const query = `SELECT * FROM npwd_marketplace_listings WHERE id = ?`;
|
||||||
const [results] = await pool.query(query, [listingId]);
|
const [results] = await pool.query(query, [listingId]);
|
||||||
const listings = <MarketplaceListing[]>results;
|
const listings = <MarketplaceListing[]>results;
|
||||||
const listing = listings[0];
|
return listings[0];
|
||||||
return listing;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function reportListing(listingId: number, profile: string): Promise<void> {
|
async function reportListing(listingId: number, profile: string): Promise<void> {
|
||||||
@@ -144,18 +142,19 @@ onNet(events.SELLOUT_REPORT_LISTING, async (listing: MarketplaceListing) => {
|
|||||||
if (reportExists) {
|
if (reportExists) {
|
||||||
// send an info alert
|
// send an info alert
|
||||||
selloutLogger.error(`This listing has already been reported`);
|
selloutLogger.error(`This listing has already been reported`);
|
||||||
emitNet(events.SELLOUT_ACTION_RESULT, pSource, {
|
return emitNet(events.SELLOUT_ACTION_RESULT, pSource, {
|
||||||
message: 'MARKETPLACE_REPORT_LISTING_FAILED',
|
message: 'MARKETPLACE_REPORT_LISTING_FAILED',
|
||||||
type: 'info',
|
type: 'info',
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
await reportListing(rListing.id, rListing.name);
|
|
||||||
await reportListingToDiscord(rListing, reportingPlayer);
|
|
||||||
emitNet(events.SELLOUT_ACTION_RESULT, pSource, {
|
|
||||||
message: 'MARKETPLACE_REPORT_LISTING_SUCCESS',
|
|
||||||
type: 'success',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await reportListing(rListing.id, rListing.name);
|
||||||
|
await reportListingToDiscord(rListing, reportingPlayer);
|
||||||
|
|
||||||
|
emitNet(events.SELLOUT_ACTION_RESULT, pSource, {
|
||||||
|
message: 'MARKETPLACE_REPORT_LISTING_SUCCESS',
|
||||||
|
type: 'success',
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
selloutLogger.error(`Failed to report listing ${e.message}`, {
|
selloutLogger.error(`Failed to report listing ${e.message}`, {
|
||||||
source: pSource,
|
source: pSource,
|
||||||
|
|||||||
Reference in new issue
Block a user