update/contact-email

This commit is contained in:
SowinskiBraeden committed 2022-01-31 19:38:44 -08:00
1 parent e47ece5bb0
commit cdb45381f6
1 file changed
+59 -5
+59 -5
View File
@@ -867,9 +867,63 @@ func UpdateContactPhone(c *fiber.Ctx) error {
} }
func UpdateContactEmail(c *fiber.Ctx) error { func UpdateContactEmail(c *fiber.Ctx) error {
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{ var data map[string]string
"success": nil, ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
"message": "not implimented",
if err := c.BodyParser(&data); err != nil {
cancel()
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"success": false,
"message": "Failed to parse body",
"error": err,
})
}
// Ensure Authenticated admin sent request
if !AuthAdmin(c) {
cancel()
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
"success": false,
"message": "Unauthorized: only an admin can perform this action",
})
}
// Check id of contact and new priority number is included
if data["_id"] == "" || data["email"] == "" {
cancel()
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"success": false,
"message": "missing required fields",
})
}
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
update := bson.M{
"$set": bson.M{
"email": data["email"],
"updated_at": update_time,
},
}
result, updateErr := contactCollection.UpdateOne(
ctx,
bson.M{"_id": data["_id"]},
update,
)
if updateErr != nil {
cancel()
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"success": false,
"message": "contact could not be updated",
"error": updateErr,
})
}
defer cancel()
return c.Status(fiber.StatusOK).JSON(fiber.Map{
"success": true,
"message": "successfully updated contact",
"result": result,
}) })
} }
@@ -921,7 +975,7 @@ func UpdateContactPriority(c *fiber.Ctx) error {
cancel() cancel()
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{ return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"success": false, "success": false,
"message": "the locker could not be updated", "message": "contact could not be updated",
"error": updateErr, "error": updateErr,
}) })
} }
@@ -929,7 +983,7 @@ func UpdateContactPriority(c *fiber.Ctx) error {
return c.Status(fiber.StatusOK).JSON(fiber.Map{ return c.Status(fiber.StatusOK).JSON(fiber.Map{
"success": true, "success": true,
"message": "successfully updated locker", "message": "successfully updated contact",
"result": result, "result": result,
}) })
} }