Migrate to yarn
This commit is contained in:
40
gather/src/index.ts
Normal file
40
gather/src/index.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
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()
|
||||
})()
|
||||
Reference in New Issue
Block a user