u
This commit is contained in:
@@ -1752,6 +1752,10 @@
|
||||
* nullable: true
|
||||
* updatedAt:
|
||||
* type: string
|
||||
* sort:
|
||||
* type: integer
|
||||
* description: Display order (ascending)
|
||||
* default: 0
|
||||
* LabelObject:
|
||||
* type: object
|
||||
* required: [id, type, x, y]
|
||||
|
||||
@@ -124,6 +124,9 @@ export function register(app, basePath = '') {
|
||||
* properties:
|
||||
* name:
|
||||
* type: string
|
||||
* sort:
|
||||
* type: integer
|
||||
* default: 0
|
||||
* example:
|
||||
* name: "Bar printer"
|
||||
* responses:
|
||||
@@ -174,10 +177,22 @@ export function register(app, basePath = '') {
|
||||
return res.status(400).json({ error: 'name is required' });
|
||||
}
|
||||
|
||||
let sort;
|
||||
if (req.body?.sort !== undefined) {
|
||||
sort = Number(req.body.sort);
|
||||
if (!Number.isInteger(sort)) {
|
||||
return res.status(400).json({ error: 'sort must be an integer' });
|
||||
}
|
||||
}
|
||||
|
||||
const pairingpin = String(randomInt(100000, 999999));
|
||||
|
||||
try {
|
||||
const printeragent = await db.create(req.user.id, { name: name.trim(), pairingpin });
|
||||
const printeragent = await db.create(req.user.id, {
|
||||
name: name.trim(),
|
||||
pairingpin,
|
||||
sort,
|
||||
});
|
||||
res.status(200).json({ printeragent });
|
||||
} catch (error) {
|
||||
const status = printeragentErrorStatus(error);
|
||||
@@ -193,7 +208,8 @@ export function register(app, basePath = '') {
|
||||
* /printeragent/{id}:
|
||||
* patch:
|
||||
* tags: [Printeragent]
|
||||
* summary: Rename printer agent
|
||||
* summary: Update printer agent
|
||||
* description: Updates name and/or display order (sort) of a printer agent.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* parameters:
|
||||
@@ -208,10 +224,11 @@ export function register(app, basePath = '') {
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required: [name]
|
||||
* properties:
|
||||
* name:
|
||||
* type: string
|
||||
* sort:
|
||||
* type: integer
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Updated printer agent
|
||||
@@ -261,12 +278,28 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
const { name } = req.body ?? {};
|
||||
if (typeof name !== 'string' || !name.trim()) {
|
||||
return res.status(400).json({ error: 'name is required' });
|
||||
if (name === undefined && req.body?.sort === undefined) {
|
||||
return res.status(400).json({ error: 'name or sort is required' });
|
||||
}
|
||||
|
||||
if (name !== undefined && (typeof name !== 'string' || !name.trim())) {
|
||||
return res.status(400).json({ error: 'name must be a non-empty string' });
|
||||
}
|
||||
|
||||
let sort;
|
||||
if (req.body?.sort !== undefined) {
|
||||
sort = Number(req.body.sort);
|
||||
if (!Number.isInteger(sort)) {
|
||||
return res.status(400).json({ error: 'sort must be an integer' });
|
||||
}
|
||||
}
|
||||
|
||||
const payload = { id: parsed.id };
|
||||
if (name !== undefined) payload.name = name.trim();
|
||||
if (sort !== undefined) payload.sort = sort;
|
||||
|
||||
try {
|
||||
const printeragent = await db.update(req.user.id, { id: parsed.id, name: name.trim() });
|
||||
const printeragent = await db.update(req.user.id, payload);
|
||||
res.status(200).json({ printeragent });
|
||||
} catch (error) {
|
||||
const status = printeragentErrorStatus(error);
|
||||
|
||||
Reference in New Issue
Block a user