-
Notifications
You must be signed in to change notification settings - Fork 0
/
Put.go
66 lines (61 loc) · 1.68 KB
/
Put.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package pembimbing
import (
"context"
"fmt"
intermoni "github.com/intern-monitoring/backend-intermoni"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
)
func UpdatePembimbing(idparam, iduser primitive.ObjectID, db *mongo.Database, insertedDoc intermoni.Pembimbing) error {
pembimbing, err := intermoni.GetPembimbingFromAkun(iduser, db)
if err != nil {
return err
}
if pembimbing.ID != idparam {
return fmt.Errorf("kamu bukan pemilik data ini")
}
if insertedDoc.NamaLengkap == "" || insertedDoc.NIK == "" {
return fmt.Errorf("mohon untuk melengkapi data")
}
data := bson.M{
"namalengkap": insertedDoc.NamaLengkap,
"nik": insertedDoc.NIK,
"akun": intermoni.User{
ID: pembimbing.Akun.ID,
},
"prodi": insertedDoc.Prodi,
}
err = intermoni.UpdateOneDoc(idparam, db, "pembimbing", data)
if err != nil {
return err
}
return nil
}
func CheckMentor_MahasiswaMagang(idpembimbing primitive.ObjectID, db *mongo.Database) bool {
collection := db.Collection("mahasiswa_magang")
filter := bson.M{
"pembimbing._id": idpembimbing,
}
count, err := collection.CountDocuments(context.Background(), filter)
if err != nil {
return false
}
if count > 0 {
jumlah_gagal := JumlahStatusGagalMahasiswaMagang(idpembimbing, db)
return jumlah_gagal != count
}
return false
}
func JumlahStatusGagalMahasiswaMagang(idpembimbing primitive.ObjectID, db *mongo.Database) int64 {
collection := db.Collection("mahasiswa_magang")
filter := bson.M{
"pembimbing._id": idpembimbing,
"status": 2,
}
count, err := collection.CountDocuments(context.Background(), filter)
if err != nil {
return 0
}
return count
}