remove unused api methods
This commit is contained in:
1 parent
73248f7d9f
commit
acf7e54be9
10 files changed
+23
-201
No files matched your search
@@ -59,48 +59,6 @@ export default function createApi(log: Log, pg: Pg, discogs, offers, events) {
|
|||||||
ctx.status = 200;
|
ctx.status = 200;
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/acp/bundles', async function bundlesGet(ctx, next) {
|
|
||||||
const bundles = await offers.bundles();
|
|
||||||
ctx.response.body = bundles;
|
|
||||||
})
|
|
||||||
|
|
||||||
router.get('/acp/offers', async function acpOffers(ctx, next) {
|
|
||||||
const offers = await pg.offersAdmin();
|
|
||||||
|
|
||||||
const grouped = groupBy(offers, o => o.listing.data.seller.id);
|
|
||||||
|
|
||||||
const bundles = sortBy(Object.values(grouped).map(offers => {
|
|
||||||
const shipping = offers[0]?.listing.data.seller.shipping;
|
|
||||||
const bundle = {
|
|
||||||
username: offers[0]?.listing.data.seller.username,
|
|
||||||
seller: offers[0]?.listing.data.seller.id,
|
|
||||||
shipsFrom: offers[0]?.listing.data.ships_from,
|
|
||||||
shipping,
|
|
||||||
offers,
|
|
||||||
mentionsAustralia: shipping.toLowerCase().includes('australia'),
|
|
||||||
mentionsWorldwide: shipping.toLowerCase().includes('world'),
|
|
||||||
}
|
|
||||||
|
|
||||||
return bundle;
|
|
||||||
}), bundle => -bundle.offers.length);
|
|
||||||
|
|
||||||
ctx.response.body = bundles;
|
|
||||||
})
|
|
||||||
|
|
||||||
router.post('/offers', async function postOffers(ctx, next) {
|
|
||||||
const { listingIds, shipping, baseShipping } = ctx.request.body;
|
|
||||||
|
|
||||||
ctx.assert(listingIds.length, 400, 'listingIds required');
|
|
||||||
ctx.assert([listingIds, shipping, baseShipping].every(i => i), 400, 'listingIds, shipping, baseShipping required');
|
|
||||||
|
|
||||||
ctx.response.body = await offers.generate(listingIds, shipping, baseShipping);
|
|
||||||
})
|
|
||||||
|
|
||||||
router.post('/offer/accept', async function postOffers(ctx, next) {
|
|
||||||
ctx.assert(ctx.isAuthenticated(), 401, 'log in required');
|
|
||||||
ctx.response.body = await offers.accept(ctx);
|
|
||||||
})
|
|
||||||
|
|
||||||
router.get('/user/offers', async function userOffersGet(ctx, next) {
|
router.get('/user/offers', async function userOffersGet(ctx, next) {
|
||||||
ctx.assert(ctx.isAuthenticated(), 401, 'log in required');
|
ctx.assert(ctx.isAuthenticated(), 401, 'log in required');
|
||||||
const user = ctx.state.user;
|
const user = ctx.state.user;
|
||||||
|
|||||||
@@ -62,18 +62,6 @@ export default function createEvents(log: Log, pg: Pg, discogs, offers) {
|
|||||||
const bundles = await offers.bundles();
|
const bundles = await offers.bundles();
|
||||||
log.info({ event: Events.ListingsUpdated, bundles: bundles.length });
|
log.info({ event: Events.ListingsUpdated, bundles: bundles.length });
|
||||||
|
|
||||||
// const bundle = {
|
|
||||||
// username: b[0]?.data.seller.username,
|
|
||||||
// seller: b[0]?.data.seller.id,
|
|
||||||
// shipsFrom: b[0]?.data.ships_from,
|
|
||||||
// total,
|
|
||||||
// currency: b[0]?.data.price.currency,
|
|
||||||
// shipping: '...',
|
|
||||||
// items,
|
|
||||||
// mentionsAustralia: shipping.toLowerCase().includes('australia'),
|
|
||||||
// mentionsWorldwide: shipping.toLowerCase().includes('world'),
|
|
||||||
// }
|
|
||||||
|
|
||||||
for (const bundle of bundles) {
|
for (const bundle of bundles) {
|
||||||
log.info({ seller: bundle.seller, items: bundle.items.length }, 'generating offers...');
|
log.info({ seller: bundle.seller, items: bundle.items.length }, 'generating offers...');
|
||||||
const listingIds = bundle.items.map(i => i.id);
|
const listingIds = bundle.items.map(i => i.id);
|
||||||
|
|||||||
+12
-2
@@ -23,6 +23,10 @@ export default function createRpc(log: Log, pg: Pg, user: User, ws, discogs, off
|
|||||||
return [RpcMessageType.Pong, []];
|
return [RpcMessageType.Pong, []];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function userOffers(): Promise<OffersMessage> {
|
||||||
|
return [RpcMessageType.Offers, await pg.userOffers(user)];
|
||||||
|
}
|
||||||
|
|
||||||
async function offerStatusSet(params: OfferStatusSetParams): Promise<OffersMessage> {
|
async function offerStatusSet(params: OfferStatusSetParams): Promise<OffersMessage> {
|
||||||
const { id, status } = params;
|
const { id, status } = params;
|
||||||
assert(id, 'no id supplied');
|
assert(id, 'no id supplied');
|
||||||
@@ -70,14 +74,20 @@ export default function createRpc(log: Log, pg: Pg, user: User, ws, discogs, off
|
|||||||
switch (msgType) {
|
switch (msgType) {
|
||||||
case RpcMessageType.Ping:
|
case RpcMessageType.Ping:
|
||||||
return ping();
|
return ping();
|
||||||
|
|
||||||
|
case RpcMessageType.Offers:
|
||||||
|
return userOffers();
|
||||||
case RpcMessageType.OfferStatusSet:
|
case RpcMessageType.OfferStatusSet:
|
||||||
return offerStatusSet(params);
|
return offerStatusSet(params);
|
||||||
|
|
||||||
|
case RpcMessageType.WantRm:
|
||||||
|
return wantRm(params);
|
||||||
|
|
||||||
case RpcMessageType.AcpOfferStatusSet:
|
case RpcMessageType.AcpOfferStatusSet:
|
||||||
return acpOfferStatusSet(params);
|
return acpOfferStatusSet(params);
|
||||||
case RpcMessageType.AcpOffers:
|
case RpcMessageType.AcpOffers:
|
||||||
return acpOffers();
|
return acpOffers();
|
||||||
case RpcMessageType.WantRm:
|
|
||||||
return wantRm(params);
|
|
||||||
default:
|
default:
|
||||||
throw new Error(`Message type ${msgType} is known but unhandled`);
|
throw new Error(`Message type ${msgType} is known but unhandled`);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-7
@@ -5,13 +5,11 @@ import { Route, Router, route } from 'preact-router';
|
|||||||
import { Provider } from 'react-redux'
|
import { Provider } from 'react-redux'
|
||||||
|
|
||||||
import createWs from './ws';
|
import createWs from './ws';
|
||||||
import http from './http';
|
|
||||||
|
|
||||||
import Header from './components/header';
|
import Header from './components/header';
|
||||||
|
|
||||||
import Home from './routes/home';
|
import Offers from './routes/offers';
|
||||||
import Bundles from './routes/bundles';
|
import Acp from './routes/acp';
|
||||||
import Admin from './routes/acp';
|
|
||||||
import Login from './routes/login';
|
import Login from './routes/login';
|
||||||
import Search from './routes/search';
|
import Search from './routes/search';
|
||||||
import List from './routes/list';
|
import List from './routes/list';
|
||||||
@@ -33,15 +31,14 @@ const Main = () => {
|
|||||||
<main id="app">
|
<main id="app">
|
||||||
<Header />
|
<Header />
|
||||||
<Router>
|
<Router>
|
||||||
<Route path="/" component={Home} />
|
<Route path="/" component={Offers} />
|
||||||
<Route path="/login" component={Login} mode="login" />
|
<Route path="/login" component={Login} mode="login" />
|
||||||
<Route path="/register" component={Login} mode="register" />
|
<Route path="/register" component={Login} mode="register" />
|
||||||
<Route path="/search" component={Search} />
|
<Route path="/search" component={Search} />
|
||||||
<Route path="/list" component={List} />
|
<Route path="/list" component={List} />
|
||||||
|
|
||||||
{/* ACP */}
|
{/* ACP */}
|
||||||
<Route path="/bundles" component={Bundles} />
|
<Route path="/offers/acp" component={Acp} />
|
||||||
<Route path="/offers/acp" component={Admin} />
|
|
||||||
</Router>
|
</Router>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
import { h } from 'preact';
|
|
||||||
import { Square, CheckSquare } from 'react-feather';
|
|
||||||
import { useState, useReducer } from 'preact/hooks';
|
|
||||||
|
|
||||||
import http from '../http';
|
|
||||||
|
|
||||||
function Item(item, state, dispatch) {
|
|
||||||
const icon = state.checkedIds.includes(item.id)
|
|
||||||
? <CheckSquare onClick={() => dispatch({ id: item.id})} />
|
|
||||||
: <Square onClick={() => dispatch({ id: item.id})} />;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div key={item.id}>
|
|
||||||
<a href={item.uri} target="_blank" >
|
|
||||||
<h4>{item.description}</h4>
|
|
||||||
</a>
|
|
||||||
<h5 class='alt-text'>{item.price.toFixed(2)} {item.currency}</h5>
|
|
||||||
{icon}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const reducer = (state, action) => {
|
|
||||||
if (state.checkedIds.includes(action.id)) {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
checkedIds: state.checkedIds.filter(id => id !== action.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
checkedIds: [
|
|
||||||
...state.checkedIds,
|
|
||||||
action.id
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Bundle(bundle) {
|
|
||||||
const initialState = { checkedIds: bundle.items.map(i => i.id) }
|
|
||||||
const [state, dispatch] = useReducer(reducer, initialState)
|
|
||||||
|
|
||||||
const items = bundle.items.map(item => Item(item, state, dispatch));
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div class="bundle">
|
|
||||||
<section>
|
|
||||||
<h2>{bundle.username} - {bundle.seller}</h2>
|
|
||||||
<h3>{bundle.items.length} items - {bundle.total.toFixed(2)} {bundle.currency}</h3>
|
|
||||||
<h4>Ships: {bundle.mentionsAustralia && 'AU'} {bundle.mentionsWorldwide && 'WORLD'}</h4>
|
|
||||||
</section>
|
|
||||||
<div class='items'>
|
|
||||||
{items}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -37,7 +37,6 @@ const Header = () => {
|
|||||||
|
|
||||||
const adminNav = () => (
|
const adminNav = () => (
|
||||||
<nav>
|
<nav>
|
||||||
<a href="/bundles">Bundles</a>
|
|
||||||
<a href='/offers/acp'>Offers ACP</a>
|
<a href='/offers/acp'>Offers ACP</a>
|
||||||
</nav>
|
</nav>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
import { h } from 'preact';
|
|
||||||
import { useState, useEffect } from 'preact/hooks';
|
|
||||||
|
|
||||||
import http from './../http';
|
|
||||||
import Bundle from './../components/bundle';
|
|
||||||
|
|
||||||
function Bundles() {
|
|
||||||
const [bundles, setBundles] = useState([]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
async function getBundles() {
|
|
||||||
const [error, bundles] = await http.getBundles();
|
|
||||||
if (error) return console.error(error);
|
|
||||||
setBundles(bundles);
|
|
||||||
}
|
|
||||||
getBundles();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (!bundles.length) {
|
|
||||||
return (
|
|
||||||
<div class={'bundles'}>
|
|
||||||
loading...
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div class={'bundles'}>
|
|
||||||
{bundles.map(Bundle)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Bundles;
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
import { h } from 'preact';
|
|
||||||
import { useState, useEffect } from 'preact/hooks';
|
|
||||||
import { route } from 'preact-router';
|
|
||||||
import { useSelector, useDispatch } from 'react-redux'
|
|
||||||
|
|
||||||
import http from './../http';
|
|
||||||
import { State, offersState } from './../store';
|
|
||||||
|
|
||||||
import Offer from './../components/offer';
|
|
||||||
|
|
||||||
function Home() {
|
|
||||||
const dispatch = useDispatch()
|
|
||||||
const offers = useSelector((state: State) => state.offers);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
async function getOffers() {
|
|
||||||
const [error, offers] = await http.getOffers();
|
|
||||||
if (error) return console.error(error);
|
|
||||||
dispatch(offersState.actions.set(offers));
|
|
||||||
if (offers.length === 0) route('/search');
|
|
||||||
}
|
|
||||||
getOffers();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (!offers.length) {
|
|
||||||
return (
|
|
||||||
<div class={'offers'}>
|
|
||||||
loading...
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div class={'offers'}>
|
|
||||||
{offers.map(Offer)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Home;
|
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
import { h } from 'preact';
|
import { h } from 'preact';
|
||||||
import { useState, useEffect } from 'preact/hooks';
|
|
||||||
|
|
||||||
import { useSelector } from 'react-redux'
|
import { useSelector } from 'react-redux'
|
||||||
import { State } from './../store'
|
import { State } from './../store'
|
||||||
|
|
||||||
// import style from './style.less';
|
|
||||||
import http from './../http';
|
|
||||||
import Want from './../components/want';
|
import Want from './../components/want';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ export default function createSocket(dispatch) {
|
|||||||
send(['WantRm', { id }]);
|
send(['WantRm', { id }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendOffers() {
|
||||||
|
send(['Offers', {}]);
|
||||||
|
}
|
||||||
|
|
||||||
function sendAcpOffers() {
|
function sendAcpOffers() {
|
||||||
send(['AcpOffers', {}]);
|
send(['AcpOffers', {}]);
|
||||||
}
|
}
|
||||||
@@ -104,6 +108,7 @@ export default function createSocket(dispatch) {
|
|||||||
console.log('websocket connected', SOCKET_URL)
|
console.log('websocket connected', SOCKET_URL)
|
||||||
sendPing();
|
sendPing();
|
||||||
sendAcpOffers();
|
sendAcpOffers();
|
||||||
|
sendOffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onError(event) {
|
function onError(event) {
|
||||||
@@ -143,6 +148,8 @@ export default function createSocket(dispatch) {
|
|||||||
sendOfferStatusSet,
|
sendOfferStatusSet,
|
||||||
sendWantRm,
|
sendWantRm,
|
||||||
|
|
||||||
|
sendOffers,
|
||||||
|
|
||||||
sendAcpOffers,
|
sendAcpOffers,
|
||||||
sendAcpOfferStatusSet,
|
sendAcpOfferStatusSet,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user