70 lines
1.6 KiB
JavaScript
70 lines
1.6 KiB
JavaScript
import { http } from './http.js';
|
|
|
|
export const agentprinter = {
|
|
/**
|
|
* GET /api/agentprinter
|
|
* Query: ?printeragentId=<id>
|
|
* → { agentprinters: Agentprinter[] }
|
|
*/
|
|
list(printeragentId) {
|
|
const url =
|
|
printeragentId != null
|
|
? `/api/agentprinter?printeragentId=${encodeURIComponent(printeragentId)}`
|
|
: '/api/agentprinter';
|
|
return http(url);
|
|
},
|
|
|
|
/**
|
|
* GET /api/agentprinter/:id
|
|
* → { agentprinter: Agentprinter }
|
|
*/
|
|
get(id) {
|
|
return http(`/api/agentprinter/${id}`);
|
|
},
|
|
|
|
/**
|
|
* PATCH /api/agentprinter/:id
|
|
* Body: { enabled?: boolean, sort?: number }
|
|
* → { agentprinter: Agentprinter }
|
|
*/
|
|
update(id, patch = {}) {
|
|
const body = {};
|
|
if (patch.enabled !== undefined) body.enabled = Boolean(patch.enabled);
|
|
if (patch.sort !== undefined && patch.sort !== null && patch.sort !== '') {
|
|
body.sort = Number(patch.sort);
|
|
}
|
|
return http(`/api/agentprinter/${id}`, {
|
|
method: 'PATCH',
|
|
body,
|
|
});
|
|
},
|
|
|
|
/**
|
|
* PUT /api/agentprinter/order
|
|
* Body: { printeragentId?: number, agentprinterIds: number[] }
|
|
* → { agentprinterIds: number[] }
|
|
*/
|
|
order({ printeragentId, agentprinterIds }) {
|
|
const body = {
|
|
agentprinterIds: Array.isArray(agentprinterIds) ? agentprinterIds.map(Number) : [],
|
|
};
|
|
if (printeragentId != null) {
|
|
body.printeragentId = Number(printeragentId);
|
|
}
|
|
return http('/api/agentprinter/order', {
|
|
method: 'PUT',
|
|
body,
|
|
});
|
|
},
|
|
|
|
/**
|
|
* DELETE /api/agentprinter/:id → 204
|
|
*/
|
|
delete(id) {
|
|
return http(`/api/agentprinter/${id}`, {
|
|
method: 'DELETE',
|
|
});
|
|
},
|
|
};
|
|
|