2022-03-21 21:53:16 +00:00
|
|
|
import { pgRead, readWritePool } from './database/pg-wrapper';
|
2022-03-16 21:02:34 +00:00
|
|
|
|
|
|
|
export async function getFrontpageRaw() {
|
2022-03-21 21:53:16 +00:00
|
|
|
const client = await readWritePool.connect();
|
2022-03-24 18:08:42 +00:00
|
|
|
const res = await client.query(`
|
|
|
|
SELECT * FROM latest.combined
|
|
|
|
WHERE
|
|
|
|
(qualityindicators->>'stars')::int >= 3
|
|
|
|
AND description != ''
|
|
|
|
AND JSON_ARRAY_LENGTH(options) > 0
|
|
|
|
ORDER BY RANDOM() LIMIT 50
|
|
|
|
`);
|
2022-03-24 18:41:23 +00:00
|
|
|
|
|
|
|
return res.rows;
|
2022-03-16 21:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getFrontpageFullRaw() {
|
2022-03-24 18:08:42 +00:00
|
|
|
return await pgRead({
|
|
|
|
schema: "latest",
|
|
|
|
tableName: "combined",
|
|
|
|
});
|
2022-03-16 21:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getFrontpage() {
|
|
|
|
let frontPageForecastsCompatibleWithFuse = [];
|
|
|
|
try {
|
|
|
|
let data = await getFrontpageRaw();
|
|
|
|
frontPageForecastsCompatibleWithFuse = data.map((result) => ({
|
|
|
|
item: result,
|
|
|
|
score: 0,
|
|
|
|
}));
|
|
|
|
return frontPageForecastsCompatibleWithFuse;
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
} finally {
|
|
|
|
return frontPageForecastsCompatibleWithFuse;
|
|
|
|
}
|
|
|
|
}
|