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