Expanded mongo model
This commit is contained in:
@@ -7,8 +7,7 @@ export default class Table extends Component {
|
|||||||
super()
|
super()
|
||||||
this.scanResults = scanResults.map(row => ({
|
this.scanResults = scanResults.map(row => ({
|
||||||
...row,
|
...row,
|
||||||
id: row._id,
|
id: row._id
|
||||||
difference: row.setPrice - row.partsPrice
|
|
||||||
}))
|
}))
|
||||||
this.columns = [
|
this.columns = [
|
||||||
{
|
{
|
||||||
@@ -16,7 +15,15 @@ export default class Table extends Component {
|
|||||||
headerName: 'Name',
|
headerName: 'Name',
|
||||||
flex: 1,
|
flex: 1,
|
||||||
renderCell: (cellValues) => {
|
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>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,13 +19,18 @@ async function initDB () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const setPrice = await item.set.getPrice()
|
const setPrice = await item.set.getPrice()
|
||||||
if (partsPrice < setPrice) {
|
|
||||||
models.ScanResult.findOneAndUpdate(
|
models.ScanResult.findOneAndUpdate(
|
||||||
{ name: item.name },
|
{ name: item.name },
|
||||||
{ partsPrice, setPrice },
|
{
|
||||||
|
fullName: item.fullName,
|
||||||
|
url: item.set.url,
|
||||||
|
timestamp: new Date(),
|
||||||
|
partsPrice,
|
||||||
|
setPrice,
|
||||||
|
difference: setPrice - partsPrice
|
||||||
|
},
|
||||||
{ upsert: true },
|
{ upsert: true },
|
||||||
() => {}
|
() => {}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})()
|
})()
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
const Part = require('./Part')
|
const Part = require('./Part')
|
||||||
|
|
||||||
|
function capitalize (string) {
|
||||||
|
return string.charAt(0).toUpperCase() + string.slice(1)
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = class Item {
|
module.exports = class Item {
|
||||||
constructor (name) {
|
constructor (name) {
|
||||||
this.name = name
|
this.name = name
|
||||||
|
this.fullName = capitalize(name) + ' Prime'
|
||||||
this.set = new Part(name, 'set')
|
this.set = new Part(name, 'set')
|
||||||
|
|
||||||
this.parts = []
|
this.parts = []
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ const Api = require('../api')
|
|||||||
module.exports = class Part {
|
module.exports = class Part {
|
||||||
constructor (set, part, amount) {
|
constructor (set, part, amount) {
|
||||||
this.part = part
|
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
|
this.amount = amount ?? 1
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPrice () {
|
async getPrice () {
|
||||||
const orders = await Api.getSortedOrders(this.url)
|
const orders = await Api.getSortedOrders(this.urlPath)
|
||||||
return Number(orders[0].platinum) * this.amount
|
return Number(orders[0].platinum) * this.amount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,14 @@ const mongoose = require('mongoose')
|
|||||||
|
|
||||||
const scanResultSchema = new mongoose.Schema({
|
const scanResultSchema = new mongoose.Schema({
|
||||||
name: String,
|
name: String,
|
||||||
|
fullName: String,
|
||||||
|
url: String,
|
||||||
partsPrice: Number,
|
partsPrice: Number,
|
||||||
setPrice: Number
|
setPrice: Number,
|
||||||
|
difference: Number
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timestamps: true
|
||||||
})
|
})
|
||||||
|
|
||||||
module.exports = mongoose.models.ScanResult || mongoose.model('ScanResult', scanResultSchema)
|
module.exports = mongoose.models.ScanResult || mongoose.model('ScanResult', scanResultSchema)
|
||||||
|
|||||||
Reference in New Issue
Block a user