offers page
This commit is contained in:
1 parent
323c7877b1
commit
453c2da045
13 files changed
+123
-128
No files matched your search
+4
-31
@@ -76,23 +76,6 @@ export default function createApi(log: Log, pg: Pg, discogs, events) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async function populateUserListings(user: User) {
|
||||
const wants = await discogs.wantlist(user);
|
||||
|
||||
// const latest = await discogs.wantlistLatest(user);
|
||||
// if (wants.length !== latest.length)
|
||||
|
||||
log.debug({ username: user.discogs, wantCount: wants.length });
|
||||
|
||||
return Bluebird.mapSeries<Want, Listing[]>(wants, async want => {
|
||||
const listings = await discogs.listings(want);
|
||||
const populated = listings.filter(l => l);
|
||||
log.debug({ id: want.id, release: want.release, populated: populated.length, total: listings.length });
|
||||
return populated;
|
||||
});
|
||||
}
|
||||
|
||||
function listen() {
|
||||
return new Promise((resolve, reject) => {
|
||||
app.on('error', err => {
|
||||
@@ -125,15 +108,12 @@ export default function createApi(log: Log, pg: Pg, discogs, events) {
|
||||
ctx.response.body = bundles;
|
||||
})
|
||||
|
||||
router.get('/user/:id/offers', async function userOffersGet(ctx, next) {
|
||||
const { id } = ctx.request.params;
|
||||
const user = await pg.userFindId(id);
|
||||
|
||||
ctx.assert(user, 404, `user ${id} not found`);
|
||||
|
||||
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)
|
||||
b.items = b.items.filter(i => i.user.id === user.id);
|
||||
return b;
|
||||
})
|
||||
.filter(b => b.items.length);
|
||||
@@ -141,13 +121,6 @@ export default function createApi(log: Log, pg: Pg, discogs, events) {
|
||||
ctx.response.body = bundles;
|
||||
});
|
||||
|
||||
router.post('/user/populate', async function usersPopulate(ctx, next) {
|
||||
const { userId } = ctx.request.body;
|
||||
const user = await pg.userFindId(userId);
|
||||
const listings = await populateUserListings(user);
|
||||
ctx.response.body = listings;
|
||||
});
|
||||
|
||||
router.post('/want', async function wantPost(ctx, next) {
|
||||
ctx.assert(ctx.isAuthenticated(), 401, 'log in required');
|
||||
const { releaseId } = ctx.request.body;
|
||||
|
||||
Reference in new issue
Block a user