|
@@ -16,6 +16,7 @@ import (
|
|
type teamMembersModel interface {
|
|
type teamMembersModel interface {
|
|
Insert(ctx context.Context, data *TeamMembers) error
|
|
Insert(ctx context.Context, data *TeamMembers) error
|
|
FindOne(ctx context.Context, id string) (*TeamMembers, error)
|
|
FindOne(ctx context.Context, id string) (*TeamMembers, error)
|
|
|
|
+ FindOneByUserId(ctx context.Context, userId primitive. ObjectID) (*TeamMembers, error)
|
|
Update(ctx context.Context, data *TeamMembers) (*mongo.UpdateResult, error)
|
|
Update(ctx context.Context, data *TeamMembers) (*mongo.UpdateResult, error)
|
|
Delete(ctx context.Context, id string) (int64, error)
|
|
Delete(ctx context.Context, id string) (int64, error)
|
|
}
|
|
}
|
|
@@ -57,6 +58,20 @@ func (m *defaultTeamMembersModel) FindOne(ctx context.Context, id string) (*Team
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (m *defaultTeamMembersModel) FindOneByUserId(ctx context.Context, userId primitive. ObjectID) (*TeamMembers, error) {
|
|
|
|
+ var data TeamMembers
|
|
|
|
+
|
|
|
|
+ err := m.conn.FindOne(ctx, &data, bson.M{"userId": userId})
|
|
|
|
+ switch err {
|
|
|
|
+ case nil:
|
|
|
|
+ return &data, nil
|
|
|
|
+ case mon.ErrNotFound:
|
|
|
|
+ return nil, ErrNotFound
|
|
|
|
+ default:
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
func (m *defaultTeamMembersModel) Update(ctx context.Context, data *TeamMembers) (*mongo.UpdateResult, error) {
|
|
func (m *defaultTeamMembersModel) Update(ctx context.Context, data *TeamMembers) (*mongo.UpdateResult, error) {
|
|
res, err := m.conn.UpdateOne(ctx, bson.M{"_id": data.ID}, bson.M{"$set": data})
|
|
res, err := m.conn.UpdateOne(ctx, bson.M{"_id": data.ID}, bson.M{"$set": data})
|
|
return res, err
|
|
return res, err
|