Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions src/api/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {application, Router} from 'express';
import {gatherStats} from '../ws/util/statsUtil.js';
import {BASE_URL, FLAG_HAS_PRIORITY_MAPPING, FLAG_SHOW_CREATOR} from '../constants.js';
import { application, Router } from 'express';
import { gatherStats } from '../ws/util/statsUtil.js';
import { BASE_URL, FLAG_HAS_PRIORITY_MAPPING, FLAG_SHOW_CREATOR } from '../constants.js';

const {chief} = application;
const { chief } = application;
const router = new Router();

router.get('/stats', (req, res) => {
Expand Down Expand Up @@ -51,4 +51,45 @@ router.get('/orders', async (req, res) => {
res.json(orders);
})

router.get('/order', async (req, res) => {
const orders = await chief.sql`SELECT * FROM orders ORDER BY created_at DESC LIMIT 1;`;
const order = orders[0]

if ((order.flags & FLAG_SHOW_CREATOR) !== 0) {
[order.creator] = await chief.sql`SELECT *
FROM users
WHERE id = ${order.created_by};`;
delete order.creator.id;
} else {
order.creator = null;
}

order.images = {
order: `${BASE_URL}/orders/${order.id}.png`,
priority: (order.flags & FLAG_HAS_PRIORITY_MAPPING) !== 0 ? `${BASE_URL}/orders/${order.id}-priority.png` : null
};

order.size = {
height: order.height,
width: order.width
};

order.offset = {
x: order.offset_x,
y: order.offset_y
};

order.createdAt = order.created_at;

delete order.created_at;
delete order.created_by;
delete order.flags; // implementation detail
delete order.height;
delete order.width;
delete order.offset_x;
delete order.offset_y;

res.json(orders);
})

export default router;