feat(api): reorderable categories in panels

This commit is contained in:
Isaac 2025-01-14 03:43:51 +00:00
parent 0b06e1852f
commit 5ffd18961b
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33

View File

@ -30,7 +30,11 @@ module.exports.post = fastify => ({
where: { id: guild.id }, where: { id: guild.id },
}); });
const getMessage = client.i18n.getLocale(settings.locale); const getMessage = client.i18n.getLocale(settings.locale);
const categories = settings.categories.filter(c => data.categories.includes(c.id)); const categories = data.categories.map(id => {
const category = settings.categories.find(c => c.id === id);
if (!category) throw new Error(`Invalid category: ${id}`);
return category;
});
if (categories.length === 0) throw new Error('No categories'); if (categories.length === 0) throw new Error('No categories');
if (categories.length !== 1 && data.type === 'MESSAGE') throw new Error('Invalid number of categories for panel type'); if (categories.length !== 1 && data.type === 'MESSAGE') throw new Error('Invalid number of categories for panel type');