unistore sucks i think
This commit is contained in:
1 parent
baeaead650
commit
02aadcf2db
21 files changed
+4468
-1354
No files matched your search
+9
-34
@@ -8,40 +8,13 @@ import discogsService from './src/discogs';
|
||||
import pgService from './src/pg';
|
||||
import { logAxiosError } from './src/utils';
|
||||
import createLog from './src/log';
|
||||
import createApi from './src/api';
|
||||
|
||||
async function start(log) {
|
||||
const prisma = new PrismaClient();
|
||||
const pg = pgService(log, prisma);
|
||||
const discogs = discogsService(log, pg);
|
||||
|
||||
async function getBundles() {
|
||||
const bundles = await pg.bundleCandidates();
|
||||
|
||||
bundles.forEach(b => {
|
||||
const data = b.map(l => l.data) as any[];
|
||||
const wants = b.map(l => l.wantId);
|
||||
const total = data.reduce((acc, l) => acc + l.price.value, 0);
|
||||
const items = data.map(l => ({
|
||||
id: l.id,
|
||||
description: l.release.description,
|
||||
price: l.price.value,
|
||||
condition: l.condition,
|
||||
uri: l.uri,
|
||||
}));
|
||||
|
||||
const username = data[0]?.seller.username
|
||||
const seller = data[0]?.seller.id
|
||||
const shipsFrom = data[0]?.ships_from;
|
||||
const currency = data[0]?.price.currency;
|
||||
const shipping = data[0]?.seller.shipping;
|
||||
const mentionsAustralia = shipping.toLowerCase().includes('australia');
|
||||
const mentionsWorldwide = shipping.toLowerCase().includes('world');
|
||||
log.info({ count: b.length, currency, total, items, username, seller, shipsFrom, mentionsAustralia, mentionsWorldwide });
|
||||
});
|
||||
|
||||
// return bundles;
|
||||
}
|
||||
|
||||
const api = createApi(log, pg);
|
||||
|
||||
const usernames = [
|
||||
'vanderbabe',
|
||||
@@ -65,12 +38,14 @@ async function start(log) {
|
||||
});
|
||||
}
|
||||
|
||||
await Promise.mapSeries(usernames, async u => {
|
||||
const user = await discogs.user(u)
|
||||
return populateUserListings(user);
|
||||
});
|
||||
// await Promise.mapSeries(usernames, async u => {
|
||||
// const user = await discogs.user(u)
|
||||
// return populateUserListings(user);
|
||||
// });
|
||||
|
||||
return getBundles();
|
||||
await api.listen();
|
||||
|
||||
// return getBundles();
|
||||
}
|
||||
|
||||
async function run() {
|
||||
|
||||
Generated
+35
@@ -13,6 +13,7 @@
|
||||
"axios": "^0.27.2",
|
||||
"bluebird": "^3.7.2",
|
||||
"bunyan": "^1.8.15",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.1",
|
||||
"lodash": "^4.17.21"
|
||||
},
|
||||
@@ -397,6 +398,18 @@
|
||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
|
||||
},
|
||||
"node_modules/cors": {
|
||||
"version": "2.8.5",
|
||||
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
||||
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
|
||||
"dependencies": {
|
||||
"object-assign": "^4",
|
||||
"vary": "^1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/create-require": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
|
||||
@@ -1118,6 +1131,14 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/object-assign": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/object-inspect": {
|
||||
"version": "1.12.2",
|
||||
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz",
|
||||
@@ -1983,6 +2004,15 @@
|
||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
|
||||
},
|
||||
"cors": {
|
||||
"version": "2.8.5",
|
||||
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
||||
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
|
||||
"requires": {
|
||||
"object-assign": "^4",
|
||||
"vary": "^1"
|
||||
}
|
||||
},
|
||||
"create-require": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
|
||||
@@ -2521,6 +2551,11 @@
|
||||
"integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==",
|
||||
"dev": true
|
||||
},
|
||||
"object-assign": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg=="
|
||||
},
|
||||
"object-inspect": {
|
||||
"version": "1.12.2",
|
||||
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"axios": "^0.27.2",
|
||||
"bluebird": "^3.7.2",
|
||||
"bunyan": "^1.8.15",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.1",
|
||||
"lodash": "^4.17.21"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import express from 'express';
|
||||
import http from 'http';
|
||||
import cors from 'cors';
|
||||
|
||||
import type Log from 'bunyan';
|
||||
|
||||
import { Pg } from './pg';
|
||||
|
||||
export default function createApi(log: Log, pg: Pg) {
|
||||
const PORT = 41337;
|
||||
|
||||
const app = express();
|
||||
const server = http.createServer(app);
|
||||
|
||||
async function getBundles() {
|
||||
const bundles = await pg.bundleCandidates();
|
||||
|
||||
bundles.forEach(b => {
|
||||
const data = b.map(l => l.data) as any[];
|
||||
const wants = b.map(l => l.wantId);
|
||||
const total = data.reduce((acc, l) => acc + l.price.value, 0);
|
||||
const items = data.map(l => ({
|
||||
id: l.id,
|
||||
description: l.release.description,
|
||||
price: l.price.value,
|
||||
condition: l.condition,
|
||||
uri: l.uri,
|
||||
}));
|
||||
|
||||
const username = data[0]?.seller.username
|
||||
const seller = data[0]?.seller.id
|
||||
const shipsFrom = data[0]?.ships_from;
|
||||
const currency = data[0]?.price.currency;
|
||||
const shipping = data[0]?.seller.shipping;
|
||||
const mentionsAustralia = shipping.toLowerCase().includes('australia');
|
||||
const mentionsWorldwide = shipping.toLowerCase().includes('world');
|
||||
log.info({ count: b.length, currency, total, items, username, seller, shipsFrom, mentionsAustralia, mentionsWorldwide });
|
||||
});
|
||||
|
||||
return bundles;
|
||||
}
|
||||
|
||||
|
||||
function listen() {
|
||||
return new Promise((resolve, reject) => {
|
||||
server.on('error', err => {
|
||||
this.reject(err);
|
||||
})
|
||||
|
||||
server.listen(PORT, () => {
|
||||
log.info('listening', { PORT });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
app.use(cors());
|
||||
|
||||
app.get('/bundles', async (req, res, next) => {
|
||||
const bundles = await getBundles();
|
||||
res.json(bundles);
|
||||
})
|
||||
|
||||
return {
|
||||
app,
|
||||
listen,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user