mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 06:28:51 +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)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS npwd_sellout_listings (
|
||||
CREATE TABLE IF NOT EXISTS npwd_marketplace_listings (
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
identifier 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,
|
||||
updatedAt timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
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 (
|
||||
@@ -88,10 +82,7 @@ CREATE TABLE IF NOT EXISTS npwd_marketplace_reports (
|
||||
listing_id int(11) DEFAULT NULL,
|
||||
profile varchar(255) DEFAULT NULL,
|
||||
PRIMARY KEY (id)
|
||||
)
|
||||
ENGINE = INNODB,
|
||||
CHARACTER SET utf8mb4,
|
||||
COLLATE utf8mb4_general_ci;
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `npwd_twitter_reports` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import events from '../utils/events';
|
||||
import { getIdentifier, getPlayer, getSource } from './functions';
|
||||
import { ESX } from './server';
|
||||
import { pool } from './db';
|
||||
import { mainLogger } from './sv_logger';
|
||||
import { MarketplaceListing } from '../../typings/marketplace';
|
||||
@@ -8,12 +9,10 @@ import { reportListingToDiscord } from './discord';
|
||||
const selloutLogger = mainLogger.child({ module: 'sellout' });
|
||||
|
||||
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 listings = <MarketplaceListing[]>results;
|
||||
|
||||
return listings;
|
||||
return <MarketplaceListing[]>results;
|
||||
}
|
||||
|
||||
async function addListing(
|
||||
@@ -24,7 +23,7 @@ async function addListing(
|
||||
listing: MarketplaceListing,
|
||||
): Promise<void> {
|
||||
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, [
|
||||
identifier,
|
||||
username,
|
||||
@@ -37,17 +36,16 @@ async function addListing(
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
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 listings = <MarketplaceListing[]>results;
|
||||
const listing = listings[0];
|
||||
return listing;
|
||||
return listings[0];
|
||||
}
|
||||
|
||||
async function reportListing(listingId: number, profile: string): Promise<void> {
|
||||
@@ -144,18 +142,19 @@ onNet(events.SELLOUT_REPORT_LISTING, async (listing: MarketplaceListing) => {
|
||||
if (reportExists) {
|
||||
// send an info alert
|
||||
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',
|
||||
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) {
|
||||
selloutLogger.error(`Failed to report listing ${e.message}`, {
|
||||
source: pSource,
|
||||
|
||||
Reference in new issue
Block a user