41 lines
897 B
TypeScript
41 lines
897 B
TypeScript
import mongoose from 'mongoose'
|
|
import items from './items'
|
|
import { models } from 'shared-stuff'
|
|
import 'dotenv/config'
|
|
|
|
async function initDB (): Promise<void> {
|
|
await mongoose.connect(String(process.env.MONGODB_URI))
|
|
}
|
|
|
|
(async () => {
|
|
await initDB()
|
|
|
|
for (const item of items) {
|
|
process.stdout.write(`Looking at ${item.name}: `)
|
|
|
|
let partsPrice = 0
|
|
for (const part of item.parts) {
|
|
process.stdout.write(`${part.part} `)
|
|
partsPrice += await part.getPrice()
|
|
}
|
|
|
|
const setPrice = await item.set.getPrice()
|
|
await models.ScanResult.findOneAndUpdate(
|
|
{ name: item.name },
|
|
{
|
|
fullName: item.fullName,
|
|
url: item.set.url,
|
|
timestamp: new Date(),
|
|
partsPrice,
|
|
setPrice,
|
|
difference: setPrice - partsPrice
|
|
},
|
|
{ upsert: true }
|
|
)
|
|
|
|
console.log('✅')
|
|
}
|
|
|
|
await mongoose.disconnect()
|
|
})()
|