offers wip
This commit is contained in:
1 parent
453c2da045
commit
deb9eb3fc2
16 files changed
+276
-88
No files matched your search
+14
-14
@@ -16,7 +16,7 @@ import { Pg } from './pg';
|
||||
import routerAuth from './routers/router.auth';
|
||||
import { Events } from './events';
|
||||
|
||||
export default function createApi(log: Log, pg: Pg, discogs, events) {
|
||||
export default function createApi(log: Log, pg: Pg, discogs, offers, events) {
|
||||
const PORT = 41337;
|
||||
const SECRET = 'ohja4Eif9eidah3aj5ta2haa4iemooth';
|
||||
|
||||
@@ -46,13 +46,14 @@ export default function createApi(log: Log, pg: Pg, discogs, events) {
|
||||
const bundles = await pg.bundleCandidates();
|
||||
|
||||
return bundles.map((b: ListingData[]) => {
|
||||
const total = b.reduce((acc, l) => acc + l.data.original_price.value, 0);
|
||||
|
||||
const total = b.reduce((acc, l) => acc + l.data.price.value, 0);
|
||||
const items = b.map(l => ({
|
||||
id: l.data.id,
|
||||
description: l.data.release.description,
|
||||
price: l.data.original_price.value,
|
||||
currency: l.data.original_price.curr_abbr,
|
||||
originalPrice: l.data.original_price.value,
|
||||
originalCurrency: l.data.original_price.curr_abbr,
|
||||
price: l.data.price.value,
|
||||
currency: l.data.price.currency,
|
||||
condition: l.data.condition,
|
||||
uri: l.data.uri,
|
||||
user: l.want.user,
|
||||
@@ -65,7 +66,7 @@ export default function createApi(log: Log, pg: Pg, discogs, events) {
|
||||
seller: b[0]?.data.seller.id,
|
||||
shipsFrom: b[0]?.data.ships_from,
|
||||
total,
|
||||
currency: b[0]?.data.original_price.curr_abbr,
|
||||
currency: b[0]?.data.price.currency,
|
||||
shipping: '...',
|
||||
items,
|
||||
mentionsAustralia: shipping.toLowerCase().includes('australia'),
|
||||
@@ -108,17 +109,16 @@ export default function createApi(log: Log, pg: Pg, discogs, events) {
|
||||
ctx.response.body = bundles;
|
||||
})
|
||||
|
||||
router.post('/offers', async (ctx, next) => {
|
||||
const { seller, shipping, baseShipping } = ctx.request.body;
|
||||
ctx.response.body = await offers.generate(seller, shipping, baseShipping);
|
||||
})
|
||||
|
||||
router.get('/user/offers', async function userOffersGet(ctx, next) {
|
||||
ctx.assert(ctx.isAuthenticated(), 401, 'log in required');
|
||||
const user = ctx.state.user;
|
||||
const bundles = (await getBundles())
|
||||
.map(b => {
|
||||
b.items = b.items.filter(i => i.user.id === user.id);
|
||||
return b;
|
||||
})
|
||||
.filter(b => b.items.length);
|
||||
|
||||
ctx.response.body = bundles;
|
||||
const offers = await pg.userOffers(user);
|
||||
ctx.response.body = offers;
|
||||
});
|
||||
|
||||
router.post('/want', async function wantPost(ctx, next) {
|
||||
|
||||
Reference in new issue
Block a user