Expanded mongo model

This commit is contained in:
2022-03-14 01:41:52 +03:00
parent beb5ff052f
commit 946a9afeac
5 changed files with 38 additions and 14 deletions

View File

@@ -7,8 +7,7 @@ export default class Table extends Component {
super()
this.scanResults = scanResults.map(row => ({
...row,
id: row._id,
difference: row.setPrice - row.partsPrice
id: row._id
}))
this.columns = [
{
@@ -16,7 +15,15 @@ export default class Table extends Component {
headerName: 'Name',
flex: 1,
renderCell: (cellValues) => {
return <Link href={`#${cellValues.row.url}`}>{cellValues.row.name}</Link>
return (
<Link
target='_blank'
href={cellValues.row.url}
rel='noreferrer'
>
{cellValues.row.fullName}
</Link>
)
}
},
{

View File

@@ -19,13 +19,18 @@ async function initDB () {
}
const setPrice = await item.set.getPrice()
if (partsPrice < setPrice) {
models.ScanResult.findOneAndUpdate(
{ name: item.name },
{ partsPrice, setPrice },
{ upsert: true },
() => {}
)
}
models.ScanResult.findOneAndUpdate(
{ name: item.name },
{
fullName: item.fullName,
url: item.set.url,
timestamp: new Date(),
partsPrice,
setPrice,
difference: setPrice - partsPrice
},
{ upsert: true },
() => {}
)
}
})()

View File

@@ -1,8 +1,13 @@
const Part = require('./Part')
function capitalize (string) {
return string.charAt(0).toUpperCase() + string.slice(1)
}
module.exports = class Item {
constructor (name) {
this.name = name
this.fullName = capitalize(name) + ' Prime'
this.set = new Part(name, 'set')
this.parts = []

View File

@@ -3,12 +3,13 @@ const Api = require('../api')
module.exports = class Part {
constructor (set, part, amount) {
this.part = part
this.url = `${set}_prime_${part}`
this.urlPath = `${set}_prime_${part}`
this.url = `https://warframe.market/items/${set}_prime_${part}`
this.amount = amount ?? 1
}
async getPrice () {
const orders = await Api.getSortedOrders(this.url)
const orders = await Api.getSortedOrders(this.urlPath)
return Number(orders[0].platinum) * this.amount
}
}

View File

@@ -2,8 +2,14 @@ const mongoose = require('mongoose')
const scanResultSchema = new mongoose.Schema({
name: String,
fullName: String,
url: String,
partsPrice: Number,
setPrice: Number
setPrice: Number,
difference: Number
},
{
timestamps: true
})
module.exports = mongoose.models.ScanResult || mongoose.model('ScanResult', scanResultSchema)