From 672f5f9055fec674cc56fc8f7b3ff7b54b2c90e3 Mon Sep 17 00:00:00 2001 From: piano1029 <46605242+piano1029@users.noreply.github.com> Date: Tue, 25 Jul 2023 11:27:09 -0700 Subject: [PATCH 1/2] Voeg API endpoint toe voor het ophalen van recenste order --- src/api/index.js | 49 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/src/api/index.js b/src/api/index.js index e69acf3..bd32a18 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -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) => { @@ -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[1] + + 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; From 0c3ccc972186c5a75587d09172f681f5f86b8441 Mon Sep 17 00:00:00 2001 From: piano1029 <46605242+piano1029@users.noreply.github.com> Date: Wed, 26 Jul 2023 08:47:20 -0700 Subject: [PATCH 2/2] Fix order index --- src/api/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/index.js b/src/api/index.js index bd32a18..5e29ec7 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -53,7 +53,7 @@ router.get('/orders', async (req, res) => { router.get('/order', async (req, res) => { const orders = await chief.sql`SELECT * FROM orders ORDER BY created_at DESC LIMIT 1;`; - const order = orders[1] + const order = orders[0] if ((order.flags & FLAG_SHOW_CREATOR) !== 0) { [order.creator] = await chief.sql`SELECT *