mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 22:16:54 +00:00
tweak(marketplace): Tweak marketplace to match current fetching std
This commit is contained in:
1 parent
10639260e0
commit
5e225ca736
23 files changed
+148
-136
No files matched your search
@@ -3,13 +3,15 @@ import { AppWrapper } from '../../../ui/components';
|
||||
import { AppTitle } from '../../../ui/components/AppTitle';
|
||||
import { AppContent } from '../../../ui/components/AppContent';
|
||||
import { useApp } from '../../../os/apps/hooks/useApps';
|
||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||
import { Route } from 'react-router-dom';
|
||||
import ContactsInfoPage from './views/ContactInfo';
|
||||
import { ContactPage } from './views/ContactsPage';
|
||||
import { ContactsThemeProvider } from '../providers/ContactsThemeProvider';
|
||||
import { ContactEvents } from '../../../../../typings/contact';
|
||||
import { LoadingSpinner } from '../../../ui/components/LoadingSpinner';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { useHistory } from 'react-router';
|
||||
import { Fab, Theme } from '@material-ui/core';
|
||||
import PersonAddIcon from '@material-ui/icons/PersonAdd';
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => ({
|
||||
absolute: {
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import { Box, Tooltip, Button } from '@material-ui/core';
|
||||
import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||
import React from 'react';
|
||||
import {
|
||||
MarketplaceActionResp,
|
||||
MarketplaceEvents,
|
||||
MarketplaceListing,
|
||||
} from '../../../../../../typings/marketplace';
|
||||
import { MarketplaceEvents, MarketplaceListing } from '../../../../../../typings/marketplace';
|
||||
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
|
||||
import DeleteIcon from '@material-ui/icons/Delete';
|
||||
import ReportIcon from '@material-ui/icons/Report';
|
||||
@@ -17,6 +13,7 @@ import { useHistory } from 'react-router';
|
||||
import { CallEvents } from '../../../../../../typings/call';
|
||||
import { fetchNui } from '../../../../utils/fetchNui';
|
||||
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
||||
import { ServerPromiseResp } from '../../../../../../typings/common';
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => ({
|
||||
icon: {
|
||||
@@ -33,12 +30,12 @@ export const ListingActions: React.FC<MarketplaceListing> = ({ children, ...list
|
||||
const { addAlert } = useSnackbar();
|
||||
|
||||
const handleDeleteListing = () => {
|
||||
fetchNui<MarketplaceActionResp>(MarketplaceEvents.DELETE_LISTING, {
|
||||
fetchNui<ServerPromiseResp>(MarketplaceEvents.DELETE_LISTING, {
|
||||
id: listing.id,
|
||||
}).then(({ err, errMsg }) => {
|
||||
if (err) {
|
||||
}).then((resp) => {
|
||||
if (resp.status !== 'ok') {
|
||||
return addAlert({
|
||||
message: t(errMsg),
|
||||
message: t('APPS_MARKETPLACE_DELETE_LISTING_FAILED'),
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
@@ -51,12 +48,12 @@ export const ListingActions: React.FC<MarketplaceListing> = ({ children, ...list
|
||||
};
|
||||
|
||||
const handleReportListing = () => {
|
||||
fetchNui<MarketplaceActionResp>(MarketplaceEvents.REPORT_LISTING, {
|
||||
fetchNui<ServerPromiseResp>(MarketplaceEvents.REPORT_LISTING, {
|
||||
listingId: listing.id,
|
||||
}).then(({ err, errMsg }) => {
|
||||
if (err) {
|
||||
}).then((resp) => {
|
||||
if (resp.status !== 'ok') {
|
||||
return addAlert({
|
||||
message: t(errMsg),
|
||||
message: t('APPS_MARKETPLACE_REPORT_LISTING_FAILED'),
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
import React from 'react';
|
||||
import { MarketplaceList } from './MarketplaceList';
|
||||
import { Box, CircularProgress } from '@material-ui/core';
|
||||
|
||||
const LoadingListings: React.FC = () => (
|
||||
<Box display="flex" flexGrow={1} width="100%" justifyContent="center" alignItems="center">
|
||||
<CircularProgress />
|
||||
</Box>
|
||||
);
|
||||
import { LoadingSpinner } from '../../../../ui/components/LoadingSpinner';
|
||||
|
||||
export const MarketplaceListContainer: React.FC = () => {
|
||||
return (
|
||||
<React.Suspense fallback={<LoadingListings />}>
|
||||
<React.Suspense fallback={<LoadingSpinner />}>
|
||||
<MarketplaceList />
|
||||
</React.Suspense>
|
||||
);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { atom, selector, useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
import { atom, selector, useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
import {
|
||||
MarketplaceEvents,
|
||||
MarketplaceFetchResp,
|
||||
MarketplaceListing,
|
||||
} from '../../../../../typings/marketplace';
|
||||
import { fetchNui } from '../../../utils/fetchNui';
|
||||
import { isEnvBrowser } from '../../../utils/misc';
|
||||
|
||||
const defaultData: MarketplaceListing[] = [
|
||||
{
|
||||
@@ -36,9 +37,11 @@ const listingState = atom<MarketplaceListing[]>({
|
||||
try {
|
||||
return (await fetchNui<MarketplaceFetchResp>(MarketplaceEvents.FETCH_LISTING)).data;
|
||||
} catch (e) {
|
||||
if (process.env.NODE_ENV === 'development' && !process.env.REACT_APP_IN_GAME) {
|
||||
if (isEnvBrowser()) {
|
||||
return defaultData;
|
||||
}
|
||||
console.error(e);
|
||||
return [];
|
||||
}
|
||||
},
|
||||
}),
|
||||
@@ -46,3 +49,4 @@ const listingState = atom<MarketplaceListing[]>({
|
||||
|
||||
export const useListingValue = () => useRecoilValue(listingState);
|
||||
export const useSetListings = () => useSetRecoilState(listingState);
|
||||
export const useListings = () => useRecoilState(listingState);
|
||||
@@ -0,0 +1,28 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useSetListings } from './state';
|
||||
import { MarketplaceListing } from '../../../../../typings/marketplace';
|
||||
|
||||
interface MarketplaceActionValues {
|
||||
deleteListing: (id: number) => void;
|
||||
addListing: (listing: MarketplaceListing) => void;
|
||||
}
|
||||
|
||||
export const useMarketplaceActions = (): MarketplaceActionValues => {
|
||||
const setListings = useSetListings();
|
||||
|
||||
const deleteListing = useCallback(
|
||||
(id: number) => {
|
||||
setListings((curListings) => [...curListings].filter((listing) => listing.id !== id));
|
||||
},
|
||||
[setListings],
|
||||
);
|
||||
|
||||
const addListing = useCallback(
|
||||
(listing: MarketplaceListing) => {
|
||||
setListings((curListings) => [...curListings, listing]);
|
||||
},
|
||||
[setListings],
|
||||
);
|
||||
|
||||
return { deleteListing, addListing };
|
||||
};
|
||||
@@ -1,31 +1,31 @@
|
||||
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||
import {
|
||||
MarketPlaceBroadcastData,
|
||||
MarketplaceBroadcastAddDTO,
|
||||
MarketplaceDeleteDTO,
|
||||
MarketplaceEvents,
|
||||
MarketplaceListing,
|
||||
} from '../../../../../typings/marketplace';
|
||||
import { useSetListings } from './state';
|
||||
import { useMarketplaceActions } from './useMarketplaceActions';
|
||||
|
||||
export const useMarketplaceService = () => {
|
||||
const setListings = useSetListings();
|
||||
const { addListing, deleteListing } = useMarketplaceActions();
|
||||
|
||||
useNuiEvent<MarketPlaceBroadcastData>(
|
||||
'SELLOUT',
|
||||
MarketplaceEvents.BROADCAST_EVENT,
|
||||
({ type, listing }) => {
|
||||
if (type === 'ADD') {
|
||||
const typeCastListing = listing as MarketplaceListing;
|
||||
return setListings((curState) => [...curState, typeCastListing]);
|
||||
}
|
||||
const addListingHandler = (resp: MarketplaceBroadcastAddDTO) => {
|
||||
addListing(resp.listing);
|
||||
};
|
||||
|
||||
if (type === 'DELETE') {
|
||||
const deleteDTO = listing as MarketplaceDeleteDTO;
|
||||
return setListings((currVal) => {
|
||||
const arrayPos = currVal.map((item) => item.id).indexOf(deleteDTO.id);
|
||||
return [...currVal].splice(arrayPos);
|
||||
});
|
||||
}
|
||||
},
|
||||
const deleteListingHandler = (listing: MarketplaceDeleteDTO) => {
|
||||
deleteListing(listing.id);
|
||||
};
|
||||
|
||||
useNuiEvent<MarketplaceBroadcastAddDTO>(
|
||||
'MARKETPLACE',
|
||||
MarketplaceEvents.BROADCAST_ADD,
|
||||
addListingHandler,
|
||||
);
|
||||
|
||||
useNuiEvent<MarketplaceDeleteDTO>(
|
||||
'MARKETPLACE',
|
||||
MarketplaceEvents.BROADCAST_DELETE,
|
||||
deleteListingHandler,
|
||||
);
|
||||
};
|
||||
@@ -14,7 +14,7 @@
|
||||
"APPS_NOTES": "Bilješke",
|
||||
"APPS_EXAMPLE": "Primjerna Aplikacija",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Market",
|
||||
"APPS_MARKETPLACE": "Market",
|
||||
"APPS_CAMERA": "Camera",
|
||||
|
||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Dolazi telefonski poziv",
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
"APPS_NOTES": "Notes",
|
||||
"APPS_EXAMPLE": "Example app",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Marketplace",
|
||||
"APPS_MARKETPLACE": "Marketplace",
|
||||
"APPS_CAMERA": "Camera",
|
||||
|
||||
"APPS_CAMERA_FAILED_TO_TAKE_PHOTO": "Photo could not be saved :(",
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
"APPS_NOTES": "Notas",
|
||||
"APPS_EXAMPLE": "App de Ejemplo",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Mercado",
|
||||
"APPS_MARKETPLACE": "Mercado",
|
||||
"APPS_CAMERA": "Camara",
|
||||
|
||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Llamada entrante",
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
"APPS_NOTES": "Notes",
|
||||
"APPS_EXAMPLE": "App test",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Marché",
|
||||
"APPS_MARKETPLACE": "Marché",
|
||||
"APPS_CAMERA": "Caméra",
|
||||
|
||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Appel entrant",
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
"APPS_NOTES": "Jegyzetek",
|
||||
"APPS_EXAMPLE": "Péla app",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Pia",
|
||||
"APPS_MARKETPLACE": "Pia",
|
||||
"APPS_CAMERA": "Kamera",
|
||||
|
||||
"APPS_CAMERA_FAILED_TO_TAKE_PHOTO": "Nem lehet elmenteni a képet :(",
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
"APPS_NOTES": "Notater",
|
||||
"APPS_EXAMPLE": "Example app",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Marked",
|
||||
"APPS_MARKETPLACE": "Marked",
|
||||
"APPS_CAMERA": "Kamera",
|
||||
|
||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Innkommende Anrop",
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"APPS_NOTES": "Notas",
|
||||
"APPS_EXAMPLE": "Aplicativo exemplo",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Market",
|
||||
"APPS_MARKETPLACE": "Market",
|
||||
"APPS_CAMERA": "Camera",
|
||||
|
||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Incoming Phone Call",
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
"APPS_NOTES": "Notas",
|
||||
"APPS_EXAMPLE": "Aplicativo de exemplo",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Mercado",
|
||||
"APPS_MARKETPLACE": "Mercado",
|
||||
"APPS_CAMERA": "Camera",
|
||||
|
||||
"APPS_CAMERA_FAILED_TO_TAKE_PHOTO": "Não foi possível salvar a foto :(",
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"APPS_NOTES": "Anteckningar",
|
||||
"APPS_EXAMPLE": "Exempel app",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Market",
|
||||
"APPS_MARKETPLACE": "Market",
|
||||
"APPS_CAMERA": "Camera",
|
||||
|
||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Incoming Phone Call",
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"APPS_NOTES": "Notlar",
|
||||
"APPS_EXAMPLE": "Örnek uygulama",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Market",
|
||||
"APPS_MARKETPLACE": "Market",
|
||||
"APPS_CAMERA": "Camera",
|
||||
|
||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Incoming Phone Call",
|
||||
|
||||
@@ -127,13 +127,18 @@ export const APPS: IAppConfig[] = [
|
||||
Route: () => <AppRoute id="TWITTER" path="/twitter" component={TwitterApp} emitOnOpen={true} />,
|
||||
},
|
||||
{
|
||||
id: 'SELLOUT',
|
||||
nameLocale: 'APPS_SELLOUT',
|
||||
id: 'MARKETPLACE',
|
||||
nameLocale: 'APPS_MARKETPLACE',
|
||||
backgroundColor: SELLOUT_APP_PRIMARY_COLOR,
|
||||
color: SELLOUT_APP_ICON_COLOR,
|
||||
path: '/marketplace',
|
||||
Route: () => (
|
||||
<AppRoute id="MARKETPLACE" path="/marketplace" component={MarketplaceApp} emitOnOpen={true} />
|
||||
<AppRoute
|
||||
id="MARKETPLACE"
|
||||
path="/marketplace"
|
||||
component={MarketplaceApp}
|
||||
emitOnOpen={false}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
|
||||
@@ -143,12 +143,6 @@ on(`__cfx_nui:${PhoneEvents.UI_IS_READY}`, (_data: any, cb: Function) => {
|
||||
* NUI Service Callback Registration
|
||||
*
|
||||
* * * * * * * * * * * * */
|
||||
RegisterNuiCallbackType(PhoneEvents.OPEN_APP_LISTINGS);
|
||||
on(`__cfx_nui:${PhoneEvents.OPEN_APP_LISTINGS}`, (data: any, cb: Function) => {
|
||||
emitNet(MarketplaceEvents.FETCH_LISTING);
|
||||
cb();
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(PhoneEvents.OPEN_APP_NOTES);
|
||||
on(`__cfx_nui:${PhoneEvents.OPEN_APP_NOTES}`, (data: any, cb: Function) => {
|
||||
emitNet(NotesEvents.FETCH_ALL_NOTES);
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { MarketplaceEvents, MarketPlaceBroadcastData } from '../../typings/marketplace';
|
||||
import {
|
||||
MarketplaceBroadcastAddDTO,
|
||||
MarketplaceDeleteDTO,
|
||||
MarketplaceEvents,
|
||||
} from '../../typings/marketplace';
|
||||
import { RegisterNuiProxy } from './cl_utils';
|
||||
import { sendMarketplaceEvent } from '../utils/messages';
|
||||
|
||||
@@ -8,6 +12,10 @@ RegisterNuiProxy(MarketplaceEvents.ADD_LISTING);
|
||||
RegisterNuiProxy(MarketplaceEvents.DELETE_LISTING);
|
||||
RegisterNuiProxy(MarketplaceEvents.REPORT_LISTING);
|
||||
|
||||
onNet(MarketplaceEvents.BROADCAST_EVENT, (broadcastEvent: MarketPlaceBroadcastData) => {
|
||||
sendMarketplaceEvent(MarketplaceEvents.BROADCAST_EVENT, broadcastEvent);
|
||||
onNet(MarketplaceEvents.BROADCAST_ADD, (broadcastEvent: MarketplaceBroadcastAddDTO) => {
|
||||
sendMarketplaceEvent(MarketplaceEvents.BROADCAST_ADD, broadcastEvent);
|
||||
});
|
||||
|
||||
onNet(MarketplaceEvents.BROADCAST_DELETE, (broadcastEvent: MarketplaceDeleteDTO) => {
|
||||
sendMarketplaceEvent(MarketplaceEvents.BROADCAST_DELETE, broadcastEvent);
|
||||
});
|
||||
@@ -1,40 +1,29 @@
|
||||
import {
|
||||
MarketplaceEvents,
|
||||
MarketplaceListing,
|
||||
MarketplaceListingBase,
|
||||
MarketplaceReportDTO,
|
||||
} from '../../../typings/marketplace';
|
||||
import PlayerService from '../players/player.service';
|
||||
import { selloutLogger } from './marketplace.utils';
|
||||
import MarketplaceService from './marketplace.service';
|
||||
import { onNetPromise } from '../utils/PromiseNetEvents/onNetPromise';
|
||||
import { MarketplaceDeleteDTO } from '../../../typings/marketplace';
|
||||
|
||||
onNetPromise(MarketplaceEvents.FETCH_LISTING, async (reqObj, resp) => {
|
||||
MarketplaceService.handleFetchListings(resp, reqObj.source).catch((e) => {
|
||||
onNetPromise<void, MarketplaceListing[]>(MarketplaceEvents.FETCH_LISTING, async (reqObj, resp) => {
|
||||
MarketplaceService.handleFetchListings(reqObj, resp).catch((e) => {
|
||||
selloutLogger.error(
|
||||
`Error occurred in fetch listing event (${reqObj.source}), Error: ${e.message}`,
|
||||
);
|
||||
resp({ error: true, errorMsg: '`Error occurred in fetch listing event' });
|
||||
resp({ status: 'error', errorMsg: 'INTERNAL_ERROR' });
|
||||
});
|
||||
});
|
||||
|
||||
onNetPromise<MarketplaceListingBase>(MarketplaceEvents.ADD_LISTING, async (reqObj, resp) => {
|
||||
const player = PlayerService.getPlayer(reqObj.source);
|
||||
MarketplaceService.handleAddListing(
|
||||
{
|
||||
src: reqObj.source,
|
||||
name: player.getName(),
|
||||
username: player.username,
|
||||
number: player.getPhoneNumber(),
|
||||
listing: reqObj.data,
|
||||
identifier: player.getIdentifier(),
|
||||
},
|
||||
resp,
|
||||
).catch((e) => {
|
||||
onNetPromise<MarketplaceListingBase, void>(MarketplaceEvents.ADD_LISTING, async (reqObj, resp) => {
|
||||
MarketplaceService.handleAddListing(reqObj, resp).catch((e) => {
|
||||
selloutLogger.error(
|
||||
`Error occurred in add listing event (${reqObj.source}), Error: ${e.message}`,
|
||||
);
|
||||
resp({ error: true, errorMsg: 'Error occurred in add listing event' });
|
||||
resp({ status: 'error', errorMsg: 'INTERNAL_ERROR' });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,7 +33,7 @@ onNetPromise<MarketplaceDeleteDTO>(MarketplaceEvents.DELETE_LISTING, async (reqO
|
||||
selloutLogger.error(
|
||||
`Error occurred in delete listing event (${reqObj.source}), Error: ${e.message}`,
|
||||
);
|
||||
resp({ error: true, errorMsg: 'Error occurred in delete listing event' });
|
||||
resp({ status: 'error', errorMsg: 'INTERNAL_ERROR' });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -54,6 +43,6 @@ onNetPromise<MarketplaceReportDTO>(MarketplaceEvents.REPORT_LISTING, async (reqO
|
||||
selloutLogger.error(
|
||||
`Error occurred in report listing event (${reqObj.source}), Error: ${e.message}`,
|
||||
);
|
||||
resp({ error: true, errorMsg: 'Error occured in report listing event' });
|
||||
resp({ status: 'error', errorMsg: 'INTERNAL_ERROR' });
|
||||
});
|
||||
});
|
||||
@@ -10,16 +10,7 @@ import {
|
||||
} from '../../../typings/marketplace';
|
||||
import { notesLogger } from '../notes/notes.utils';
|
||||
import { reportListingToDiscord } from '../discord';
|
||||
import { PromiseEventReturnFunc, PromiseRequest } from '../utils/PromiseNetEvents/promise.types';
|
||||
|
||||
interface HandleAddListingObj {
|
||||
src: number;
|
||||
identifier: string;
|
||||
username: string;
|
||||
name: string;
|
||||
number: any;
|
||||
listing: MarketplaceListingBase;
|
||||
}
|
||||
import { PromiseEventResp, PromiseRequest } from '../utils/PromiseNetEvents/promise.types';
|
||||
|
||||
class _MarketplaceService {
|
||||
private readonly marketplaceDB: _MarketplaceDB;
|
||||
@@ -30,60 +21,65 @@ class _MarketplaceService {
|
||||
}
|
||||
|
||||
async handleAddListing(
|
||||
{ listing, src, identifier, number, name, username }: HandleAddListingObj,
|
||||
resp: PromiseEventReturnFunc,
|
||||
reqObj: PromiseRequest<MarketplaceListingBase>,
|
||||
resp: PromiseEventResp<void>,
|
||||
): Promise<void> {
|
||||
selloutLogger.debug('Handling add listing, listing:');
|
||||
selloutLogger.debug(listing);
|
||||
selloutLogger.debug(reqObj.data);
|
||||
|
||||
const player = PlayerService.getPlayer(reqObj.source);
|
||||
|
||||
try {
|
||||
const listingId = await this.marketplaceDB.addListing(
|
||||
identifier,
|
||||
username,
|
||||
name,
|
||||
number,
|
||||
listing,
|
||||
player.getIdentifier(),
|
||||
player.username,
|
||||
player.getName(),
|
||||
player.getPhoneNumber(),
|
||||
reqObj.data,
|
||||
);
|
||||
// Respond with success to original source
|
||||
resp({ status: 'ok' });
|
||||
|
||||
const returnObj: MarketplaceListing = {
|
||||
id: listingId,
|
||||
identifier,
|
||||
name,
|
||||
number,
|
||||
url: listing.url,
|
||||
username,
|
||||
description: listing.description,
|
||||
title: listing.title,
|
||||
identifier: player.getIdentifier(),
|
||||
name: player.getName(),
|
||||
number: player.getPhoneNumber(),
|
||||
url: reqObj.data.url,
|
||||
username: player.username,
|
||||
description: reqObj.data.description,
|
||||
title: reqObj.data.title,
|
||||
};
|
||||
// Broadcast to everyone we are adding a listing
|
||||
emitNet(MarketplaceEvents.BROADCAST_EVENT, -1, { type: 'ADD', listing: returnObj });
|
||||
emitNet(MarketplaceEvents.BROADCAST_ADD, -1, { type: 'ADD', listing: returnObj });
|
||||
} catch (e) {
|
||||
selloutLogger.error(`Failed to add listing ${e.message}`, {
|
||||
source: src,
|
||||
source: reqObj.source,
|
||||
});
|
||||
|
||||
resp({ err: true, errMsg: 'Failed to create listing' });
|
||||
resp({ status: 'error', errorMsg: 'DB_ERROR' });
|
||||
}
|
||||
}
|
||||
|
||||
async handleFetchListings(resp: PromiseEventReturnFunc, src: number) {
|
||||
async handleFetchListings(
|
||||
req: PromiseRequest<void>,
|
||||
resp: PromiseEventResp<MarketplaceListing[]>,
|
||||
) {
|
||||
try {
|
||||
const listings = await this.marketplaceDB.fetchListings();
|
||||
|
||||
resp({ data: listings, status: 'ok' });
|
||||
} catch (e) {
|
||||
selloutLogger.error(`Failed to fetch listings, ${e.message}`, {
|
||||
source: src,
|
||||
source: req.source,
|
||||
});
|
||||
resp({ err: true, errMsg: 'Failed to fetch listings' });
|
||||
resp({ status: 'error', errorMsg: 'DB_ERROR' });
|
||||
}
|
||||
}
|
||||
|
||||
async handleDeleteListing(
|
||||
reqObj: PromiseRequest<MarketplaceDeleteDTO>,
|
||||
resp: PromiseEventReturnFunc,
|
||||
resp: PromiseEventResp<void>,
|
||||
): Promise<void> {
|
||||
const identifier = PlayerService.getIdentifier(reqObj.source);
|
||||
try {
|
||||
@@ -95,17 +91,17 @@ class _MarketplaceService {
|
||||
id: reqObj.data.id,
|
||||
};
|
||||
|
||||
emitNet(MarketplaceEvents.BROADCAST_EVENT, -1, { type: 'DELETE', listing: returnObj });
|
||||
emitNet(MarketplaceEvents.BROADCAST_DELETE, -1, returnObj);
|
||||
} catch (e) {
|
||||
notesLogger.error(`Error in handleDeleteListing, ${e.message}`);
|
||||
|
||||
resp({ error: true, errMsg: 'Error in deleting listing' });
|
||||
resp({ status: 'error', errorMsg: 'DB_ERROR' });
|
||||
}
|
||||
}
|
||||
|
||||
async handleReportListing(
|
||||
reqObj: PromiseRequest<MarketplaceReportDTO>,
|
||||
resp: PromiseEventReturnFunc,
|
||||
resp: PromiseEventResp<void>,
|
||||
): Promise<void> {
|
||||
try {
|
||||
const rListing = await this.marketplaceDB.getListing(reqObj.data.id);
|
||||
@@ -118,7 +114,7 @@ class _MarketplaceService {
|
||||
|
||||
if (reportExists) {
|
||||
selloutLogger.error(`This listing has already been reported`);
|
||||
resp({ error: true, errorMsg: 'Listing already exists' });
|
||||
resp({ status: 'error', errorMsg: 'REPORT_EXISTS' });
|
||||
}
|
||||
|
||||
await this.marketplaceDB.reportListing(rListing.id, rListing.name);
|
||||
@@ -127,7 +123,7 @@ class _MarketplaceService {
|
||||
selloutLogger.error(`Failed to report listing ${e.message}`, {
|
||||
source: reqObj.source,
|
||||
});
|
||||
resp({ error: true, errorMsg: 'Failed to report listing' });
|
||||
resp({ status: 'error', errorMsg: 'DB_ERROR' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ export default {
|
||||
MATCH: 'MATCH',
|
||||
MESSAGES: 'MESSAGES',
|
||||
NOTES: 'NOTES',
|
||||
MARKETPLACE: 'SELLOUT',
|
||||
MARKETPLACE: 'MARKETPLACE',
|
||||
CONTACTS: 'CONTACTS',
|
||||
CAMERA: 'CAMERA',
|
||||
};
|
||||
+6
-11
@@ -33,7 +33,12 @@ export enum MarketplaceEvents {
|
||||
REPORT_LISTING_SUCCESS = 'npwd:reportListingSuccess',
|
||||
REPORT_LISTING_SUCESS = 'npwd:reportListingFailed',
|
||||
SEND_ALERT = 'nwpd:sendListingAlert',
|
||||
BROADCAST_EVENT = 'npwd:sendMarketplaceBroadcast',
|
||||
BROADCAST_ADD = 'npwd:sendMarketplaceBroadcastAdd',
|
||||
BROADCAST_DELETE = 'npwd:sendMarketplaceBroadcastDelete',
|
||||
}
|
||||
|
||||
export interface MarketplaceBroadcastAddDTO {
|
||||
listing: MarketplaceListing;
|
||||
}
|
||||
|
||||
export interface MarketplaceDeleteDTO {
|
||||
@@ -43,13 +48,3 @@ export interface MarketplaceDeleteDTO {
|
||||
export interface MarketplaceReportDTO {
|
||||
id: number;
|
||||
}
|
||||
|
||||
export type MarketPlaceBroadcastData =
|
||||
| {
|
||||
type: 'ADD';
|
||||
listing: MarketplaceListing;
|
||||
}
|
||||
| {
|
||||
type: 'DELETE';
|
||||
listing: MarketplaceDeleteDTO;
|
||||
};
|
||||
Reference in new issue
Block a user