u
This commit is contained in:
@@ -87,6 +87,37 @@ export const printerjob = {
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* POST /api/printerjob/cancel-all
|
||||
* Cancels all pending/processing jobs, optionally scoped to an agentprinter.
|
||||
* Falls back to listing and cancelling individual jobs if needed.
|
||||
* @param {{ agentprinterId?: number }} [payload]
|
||||
* → { success: true, cancelledCount: number, jobs: PrinterJob[] }
|
||||
*/
|
||||
async cancelAll({ agentprinterId } = {}) {
|
||||
try {
|
||||
return await http('/api/printerjob/cancel-all', {
|
||||
method: 'POST',
|
||||
body: agentprinterId != null ? { agentprinterId: Number(agentprinterId) } : {},
|
||||
});
|
||||
} catch (err) {
|
||||
if (err?.status === 404) {
|
||||
const { printerjobs = [] } = await this.list({ agentprinterId });
|
||||
const cancellable = printerjobs.filter(
|
||||
(j) => j.state === 'pending' || j.state === 'processing',
|
||||
);
|
||||
if (cancellable.length === 0) return { success: true, cancelledCount: 0, jobs: [] };
|
||||
const results = await Promise.all(cancellable.map((j) => this.cancel(j.id)));
|
||||
return {
|
||||
success: true,
|
||||
cancelledCount: results.length,
|
||||
jobs: results.map((r) => r.printerjob),
|
||||
};
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* DELETE /api/printerjob/:id
|
||||
* → { success: true, deletedJob: PrinterJob }
|
||||
|
||||
Reference in New Issue
Block a user