Add category.order to reorder siblings under a parent.

Sets each direct child's sort to its index in the given categoryIds,
scoped by parentId. Validates the set matches the current children.
This commit is contained in:
seb
2026-08-02 19:41:54 +02:00
parent e96bfb0624
commit b070607357
5 changed files with 108 additions and 0 deletions

View File

@@ -163,6 +163,7 @@ const MENU = {
items: [
{ value: 'category.createUnderParent', label: 'createUnderParent', hint: 'googleAuthId, parentId, name → row' },
{ value: 'category.rename', label: 'rename', hint: 'googleAuthId, id, name → row' },
{ value: 'category.order', label: 'order', hint: 'googleAuthId, parentId, JSON categoryIds' },
{ value: 'category.delete', label: 'delete', hint: 'googleAuthId, id' },
{ value: 'category.getTreeForCompany', label: 'getTreeForCompany', hint: 'googleAuthId, companyId → rows' },
{ value: 'category.getCategoryArticles', label: 'getCategoryArticles', hint: 'googleAuthId, categoryId → rows' },
@@ -670,6 +671,33 @@ async function runMethod(client, action) {
}),
];
}
case 'category.order': {
const googleAuthId = await askInt('google_auth id');
if (googleAuthId == null) return;
const parentId = await askInt('parent id');
if (parentId == null) return;
const categoryIdsJson = await askText('categoryIds JSON', {
placeholder: '[2,4,3,5]',
validate: (v) => {
if (!v?.trim()) return 'Required';
try {
const parsed = JSON.parse(v);
if (!Array.isArray(parsed)) return 'Must be a JSON array';
} catch {
return 'Invalid JSON';
}
},
});
if (categoryIdsJson == null) return;
return [
'result',
await client.category.order({
googleAuthId: Number(googleAuthId),
parentId: Number(parentId),
categoryIds: JSON.parse(categoryIdsJson),
}),
];
}
case 'category.delete': {
const googleAuthId = await askInt('google_auth id');
if (googleAuthId == null) return;