Compare commits

...

2 Commits

Author SHA1 Message Date
946a9afeac Expanded mongo model 2022-03-14 01:41:52 +03:00
beb5ff052f Material UI 2022-03-14 00:29:29 +03:00
7 changed files with 1588 additions and 139 deletions

1615
app/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,11 @@
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"@emotion/react": "^11.8.2",
"@emotion/styled": "^11.8.1",
"@mui/icons-material": "^5.5.0",
"@mui/material": "^5.5.0",
"@mui/x-data-grid": "^5.6.1",
"next": "latest", "next": "latest",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",

View File

@@ -1,25 +1,63 @@
import React from 'react' import { Component } from 'react'
import ItemRow from './ItemRow' import { DataGrid } from '@mui/x-data-grid'
import { Link } from '@mui/material'
export default class Table extends React.Component { export default class Table extends Component {
constructor ({ scanResults }) { constructor ({ scanResults }) {
super() super()
this.scanResults = scanResults this.scanResults = scanResults.map(row => ({
...row,
id: row._id
}))
this.columns = [
{
field: 'name',
headerName: 'Name',
flex: 1,
renderCell: (cellValues) => {
return (
<Link
target='_blank'
href={cellValues.row.url}
rel='noreferrer'
>
{cellValues.row.fullName}
</Link>
)
}
},
{
field: 'partsPrice',
headerName: 'Parts Price',
flex: 1
},
{
field: 'setPrice',
headerName: 'Set Price',
flex: 1
},
{
field: 'difference',
headerName: 'Difference',
flex: 1
}
]
} }
render () { render () {
return ( return (
<table> <div style={{ height: '90vh', width: '100%' }}>
<thead /> <DataGrid
<tbody> rows={this.scanResults}
{this.scanResults.map((scanResult) => columns={this.columns}
<ItemRow autoPageSize
key={scanResult._id} initialState={{
scanResult={scanResult} sorting: {
/> sortModel: [{ field: 'difference', sort: 'desc' }]
)} }
</tbody> }}
</table> />
</div>
) )
} }
} }

View File

@@ -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,
{ upsert: true }, url: item.set.url,
() => {} timestamp: new Date(),
) partsPrice,
} setPrice,
difference: setPrice - partsPrice
},
{ upsert: true },
() => {}
)
} }
})() })()

View File

@@ -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 = []

View File

@@ -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
} }
} }

View File

@@ -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)