u
This commit is contained in:
@@ -232,7 +232,6 @@ export function notifyAgentJob(agentId, action, job) {
|
||||
for (const clientRes of conns) {
|
||||
if (!clientRes.writableEnded) {
|
||||
clientRes.write(`event: job\ndata: ${payload}\n\n`);
|
||||
clientRes.write(`event: printerjob\ndata: ${payload}\n\n`);
|
||||
clientRes.flush?.();
|
||||
}
|
||||
}
|
||||
@@ -407,14 +406,11 @@ async function handleState(req, res) {
|
||||
|
||||
if (rawState?.job?.id && rawState?.job?.state) {
|
||||
try {
|
||||
const updatedJob = await printerjobDb.updateState(
|
||||
await printerjobDb.updateState(
|
||||
{ agentId: req.agent.id },
|
||||
rawState.job.id,
|
||||
rawState.job.state
|
||||
);
|
||||
if (req.agent?.companyId) {
|
||||
emit('printerjob', { companyId: req.agent.companyId, data: { job: updatedJob } });
|
||||
}
|
||||
} catch (jobErr) {
|
||||
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) => {
|
||||
try {
|
||||
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 });
|
||||
} catch (err) {
|
||||
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) => {
|
||||
try {
|
||||
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 });
|
||||
} catch (err) {
|
||||
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 {
|
||||
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 });
|
||||
} catch (err) {
|
||||
if (err.message === 'Printerjob not found') return res.status(404).json({ error: err.message });
|
||||
|
||||
@@ -7,7 +7,6 @@ import * as printerDb from '../../../db/printer.js';
|
||||
import * as agentprinterDb from '../../../db/agentprinter.js';
|
||||
import * as labeltemplateDb from '../../../db/labeltemplate.js';
|
||||
import * as printerjobDb from '../../../db/printerjob.js';
|
||||
import { emit } from '../../sse.js';
|
||||
import { notifyAgentJob } from '../../agent/index.js';
|
||||
import { pngToZpl } from '../../../services/zplService.js';
|
||||
import { applyZplCopies } from '../zpljob.js';
|
||||
@@ -481,7 +480,6 @@ export function register(app, basePath = '') {
|
||||
notifyAgentJob(job.printeragentId, 'created', job);
|
||||
}
|
||||
|
||||
emit('printerjob', { companyId, data: { job } });
|
||||
return res.status(200).json({ success: true, printerjob: job });
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,6 @@ export function register(app, basePath = '') {
|
||||
* | `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 |
|
||||
* | `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}` |
|
||||
* | `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}` |
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import * as printerjobDb from '../../db/printerjob.js';
|
||||
import { emit } from '../sse.js';
|
||||
import { notifyAgentJob } from '../agent/index.js';
|
||||
|
||||
// #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.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* x-signals: [printerjob]
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
@@ -249,7 +247,6 @@ export function register(app, basePath = '') {
|
||||
notifyAgentJob(job.printeragentId, 'created', job);
|
||||
}
|
||||
|
||||
emit('printerjob', { companyId: selected.companyId, data: { job } });
|
||||
res.status(201).json({ printerjob: job });
|
||||
} catch (error) {
|
||||
const status = printerjobErrorStatus(error);
|
||||
@@ -271,7 +268,6 @@ export function register(app, basePath = '') {
|
||||
* Notifies connected agents in real time.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* x-signals: [printerjob]
|
||||
* requestBody:
|
||||
* content:
|
||||
* application/json:
|
||||
@@ -318,7 +314,6 @@ export function register(app, basePath = '') {
|
||||
if (job.printeragentId) {
|
||||
notifyAgentJob(job.printeragentId, 'cancelled', job);
|
||||
}
|
||||
emit('printerjob', { companyId: selected.companyId, data: { job } });
|
||||
cancelledJobs.push(job);
|
||||
} catch (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.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* x-signals: [printerjob]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
@@ -388,7 +382,6 @@ export function register(app, basePath = '') {
|
||||
notifyAgentJob(job.printeragentId, 'cancelled', job);
|
||||
}
|
||||
|
||||
emit('printerjob', { companyId: selected.companyId, data: { job } });
|
||||
res.status(200).json({ success: true, printerjob: job });
|
||||
} catch (error) {
|
||||
const status = printerjobErrorStatus(error);
|
||||
@@ -410,7 +403,6 @@ export function register(app, basePath = '') {
|
||||
* event to the connected printer agent before deletion.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* x-signals: [printerjob]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
@@ -450,10 +442,6 @@ export function register(app, basePath = '') {
|
||||
notifyAgentJob(job.printeragentId, 'cancelled', job);
|
||||
}
|
||||
|
||||
emit('printerjob', {
|
||||
companyId: selected.companyId,
|
||||
data: { jobId: job.id, state: 'cancelled' },
|
||||
});
|
||||
res.status(200).json({ success: true, deletedJob: job });
|
||||
} catch (error) {
|
||||
const status = printerjobErrorStatus(error);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import * as printerjobDb from '../../db/printerjob.js';
|
||||
import { emit } from '../sse.js';
|
||||
import { notifyAgentJob } from '../agent/index.js';
|
||||
|
||||
// #region Helpers
|
||||
@@ -73,7 +72,6 @@ export function register(app, basePath = '') {
|
||||
* is automatically applied. The connected printer agent receives an immediate real-time event.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* x-signals: [printerjob]
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
@@ -162,7 +160,6 @@ export function register(app, basePath = '') {
|
||||
notifyAgentJob(job.printeragentId, 'created', job);
|
||||
}
|
||||
|
||||
emit('printerjob', { companyId: selected.companyId, data: { job } });
|
||||
res.status(201).json({ printerjob: job });
|
||||
} catch (error) {
|
||||
const status = printerjobErrorStatus(error);
|
||||
|
||||
Reference in New Issue
Block a user