-
Notifications
You must be signed in to change notification settings - Fork 0
/
Put.go
40 lines (37 loc) · 1.03 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
package email
import (
"fmt"
"github.com/badoux/checkmail"
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"
)
// mahasiswa & mitra
func UpdateEmailUser(iduser primitive.ObjectID, db *mongo.Database, insertedDoc intermoni.User) error {
dataUser, err := intermoni.GetUserFromID(iduser, db)
if err != nil {
return err
}
if insertedDoc.Email == "" {
return fmt.Errorf("mohon untuk melengkapi data")
}
if err = checkmail.ValidateFormat(insertedDoc.Email); err != nil {
return fmt.Errorf("email tidak valid")
}
existsDoc, _ := intermoni.GetUserFromEmail(insertedDoc.Email, db)
if existsDoc.Email == insertedDoc.Email {
return fmt.Errorf("email sudah terdaftar")
}
user := bson.M{
"email": insertedDoc.Email,
"password": dataUser.Password,
"salt": dataUser.Salt,
"role": dataUser.Role,
}
err = intermoni.UpdateOneDoc(iduser, db, "user", user)
if err != nil {
return err
}
return nil
}