change yog to any year
This commit is contained in:
1 file changed
+5
-5
@@ -574,7 +574,7 @@ func UpdateStudentAddress(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
// In the case a student gets held back a grade, we need to update their YOG (Year of Graduation)
|
// In the case a student gets held back a grade, we need to update their YOG (Year of Graduation)
|
||||||
func UpdateStudentYOG(c *fiber.Ctx) error {
|
func UpdateStudentYOG(c *fiber.Ctx) error {
|
||||||
var data map[string]string
|
var data map[string]interface{}
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
|
||||||
if err := c.BodyParser(&data); err != nil {
|
if err := c.BodyParser(&data); err != nil {
|
||||||
@@ -596,7 +596,7 @@ func UpdateStudentYOG(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check required fields are included
|
// Check required fields are included
|
||||||
if data["sid"] == "" {
|
if data["sid"] == "" || data["yog"] == nil {
|
||||||
cancel()
|
cancel()
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
"success": false,
|
"success": false,
|
||||||
@@ -605,7 +605,7 @@ func UpdateStudentYOG(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var student models.Student
|
var student models.Student
|
||||||
findErr := studentCollection.FindOne(context.TODO(), bson.M{"schooldata.sid": data["sid"]}).Decode(&student)
|
findErr := studentCollection.FindOne(context.TODO(), bson.M{"schooldata.sid": data["sid"].(string)}).Decode(&student)
|
||||||
if findErr != nil {
|
if findErr != nil {
|
||||||
cancel()
|
cancel()
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
@@ -617,14 +617,14 @@ func UpdateStudentYOG(c *fiber.Ctx) error {
|
|||||||
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{
|
||||||
"schooldata.yog": student.SchoolData.YOG + 1,
|
"schooldata.yog": data["yog"].(int),
|
||||||
"updated_at": update_time,
|
"updated_at": update_time,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
result, updateErr := studentCollection.UpdateOne(
|
result, updateErr := studentCollection.UpdateOne(
|
||||||
ctx,
|
ctx,
|
||||||
bson.M{"schooldata.sid": data["sid"]},
|
bson.M{"schooldata.sid": data["sid"].(string)},
|
||||||
update,
|
update,
|
||||||
)
|
)
|
||||||
if updateErr != nil {
|
if updateErr != nil {
|
||||||
|
|||||||
Reference in new issue
Block a user