tokenizer works

This commit is contained in:
jmosrael@gmail.com
2024-05-17 19:59:17 -07:00
parent 3094ae3a08
commit 401330d842
2 changed files with 55 additions and 85 deletions

View File

@@ -2,10 +2,12 @@ import express from 'express'
import { json } from 'body-parser'
import { Sequelize, Op } from 'sequelize'
import { database, Character, Game, Pick, App } from './db'
import { lexr, parseOrderByString, FilterParser } from './tokenizer'
import { OrderByParser, FilterParser } from './tokenizer'
const app = express()
const jsonParser = json()
const fp = new FilterParser()
const obp = new OrderByParser()
const port = 3001
app.get('/', (req, res) => {
@@ -36,34 +38,19 @@ app.get('/api/game/:gameId', async (req, res) => {
})
app.post('/api/game', jsonParser, async (req, res) => {
console.log(req.body)
const page = req.body.page || 0
const orderBy = req.body.orderBy ? parseOrderByString(req.body.orderBy) : ['id']
const orderBy = req.body.orderBy ? obp.parse(req.body.orderBy) : ['id']
const count = req.body.count || 10
const filter = req.body.filter || ''
const filter = req.body.filter ? fp.parse(req.body.filter) : {}
const gameData = await Game.findAll({
offset: page * count,
limit: count,
order: orderBy,
where: {
id: { [Op.eq]: 2 }
}
where: filter
})
const pageCount = Math.ceil((await Character.count()) / count)
let fp = new FilterParser()
fp.lexer
.input(filter)
.tokens()
.forEach((t) => {
console.log(t)
})
console.log(fp.parseFilter(filter))
res.setHeader('Content-Type', 'application/json')
res.send({ gameData, pageCount })
})