This commit is contained in:
seb
2026-11-01 00:38:04 +01:00
parent 8827d6fc14
commit 5d6b31de15
5 changed files with 1 additions and 32 deletions

View File

@@ -232,7 +232,6 @@ export function notifyAgentJob(agentId, action, job) {
for (const clientRes of conns) { for (const clientRes of conns) {
if (!clientRes.writableEnded) { if (!clientRes.writableEnded) {
clientRes.write(`event: job\ndata: ${payload}\n\n`); clientRes.write(`event: job\ndata: ${payload}\n\n`);
clientRes.write(`event: printerjob\ndata: ${payload}\n\n`);
clientRes.flush?.(); clientRes.flush?.();
} }
} }
@@ -407,14 +406,11 @@ async function handleState(req, res) {
if (rawState?.job?.id && rawState?.job?.state) { if (rawState?.job?.id && rawState?.job?.state) {
try { try {
const updatedJob = await printerjobDb.updateState( await printerjobDb.updateState(
{ agentId: req.agent.id }, { agentId: req.agent.id },
rawState.job.id, rawState.job.id,
rawState.job.state rawState.job.state
); );
if (req.agent?.companyId) {
emit('printerjob', { companyId: req.agent.companyId, data: { job: updatedJob } });
}
} catch (jobErr) { } catch (jobErr) {
log.debug(`Agent reported job state update for ${rawState.job.id}:`, jobErr?.message); log.debug(`Agent reported job state update for ${rawState.job.id}:`, jobErr?.message);
} }
@@ -486,9 +482,6 @@ agentRouter.get('/jobs/:id', agentAuthMiddleware, async (req, res) => {
agentRouter.post('/jobs/:id/processing', agentAuthMiddleware, async (req, res) => { agentRouter.post('/jobs/:id/processing', agentAuthMiddleware, async (req, res) => {
try { try {
const job = await printerjobDb.updateState({ agentId: req.agent.id }, req.params.id, 'processing'); const job = await printerjobDb.updateState({ agentId: req.agent.id }, req.params.id, 'processing');
if (req.agent?.companyId) {
emit('printerjob', { companyId: req.agent.companyId, data: { job } });
}
res.status(200).json({ success: true, job }); res.status(200).json({ success: true, job });
} catch (err) { } catch (err) {
if (err.message === 'Printerjob not found') return res.status(404).json({ error: err.message }); if (err.message === 'Printerjob not found') return res.status(404).json({ error: err.message });
@@ -500,9 +493,6 @@ agentRouter.post('/jobs/:id/processing', agentAuthMiddleware, async (req, res) =
agentRouter.post('/jobs/:id/completed', agentAuthMiddleware, async (req, res) => { agentRouter.post('/jobs/:id/completed', agentAuthMiddleware, async (req, res) => {
try { try {
const job = await printerjobDb.updateState({ agentId: req.agent.id }, req.params.id, 'completed'); const job = await printerjobDb.updateState({ agentId: req.agent.id }, req.params.id, 'completed');
if (req.agent?.companyId) {
emit('printerjob', { companyId: req.agent.companyId, data: { job } });
}
res.status(200).json({ success: true, job }); res.status(200).json({ success: true, job });
} catch (err) { } catch (err) {
if (err.message === 'Printerjob not found') return res.status(404).json({ error: err.message }); if (err.message === 'Printerjob not found') return res.status(404).json({ error: err.message });
@@ -518,9 +508,6 @@ agentRouter.patch('/jobs/:id', agentAuthMiddleware, async (req, res) => {
} }
try { try {
const job = await printerjobDb.updateState({ agentId: req.agent.id }, req.params.id, state); const job = await printerjobDb.updateState({ agentId: req.agent.id }, req.params.id, state);
if (req.agent?.companyId) {
emit('printerjob', { companyId: req.agent.companyId, data: { job } });
}
res.status(200).json({ success: true, job }); res.status(200).json({ success: true, job });
} catch (err) { } catch (err) {
if (err.message === 'Printerjob not found') return res.status(404).json({ error: err.message }); if (err.message === 'Printerjob not found') return res.status(404).json({ error: err.message });

View File

@@ -7,7 +7,6 @@ import * as printerDb from '../../../db/printer.js';
import * as agentprinterDb from '../../../db/agentprinter.js'; import * as agentprinterDb from '../../../db/agentprinter.js';
import * as labeltemplateDb from '../../../db/labeltemplate.js'; import * as labeltemplateDb from '../../../db/labeltemplate.js';
import * as printerjobDb from '../../../db/printerjob.js'; import * as printerjobDb from '../../../db/printerjob.js';
import { emit } from '../../sse.js';
import { notifyAgentJob } from '../../agent/index.js'; import { notifyAgentJob } from '../../agent/index.js';
import { pngToZpl } from '../../../services/zplService.js'; import { pngToZpl } from '../../../services/zplService.js';
import { applyZplCopies } from '../zpljob.js'; import { applyZplCopies } from '../zpljob.js';
@@ -481,7 +480,6 @@ export function register(app, basePath = '') {
notifyAgentJob(job.printeragentId, 'created', job); notifyAgentJob(job.printeragentId, 'created', job);
} }
emit('printerjob', { companyId, data: { job } });
return res.status(200).json({ success: true, printerjob: job }); return res.status(200).json({ success: true, printerjob: job });
} }

View File

@@ -57,7 +57,6 @@ export function register(app, basePath = '') {
* | `printer` | `{}` | `POST /printer`, `PUT /printer/{id}`, `PATCH /printer/{id}`, `DELETE /printer/{id}` | * | `printer` | `{}` | `POST /printer`, `PUT /printer/{id}`, `PATCH /printer/{id}`, `DELETE /printer/{id}` |
* | `printeragent` | `{}` | `PUT /printeragent`, `PATCH /printeragent/{id}`, `DELETE /printeragent/{id}`, printer agent connect/disconnect/state | * | `printeragent` | `{}` | `PUT /printeragent`, `PATCH /printeragent/{id}`, `DELETE /printeragent/{id}`, printer agent connect/disconnect/state |
* | `agentprinter` | `{ printers }` or `{}` | `PATCH /agentprinter/{id}`, `PUT /agentprinter/order`, `DELETE /agentprinter/{id}`, agent state updates / printer discovery | * | `agentprinter` | `{ printers }` or `{}` | `PATCH /agentprinter/{id}`, `PUT /agentprinter/order`, `DELETE /agentprinter/{id}`, agent state updates / printer discovery |
* | `printerjob` | `{ job }` or `{ jobId, state }` | `POST /zpljob`, `POST /printerjob`, `POST /printerjob/{id}/cancel`, `DELETE /printerjob/{id}`, agent job state updates |
* | `warehouse` | `{}` | `POST /warehouse`, `PUT /warehouse/{id}`, `PATCH /warehouse/{id}`, `DELETE /warehouse/{id}` | * | `warehouse` | `{}` | `POST /warehouse`, `PUT /warehouse/{id}`, `PATCH /warehouse/{id}`, `DELETE /warehouse/{id}` |
* | `supplier` | `{}` | `POST /supplier`, `PATCH /supplier/{id}`, `DELETE /supplier/{id}` | * | `supplier` | `{}` | `POST /supplier`, `PATCH /supplier/{id}`, `DELETE /supplier/{id}` |
* | `vfs` | `{}` | VFS uploads and filesystem mutations such as `POST /vfs/upload`, `POST /vfs/mkdir`, `POST /vfs/rename`, `PUT /vfs/{*path}`, `DELETE /vfs/{*path}` | * | `vfs` | `{}` | VFS uploads and filesystem mutations such as `POST /vfs/upload`, `POST /vfs/mkdir`, `POST /vfs/rename`, `PUT /vfs/{*path}`, `DELETE /vfs/{*path}` |

View File

@@ -1,5 +1,4 @@
import * as printerjobDb from '../../db/printerjob.js'; import * as printerjobDb from '../../db/printerjob.js';
import { emit } from '../sse.js';
import { notifyAgentJob } from '../agent/index.js'; import { notifyAgentJob } from '../agent/index.js';
// #region Helpers // #region Helpers
@@ -188,7 +187,6 @@ export function register(app, basePath = '') {
* description: Creates a new print job for an agent printer. Notifies the agent in real time. * description: Creates a new print job for an agent printer. Notifies the agent in real time.
* security: * security:
* - cookieAuth: [] * - cookieAuth: []
* x-signals: [printerjob]
* requestBody: * requestBody:
* required: true * required: true
* content: * content:
@@ -249,7 +247,6 @@ export function register(app, basePath = '') {
notifyAgentJob(job.printeragentId, 'created', job); notifyAgentJob(job.printeragentId, 'created', job);
} }
emit('printerjob', { companyId: selected.companyId, data: { job } });
res.status(201).json({ printerjob: job }); res.status(201).json({ printerjob: job });
} catch (error) { } catch (error) {
const status = printerjobErrorStatus(error); const status = printerjobErrorStatus(error);
@@ -271,7 +268,6 @@ export function register(app, basePath = '') {
* Notifies connected agents in real time. * Notifies connected agents in real time.
* security: * security:
* - cookieAuth: [] * - cookieAuth: []
* x-signals: [printerjob]
* requestBody: * requestBody:
* content: * content:
* application/json: * application/json:
@@ -318,7 +314,6 @@ export function register(app, basePath = '') {
if (job.printeragentId) { if (job.printeragentId) {
notifyAgentJob(job.printeragentId, 'cancelled', job); notifyAgentJob(job.printeragentId, 'cancelled', job);
} }
emit('printerjob', { companyId: selected.companyId, data: { job } });
cancelledJobs.push(job); cancelledJobs.push(job);
} catch (e) { } catch (e) {
console.error(`Failed to cancel printerjob #${j.id}:`, e); console.error(`Failed to cancel printerjob #${j.id}:`, e);
@@ -348,7 +343,6 @@ export function register(app, basePath = '') {
* description: Marks a print job as cancelled and notifies the connected agent in real time. * description: Marks a print job as cancelled and notifies the connected agent in real time.
* security: * security:
* - cookieAuth: [] * - cookieAuth: []
* x-signals: [printerjob]
* parameters: * parameters:
* - in: path * - in: path
* name: id * name: id
@@ -388,7 +382,6 @@ export function register(app, basePath = '') {
notifyAgentJob(job.printeragentId, 'cancelled', job); notifyAgentJob(job.printeragentId, 'cancelled', job);
} }
emit('printerjob', { companyId: selected.companyId, data: { job } });
res.status(200).json({ success: true, printerjob: job }); res.status(200).json({ success: true, printerjob: job });
} catch (error) { } catch (error) {
const status = printerjobErrorStatus(error); const status = printerjobErrorStatus(error);
@@ -410,7 +403,6 @@ export function register(app, basePath = '') {
* event to the connected printer agent before deletion. * event to the connected printer agent before deletion.
* security: * security:
* - cookieAuth: [] * - cookieAuth: []
* x-signals: [printerjob]
* parameters: * parameters:
* - in: path * - in: path
* name: id * name: id
@@ -450,10 +442,6 @@ export function register(app, basePath = '') {
notifyAgentJob(job.printeragentId, 'cancelled', job); notifyAgentJob(job.printeragentId, 'cancelled', job);
} }
emit('printerjob', {
companyId: selected.companyId,
data: { jobId: job.id, state: 'cancelled' },
});
res.status(200).json({ success: true, deletedJob: job }); res.status(200).json({ success: true, deletedJob: job });
} catch (error) { } catch (error) {
const status = printerjobErrorStatus(error); const status = printerjobErrorStatus(error);

View File

@@ -1,5 +1,4 @@
import * as printerjobDb from '../../db/printerjob.js'; import * as printerjobDb from '../../db/printerjob.js';
import { emit } from '../sse.js';
import { notifyAgentJob } from '../agent/index.js'; import { notifyAgentJob } from '../agent/index.js';
// #region Helpers // #region Helpers
@@ -73,7 +72,6 @@ export function register(app, basePath = '') {
* is automatically applied. The connected printer agent receives an immediate real-time event. * is automatically applied. The connected printer agent receives an immediate real-time event.
* security: * security:
* - cookieAuth: [] * - cookieAuth: []
* x-signals: [printerjob]
* requestBody: * requestBody:
* required: true * required: true
* content: * content:
@@ -162,7 +160,6 @@ export function register(app, basePath = '') {
notifyAgentJob(job.printeragentId, 'created', job); notifyAgentJob(job.printeragentId, 'created', job);
} }
emit('printerjob', { companyId: selected.companyId, data: { job } });
res.status(201).json({ printerjob: job }); res.status(201).json({ printerjob: job });
} catch (error) { } catch (error) {
const status = printerjobErrorStatus(error); const status = printerjobErrorStatus(error);