fix UpdateTeacherName
This commit is contained in:
1 file changed
+10
-8
@@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1460,7 +1459,7 @@ func UpdateTeacherPhoto(c *fiber.Ctx) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get student
|
// Get teacher
|
||||||
var teacher models.Teacher
|
var teacher models.Teacher
|
||||||
findErr := teacherCollection.FindOne(context.TODO(), bson.M{"schooldata.tid": tid}).Decode(&teacher)
|
findErr := teacherCollection.FindOne(context.TODO(), bson.M{"schooldata.tid": tid}).Decode(&teacher)
|
||||||
if findErr != nil {
|
if findErr != nil {
|
||||||
@@ -1640,7 +1639,7 @@ func UpdateTeacherName(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check id and names are included
|
// Check id and names are included
|
||||||
if data["_id"] == "" || data["firstname"] == "" || data["middlename"] == "" || data["lastname"] == "" {
|
if data["tid"] == "" || data["firstname"] == "" || data["middlename"] == "" || data["lastname"] == "" {
|
||||||
cancel()
|
cancel()
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
"success": false,
|
"success": false,
|
||||||
@@ -1648,15 +1647,18 @@ func UpdateTeacherName(c *fiber.Ctx) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
teacherObjectId, idErr := primitive.ObjectIDFromHex(data["_id"])
|
// Get teacher
|
||||||
if idErr != nil {
|
var teacher models.Teacher
|
||||||
|
findErr := teacherCollection.FindOne(context.TODO(), bson.M{"schooldata.tid": data["tid"]}).Decode(&teacher)
|
||||||
|
if findErr != nil {
|
||||||
cancel()
|
cancel()
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "teacher not found",
|
"message": "the teacher could not be found",
|
||||||
"error": idErr,
|
"error": findErr,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
update := bson.M{
|
update := bson.M{
|
||||||
"$set": bson.M{
|
"$set": bson.M{
|
||||||
@@ -1669,7 +1671,7 @@ func UpdateTeacherName(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
result, updateErr := teacherCollection.UpdateOne(
|
result, updateErr := teacherCollection.UpdateOne(
|
||||||
ctx,
|
ctx,
|
||||||
bson.M{"_id": teacherObjectId},
|
bson.M{"schooldata.tid": data["tid"]},
|
||||||
update,
|
update,
|
||||||
)
|
)
|
||||||
if updateErr != nil {
|
if updateErr != nil {
|
||||||
|
|||||||
Reference in new issue
Block a user