vault backup: 2023-11-06 13:58:27

This commit is contained in:
Paul Trowbridge 2023-11-06 13:58:28 -05:00
parent 55d950d010
commit 2651b40e45

27
api.ts
View File

@ -33,20 +33,27 @@ const query = await Deno.readTextFile("sql/get.pg.sql");
function apply_guidance(doc: any) { function apply_guidance(doc: any) {
if (doc["hist"]["chan.mold.v0ds.vers"] && Array.isArray(doc["hist"]["chan.mold.v0ds.vers"])) { // Iterate over each key in the "hist" object
// Loop through each element in the 'chan.mold.v0ds.vers' array for (let key of Object.keys(doc.hist)) {
for (const element of doc["hist"]["chan.mold.v0ds.vers"]) { // Update each item in the current key with the most recent price
// Process each element - 'element' is of type SeasonData updateWithMostRecentPrice(doc.hist[key]);
console.log(element); // Replace with actual processing logic
} }
} else {
// Handle the case where 'chan.mold.v0ds.vers' is not an array or doesn't exist
console.error("'chan.mold.v0ds.vers' is not an array or does not exist in the document.");
}
return doc; return doc;
} }
// Function to update each item with the most recent price
function updateWithMostRecentPrice(items) {
for (let item of items) {
// Find the most recent price
//const lastPrice = findMostRecentPrice(item.season);
const years = Object.keys(item.season);
const recentYear = Math.max(...years);
const lastPrice = item.season[recentYear].price_usd;
// Append the last_price to the item
item.last_price = lastPrice;
}
}
// Define a route to retrieve values from the database using parameters // Define a route to retrieve values from the database using parameters
router.get('/code_price/:billcode/:shipcode/:partcode/:qty', async (ctx) => { router.get('/code_price/:billcode/:shipcode/:partcode/:qty', async (ctx) => {