fix db queries

This commit is contained in:
SowinskiBraeden committed 2023-01-09 09:31:57 -08:00
1 parent 2914859505
commit fede9ff793
8 files changed
+61 -61

No files matched your search

+2 -2
View File
@@ -378,7 +378,7 @@ func RemoveStudentsDisabled(c *fiber.Ctx) error {
result, updateErr := StudentCollection.UpdateOne(
ctx,
bson.M{"School.sid": data["sid"]},
bson.M{"school.sid": data["sid"]},
update,
)
if updateErr != nil {
@@ -440,7 +440,7 @@ func RemoveTeachersDisabled(c *fiber.Ctx) error {
result, updateErr := TeacherCollection.UpdateOne(
ctx,
bson.M{"School.tid": data["tid"]},
bson.M{"school.tid": data["tid"]},
update,
)
if updateErr != nil {
+26 -26
View File
@@ -63,17 +63,17 @@ func UpdateStudentName(c *fiber.Ctx) error {
if updateMiddle {
update = bson.M{
"$set": bson.M{
"Personal.firstname": data["firstname"],
"Personal.middlename": data["middlename"],
"Personal.lastname": data["lastname"],
"personal.firstname": data["firstname"],
"personal.middlename": data["middlename"],
"personal.lastname": data["lastname"],
"updated_at": update_time,
},
}
} else {
update = bson.M{
"$set": bson.M{
"Personal.firstname": data["firstname"],
"Personal.lastname": data["lastname"],
"personal.firstname": data["firstname"],
"personal.lastname": data["lastname"],
"updated_at": update_time,
},
}
@@ -81,7 +81,7 @@ func UpdateStudentName(c *fiber.Ctx) error {
result, updateErr := StudentCollection.UpdateOne(
ctx,
bson.M{"School.sid": data["sid"]},
bson.M{"school.sid": data["sid"]},
update,
)
if updateErr != nil {
@@ -142,7 +142,7 @@ func UpdateStudentGradeLevel(c *fiber.Ctx) error {
_, updateErr := StudentCollection.UpdateOne(
ctx,
bson.M{"School.sid": data["sid"].(string)},
bson.M{"school.sid": data["sid"].(string)},
update,
)
if updateErr != nil {
@@ -213,7 +213,7 @@ func UpdateStudentHomeroom(c *fiber.Ctx) error {
_, updateErr := StudentCollection.UpdateOne(
ctx,
bson.M{"School.sid": data["sid"]},
bson.M{"school.sid": data["sid"]},
update,
)
if updateErr != nil {
@@ -261,7 +261,7 @@ func UpdateStudentPassword(c *fiber.Ctx) error {
claims := token.Claims.(*jwt.StandardClaims)
var student models.Student
findErr := StudentCollection.FindOne(ctx, bson.M{"School.sid": claims.Issuer}).Decode(&student)
findErr := StudentCollection.FindOne(ctx, bson.M{"school.sid": claims.Issuer}).Decode(&student)
if findErr != nil {
cancel()
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
@@ -317,7 +317,7 @@ func UpdateStudentPassword(c *fiber.Ctx) error {
_, updateErr := StudentCollection.UpdateOne(
ctx,
bson.M{"School.sid": claims.Issuer},
bson.M{"school.sid": claims.Issuer},
update,
)
if updateErr != nil {
@@ -372,7 +372,7 @@ func ResetStudentPassword(c *fiber.Ctx) error {
}
var student models.Student
findErr := StudentCollection.FindOne(context.TODO(), bson.M{"School.sid": data["sid"]}).Decode(&student)
findErr := StudentCollection.FindOne(context.TODO(), bson.M{"school.sid": data["sid"]}).Decode(&student)
if findErr != nil {
cancel()
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
@@ -401,7 +401,7 @@ func ResetStudentPassword(c *fiber.Ctx) error {
result, updateErr := StudentCollection.UpdateOne(
ctx,
bson.M{"School.sid": data["sid"]},
bson.M{"school.sid": data["sid"]},
update,
)
if updateErr != nil {
@@ -485,7 +485,7 @@ func UpdateStudentLocker(c *fiber.Ctx) error {
_, updateErr := StudentCollection.UpdateOne(
ctx,
bson.M{"School.sid": data["sid"]},
bson.M{"school.sid": data["sid"]},
update,
)
if updateErr != nil {
@@ -538,10 +538,10 @@ func UpdateStudentAddress(c *fiber.Ctx) error {
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
update := bson.M{
"$set": bson.M{
"Personal.address": data["address"],
"Personal.city": data["city"],
"Personal.province": data["province"],
"Personal.postal": data["postal"],
"personal.address": data["address"],
"personal.city": data["city"],
"personal.province": data["province"],
"personal.postal": data["postal"],
"updated_at": update_time,
},
}
@@ -600,7 +600,7 @@ func UpdateStudentYOG(c *fiber.Ctx) error {
}
var student models.Student
findErr := StudentCollection.FindOne(context.TODO(), bson.M{"School.sid": data["sid"].(string)}).Decode(&student)
findErr := StudentCollection.FindOne(context.TODO(), bson.M{"school.sid": data["sid"].(string)}).Decode(&student)
if findErr != nil {
cancel()
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
@@ -619,7 +619,7 @@ func UpdateStudentYOG(c *fiber.Ctx) error {
result, updateErr := StudentCollection.UpdateOne(
ctx,
bson.M{"School.sid": data["sid"].(string)},
bson.M{"school.sid": data["sid"].(string)},
update,
)
if updateErr != nil {
@@ -687,13 +687,13 @@ func RemoveStudentContact(c *fiber.Ctx) error {
"updated_at": update_time,
},
"$pull": bson.M{
"Personal.contacts": contact.ID,
"personal.contacts": contact.ID,
},
}
result, updateErr := StudentCollection.UpdateOne(
ctx,
bson.M{"School.sid": data["sid"]},
bson.M{"school.sid": data["sid"]},
update,
)
if updateErr != nil {
@@ -761,13 +761,13 @@ func AddStudentContact(c *fiber.Ctx) error {
"updated_at": update_time,
},
"$push": bson.M{
"Personal.contacts": contact.ID,
"personal.contacts": contact.ID,
},
}
result, updateErr := StudentCollection.UpdateOne(
ctx,
bson.M{"School.sid": data["sid"]},
bson.M{"school.sid": data["sid"]},
update,
)
if updateErr != nil {
@@ -810,7 +810,7 @@ func UpdateStudentPhoto(c *fiber.Ctx) error {
// Get student
var student models.Student
findErr := StudentCollection.FindOne(context.TODO(), bson.M{"School.sid": sid}).Decode(&student)
findErr := StudentCollection.FindOne(context.TODO(), bson.M{"school.sid": sid}).Decode(&student)
if findErr != nil {
cancel()
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
@@ -951,14 +951,14 @@ func UpdateStudentEmail(c *fiber.Ctx) error {
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
update := bson.M{
"$set": bson.M{
"Personal.email": data["email"],
"personal.email": data["email"],
"updated_at": update_time,
},
}
result, updateErr := StudentCollection.UpdateOne(
ctx,
bson.M{"School.sid": sid},
bson.M{"school.sid": sid},
update,
)
if updateErr != nil {
+18 -18
View File
@@ -68,7 +68,7 @@ func UpdateTeacherHomeroom(c *fiber.Ctx) error {
_, updateErr := TeacherCollection.UpdateOne(
ctx,
bson.M{"School.tid": data["tid"]},
bson.M{"school.tid": data["tid"]},
update,
)
if updateErr != nil {
@@ -116,7 +116,7 @@ func UpdateTeacherPassword(c *fiber.Ctx) error {
claims := token.Claims.(*jwt.StandardClaims)
var teacher models.Teacher
findErr := TeacherCollection.FindOne(ctx, bson.M{"School.tid": claims.Issuer}).Decode(&teacher)
findErr := TeacherCollection.FindOne(ctx, bson.M{"school.tid": claims.Issuer}).Decode(&teacher)
if findErr != nil {
cancel()
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
@@ -172,7 +172,7 @@ func UpdateTeacherPassword(c *fiber.Ctx) error {
_, updateErr := TeacherCollection.UpdateOne(
ctx,
bson.M{"School.tid": claims.Issuer},
bson.M{"school.tid": claims.Issuer},
update,
)
if updateErr != nil {
@@ -225,7 +225,7 @@ func ResetTeacherPassword(c *fiber.Ctx) error {
}
var teacher models.Teacher
findErr := TeacherCollection.FindOne(context.TODO(), bson.M{"School.tid": data["tid"]}).Decode(&teacher)
findErr := TeacherCollection.FindOne(context.TODO(), bson.M{"school.tid": data["tid"]}).Decode(&teacher)
if findErr != nil {
cancel()
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
@@ -254,7 +254,7 @@ func ResetTeacherPassword(c *fiber.Ctx) error {
result, updateErr := StudentCollection.UpdateOne(
ctx,
bson.M{"School.tid": data["tid"]},
bson.M{"school.tid": data["tid"]},
update,
)
if updateErr != nil {
@@ -320,17 +320,17 @@ func UpdateTeacherAddress(c *fiber.Ctx) error {
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
update := bson.M{
"$set": bson.M{
"Personal.address": data["address"],
"Personal.city": data["city"],
"Personal.province": data["province"],
"Personal.postal": data["postal"],
"personal.address": data["address"],
"personal.city": data["city"],
"personal.province": data["province"],
"personal.postal": data["postal"],
"updated_at": update_time,
},
}
_, updateErr := TeacherCollection.UpdateOne(
ctx,
bson.M{"School.tid": data["tid"]},
bson.M{"school.tid": data["tid"]},
update,
)
if updateErr != nil {
@@ -372,7 +372,7 @@ func UpdateTeacherPhoto(c *fiber.Ctx) error {
// Get teacher
var teacher models.Teacher
findErr := TeacherCollection.FindOne(context.TODO(), bson.M{"School.tid": tid}).Decode(&teacher)
findErr := TeacherCollection.FindOne(context.TODO(), bson.M{"school.tid": tid}).Decode(&teacher)
if findErr != nil {
cancel()
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
@@ -514,14 +514,14 @@ func UpdateTeacherEmail(c *fiber.Ctx) error {
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
update := bson.M{
"$set": bson.M{
"Personal.email": data["email"],
"personal.email": data["email"],
"updated_at": update_time,
},
}
_, updateErr := TeacherCollection.UpdateOne(
ctx,
bson.M{"School.tid": tid},
bson.M{"school.tid": tid},
update,
)
if updateErr != nil {
@@ -573,7 +573,7 @@ func UpdateTeacherName(c *fiber.Ctx) error {
// Get teacher
var teacher models.Teacher
findErr := TeacherCollection.FindOne(ctx, bson.M{"School.tid": data["tid"]}).Decode(&teacher)
findErr := TeacherCollection.FindOne(ctx, bson.M{"school.tid": data["tid"]}).Decode(&teacher)
if findErr != nil {
cancel()
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
@@ -592,16 +592,16 @@ func UpdateTeacherName(c *fiber.Ctx) error {
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
update := bson.M{
"$set": bson.M{
"Personal.firstname": data["firstname"],
"Personal.middlename": middlename,
"Personal.lastname": data["lastname"],
"personal.firstname": data["firstname"],
"personal.middlename": middlename,
"personal.lastname": data["lastname"],
"updated_at": update_time,
},
}
_, updateErr := TeacherCollection.UpdateOne(
ctx,
bson.M{"School.tid": data["tid"]},
bson.M{"school.tid": data["tid"]},
update,
)
if updateErr != nil {