From bf06c1ed3f5c2faf2ccbfe4c09fc3c226b2e97dd Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 2 Mar 2021 20:05:11 +0100 Subject: [PATCH] feat(resources/marketplace): more cleanup --- resources/client/cl_sellout.ts | 21 +++++++++++---------- resources/server/sv_sellout.ts | 12 ++++++------ resources/utils/events.ts | 1 + 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/resources/client/cl_sellout.ts b/resources/client/cl_sellout.ts index e4fe69b..b130f38 100644 --- a/resources/client/cl_sellout.ts +++ b/resources/client/cl_sellout.ts @@ -15,20 +15,21 @@ onNet(events.SELLOUT_SEND_LISTING, (listing: MarketplaceListing) => { RegisterNuiCallbackType(events.SELLOUT_ADD_LISTING); on(`__cfx_nui:${events.SELLOUT_ADD_LISTING}`, (data: MarketplaceListing) => { emitNet(events.SELLOUT_ADD_LISTING, data); - - setTimeout(() => { - emitNet(events.SELLOUT_FETCH_LISTING); - console.log('Fetched'); - }, 500); }); +// this will be triggerd when +// the adding of a new listing is successfully + +onNet(events.SELLOUT_ADD_LISTING_SUCCESS, () => { + emitNet(events.SELLOUT_FETCH_LISTING); +}); onNet(events.SELLOUT_ACTION_RESULT, (alert: IAlertProps) => { SendNuiMessage( JSON.stringify({ - app: "SELLOUT", - method: "setAlert", - data: alert + app: 'SELLOUT', + method: 'setAlert', + data: alert, }) - ) -}) \ No newline at end of file + ); +}); diff --git a/resources/server/sv_sellout.ts b/resources/server/sv_sellout.ts index d0a42be..569ee35 100644 --- a/resources/server/sv_sellout.ts +++ b/resources/server/sv_sellout.ts @@ -8,7 +8,6 @@ import { MarketplaceListing } from '../../phone/src/common/typings/marketplace'; const selloutLogger = mainLogger.child({ module: 'sellout' }); - async function fetchAllListings(): Promise { const query = 'SELECT * FROM npwd_sellout_listings ORDER BY id DESC'; @@ -58,18 +57,19 @@ onNet(events.SELLOUT_ADD_LISTING, async (listing: MarketplaceListing) => { const phoneNumber = await usePhoneNumber(_identifier); await addListing(_identifier, name, phoneNumber, listing); + emitNet(events.SELLOUT_ADD_LISTING_SUCCESS, _source); emitNet(events.SELLOUT_ACTION_RESULT, _source, { message: 'MARKETPLACE_CREATE_LISTING_SUCCESS', - type: 'success' - }) + type: 'success', + }); } catch (e) { selloutLogger.error(`Failed to add listing ${e.message}`, { source: _source, }); - + emitNet(events.SELLOUT_ACTION_RESULT, _source, { message: 'MARKETPALCE_CREATE_LISTING_FAILED', - type: 'error' - }) + type: 'error', + }); } }); diff --git a/resources/utils/events.ts b/resources/utils/events.ts index fadb583..e72c433 100644 --- a/resources/utils/events.ts +++ b/resources/utils/events.ts @@ -41,6 +41,7 @@ export default { // Sellout SELLOUT_ADD_LISTING: 'phone:addListing', + SELLOUT_ADD_LISTING_SUCCESS: 'phone:addListingSuccess', SELLOUT_FETCH_LISTING: 'phone:fetchAllListings', SELLOUT_SEND_LISTING: 'phone:sendAllListings', SELLOUT_ACTION_RESULT: 'phone:selloutActionResult',