👔 Prevent user from deleting their primary contact
This commit is contained in:
parent
45dd50ccba
commit
db018b35f9
@ -118,6 +118,9 @@ func deleteContact(c *fiber.Ctx) error {
|
|||||||
if err := database.C.Where("account_id = ? AND id = ?", user.ID, contactId).First(&contact).Error; err != nil {
|
if err := database.C.Where("account_id = ? AND id = ?", user.ID, contactId).First(&contact).Error; err != nil {
|
||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
|
if contact.IsPrimary {
|
||||||
|
return fiber.NewError(fiber.StatusBadRequest, "cannot delete primary contact")
|
||||||
|
}
|
||||||
|
|
||||||
if err := database.C.Delete(&contact).Error; err != nil {
|
if err := database.C.Delete(&contact).Error; err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user