mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 23:15:36 +00:00
fix: error when removing a category without a previous category
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
"category": "Category",
|
||||
"name": "Category name",
|
||||
"description": "Category description",
|
||||
"no-description": "No description",
|
||||
"create": "Create a category",
|
||||
"edit": "Edit a category",
|
||||
"remove": "Delete a category",
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
"category": "Catégorie",
|
||||
"name": "Nom de la catégorie",
|
||||
"description": "Description de la catégorie",
|
||||
"no-description": "Aucune description",
|
||||
"create": "Créer une catégorie",
|
||||
"edit": "Modifier une catégorie",
|
||||
"remove": "Supprimer une catégorie",
|
||||
|
||||
@@ -134,18 +134,22 @@ async function deleteCategory({ req, res, user }) {
|
||||
where: { id: cid },
|
||||
});
|
||||
|
||||
const { id: previousCategoryId } = await prisma.category.findFirst({
|
||||
const previousCategory = await prisma.category.findFirst({
|
||||
where: { nextId: category.id },
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
if (previousCategory) {
|
||||
await prisma.category.update({
|
||||
where: {
|
||||
id: previousCategoryId,
|
||||
id: previousCategory?.id,
|
||||
},
|
||||
data: {
|
||||
nextId: category.nextId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return res.send({
|
||||
success: 'Category successfully deleted',
|
||||
categoryId: category.id,
|
||||
|
||||
@@ -70,6 +70,16 @@ export default function PageRemoveCategory({
|
||||
fieldClass={styles['input-field']}
|
||||
disabled={true}
|
||||
/>
|
||||
<TextBox
|
||||
name='description'
|
||||
label={t('common:category.description')}
|
||||
value={category.description}
|
||||
fieldClass={styles['input-field']}
|
||||
placeholder={
|
||||
!category.description && t('common:category.no-description')
|
||||
}
|
||||
disabled={true}
|
||||
/>
|
||||
<Checkbox
|
||||
name='confirm-delete'
|
||||
label={t('common:category.remove-confirm')}
|
||||
|
||||
Reference in New Issue
Block a user