fix(app): emit.maxlistener issue
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 1m27s
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 1m27s
BREAKING CHANGE: moved teh middleware to call the api hits to the main app and removed from everywhere else closes #18
This commit is contained in:
54
backend/mobile/availableScanIds.route.ts
Normal file
54
backend/mobile/availableScanIds.route.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { Router } from "express";
|
||||
import { db } from "../db/db.controller.js";
|
||||
import { scanUser } from "../db/schema/scanUsers.js";
|
||||
import { settings } from "../db/schema/settings.schema.js";
|
||||
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||
|
||||
const r = Router();
|
||||
|
||||
// scanners that are dedicated to specific users.
|
||||
const SPECIAL_SCANNERS = [69, 98];
|
||||
|
||||
const buildAllowedScannerIds = (scannerCount: number) => {
|
||||
const generatedIds = Array.from({ length: scannerCount }, (_, i) => i + 1);
|
||||
|
||||
return Array.from(new Set([...generatedIds, ...SPECIAL_SCANNERS])).sort(
|
||||
(a, b) => a - b,
|
||||
);
|
||||
};
|
||||
|
||||
r.get("/", async (_, res) => {
|
||||
// get the scan users and setting
|
||||
const scanusers = await db.select().from(scanUser);
|
||||
const scannerIdSetting = await db
|
||||
.select()
|
||||
.from(settings)
|
||||
.where(eq(settings.name, "scannerIds"));
|
||||
|
||||
const usedScannerIds = scanusers.map((x) => Number(x.scannerId));
|
||||
const allowedScannerIds = buildAllowedScannerIds(
|
||||
Number(scannerIdSetting[0]?.value ?? 0),
|
||||
);
|
||||
|
||||
const availableScannerIds = allowedScannerIds.filter(
|
||||
(id) => !usedScannerIds.includes(id),
|
||||
);
|
||||
|
||||
const data = availableScannerIds.map((id) => ({
|
||||
label: `${id}`,
|
||||
value: id,
|
||||
}));
|
||||
|
||||
return apiReturn(res, {
|
||||
success: true,
|
||||
level: "info",
|
||||
module: "mobile",
|
||||
subModule: "scanner",
|
||||
message: `There are ${availableScannerIds.length} scanner id's`,
|
||||
data,
|
||||
status: 200,
|
||||
});
|
||||
});
|
||||
|
||||
export default r;
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Express } from "express";
|
||||
import { routeHitMiddleware } from "../middleware/routeHit.middleware.js";
|
||||
import available from "./availableScanIds.route.js";
|
||||
import downloads from "./downloadApps.route.js";
|
||||
import lanes from "./laneCheck.js";
|
||||
import authPin from "./mobileAuth.route.js";
|
||||
@@ -10,14 +10,13 @@ import version from "./version.route.js";
|
||||
export const setupMobileRoutes = (baseUrl: string, app: Express) => {
|
||||
//stats will be like this as we dont need to change this
|
||||
|
||||
app.use(routeHitMiddleware);
|
||||
|
||||
app.use(`${baseUrl}/api/mobile/version`, version);
|
||||
app.use(`${baseUrl}/api/mobile/apk`, downloads);
|
||||
app.use(`${baseUrl}/api/mobile/logs`, logs);
|
||||
app.use(`${baseUrl}/api/mobile/auth`, authPin);
|
||||
app.use(`${baseUrl}/api/mobile/pin`, newPin);
|
||||
app.use(`${baseUrl}/api/mobile/laneCheck`, lanes);
|
||||
app.use(`${baseUrl}/api/mobile/available`, available);
|
||||
|
||||
// all other system should be under /api/system/*
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user