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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user