diff --git a/backend/src/app.ts b/backend/src/app.ts
index 5f50c87..13ebca8 100644
--- a/backend/src/app.ts
+++ b/backend/src/app.ts
@@ -6,6 +6,7 @@ import { OrderByParser, FilterParser } from './tokenizer'
import { addGameApis } from './gameservice'
import { addCharacterApis } from './characterservice'
import { addRushStatsApis } from './rushstatsservice'
+import { addDmApis } from './dmservice'
const app = express()
const jsonParser = json()
@@ -14,7 +15,7 @@ const port = 3001
addGameApis(app, jsonParser)
addCharacterApis(app, jsonParser)
addRushStatsApis(app, jsonParser)
-
+addDmApis(app, jsonParser)
app.use(express.static(__dirname + '/frontend'))
app.use('/', (req, res) => {
diff --git a/backend/src/characterservice.ts b/backend/src/characterservice.ts
index 7cce42c..1750d46 100644
--- a/backend/src/characterservice.ts
+++ b/backend/src/characterservice.ts
@@ -5,7 +5,7 @@ export function addCharacterApis(app, jsonParser) {
app.get('/api/character/:characterId', async (req, res) => {
try {
const character = await Character.findOne({
- attributes: ["id", "characterName", "playerName", "role", "creationDate", "status"],
+ attributes: ['id', 'characterName', 'playerName', 'role', 'creationDate', 'status'],
where: { id: req.params['characterId'] }
})
if (character) {
@@ -35,11 +35,9 @@ export function addCharacterApis(app, jsonParser) {
where: filter
})
const totalCount = await Character.count({
- where: filter
- })
- const pageCount = Math.ceil(
- totalCount / count
- )
+ where: filter
+ })
+ const pageCount = Math.ceil(totalCount / count)
res.setHeader('Content-Type', 'application/json')
res.send({ characterData, pageCount, totalCount })
diff --git a/backend/src/dmservice.ts b/backend/src/dmservice.ts
new file mode 100644
index 0000000..3bb3dad
--- /dev/null
+++ b/backend/src/dmservice.ts
@@ -0,0 +1,58 @@
+import { database, Character, Game, Pick, App } from './db'
+import { OrderByParser, FilterParser, ParsingError } from './tokenizer'
+import { fn, col } from 'sequelize'
+
+export function addDmApis(app, jsonParser) {
+ app.get('/api/dm/:dmName', async (req, res) => {
+ const dmName = req.params.dmName
+
+ let games = await Game.findAll({
+ where: { gamemaster: dmName }
+ })
+
+ res.send(games)
+ })
+
+ app.post('/api/dm', jsonParser, async (req, res) => {
+ try {
+ const fp = new FilterParser()
+ const obp = new OrderByParser()
+
+ const page = req.body.page || 0
+ const orderBy = req.body.orderBy ? obp.parse(req.body.orderBy) : ['id']
+ const count = req.body.count || 10
+ const filter = req.body.filter ? fp.parse(req.body.filter) : {}
+
+ const dms = await Game.findAll({
+ offset: page * count,
+ limit: count,
+ attributes: ['gamemaster', [fn('count', col('id')), 'gamecount']],
+ group: ['gamemaster'],
+ order: orderBy,
+ where: filter
+ })
+
+ const totalCount = (
+ await Game.count({
+ group: ['gamemaster'],
+ where: filter
+ })
+ ).length
+
+ const pageCount = Math.ceil(totalCount / count)
+
+ res.setHeader('Content-Type', 'application/json')
+ res.send({
+ dms,
+ pageCount,
+ totalCount
+ })
+ } catch (e) {
+ if (e instanceof ParsingError) {
+ res.status(400).send('Could not parse filter.')
+ } else {
+ res.status(500).send(e)
+ }
+ }
+ })
+}
diff --git a/backend/src/gameservice.ts b/backend/src/gameservice.ts
index 96140f7..24d6738 100644
--- a/backend/src/gameservice.ts
+++ b/backend/src/gameservice.ts
@@ -33,11 +33,9 @@ export function addGameApis(app, jsonParser) {
where: filter
})
const totalCount = await Game.count({
- where: filter
- })
- const pageCount = Math.ceil(
- totalCount / count
- )
+ where: filter
+ })
+ const pageCount = Math.ceil(totalCount / count)
res.setHeader('Content-Type', 'application/json')
res.send({ gameData, pageCount, totalCount })
diff --git a/backend/src/tokenizer.ts b/backend/src/tokenizer.ts
index 5a4fe83..fde9ee2 100644
--- a/backend/src/tokenizer.ts
+++ b/backend/src/tokenizer.ts
@@ -98,7 +98,6 @@ export class FilterParser {
ctx.accept('value', m[3])
})
-
this.lexer.rule(spacerRegex, (ctx, m) => {
ctx.ignore()
})
diff --git a/frontend/src/vues/DmList.vue b/frontend/src/vues/DmList.vue
new file mode 100644
index 0000000..7401387
--- /dev/null
+++ b/frontend/src/vues/DmList.vue
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
\ No newline at end of file