fix code #13
			
				
			
		
		
		
	
							
								
								
									
										104
									
								
								user/db.go
								
								
								
								
							
							
						
						
									
										104
									
								
								user/db.go
								
								
								
								
							| 
						 | 
					@ -24,8 +24,9 @@ func isPhoneNumberExisted(ctx context.Context, phone string) bool {
 | 
				
			||||||
	total, err := col.CountDocuments(ctx, cond)
 | 
						total, err := col.CountDocuments(ctx, cond)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Error("usermngmt - User - CountDocuments", logger.LogData{
 | 
							logger.Error("usermngmt - User - CountDocuments", logger.LogData{
 | 
				
			||||||
			"condition": cond,
 | 
								Source:  "usermngmt.user.isPhoneNumberExisted",
 | 
				
			||||||
			"err":       err.Error(),
 | 
								Message: err.Error(),
 | 
				
			||||||
 | 
								Data:    cond,
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		return true
 | 
							return true
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -44,8 +45,9 @@ func isEmailExisted(ctx context.Context, email string) bool {
 | 
				
			||||||
	total, err := col.CountDocuments(ctx, cond)
 | 
						total, err := col.CountDocuments(ctx, cond)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Error("usermngmt - User - CountDocuments", logger.LogData{
 | 
							logger.Error("usermngmt - User - CountDocuments", logger.LogData{
 | 
				
			||||||
			"condition": cond,
 | 
								Source:  "usermngmt.user.isEmailExisted",
 | 
				
			||||||
			"err":       err.Error(),
 | 
								Message: err.Error(),
 | 
				
			||||||
 | 
								Data:    cond,
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		return true
 | 
							return true
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -63,8 +65,9 @@ func isRoleExisted(ctx context.Context, roleID primitive.ObjectID) bool {
 | 
				
			||||||
	total, err := col.CountDocuments(ctx, cond)
 | 
						total, err := col.CountDocuments(ctx, cond)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Error("usermngmt - Role - CountDocuments", logger.LogData{
 | 
							logger.Error("usermngmt - Role - CountDocuments", logger.LogData{
 | 
				
			||||||
			"condition": cond,
 | 
								Source:  "usermngmt.user.isRoleExisted",
 | 
				
			||||||
			"err":       err.Error(),
 | 
								Message: err.Error(),
 | 
				
			||||||
 | 
								Data:    cond,
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return total != 0
 | 
						return total != 0
 | 
				
			||||||
| 
						 | 
					@ -88,18 +91,24 @@ func roleFindByCondition(ctx context.Context, cond interface{}, opts ...*options
 | 
				
			||||||
	cursor, err := col.Find(ctx, cond, opts...)
 | 
						cursor, err := col.Find(ctx, cond, opts...)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Error("usermngmt - Role - Find", logger.LogData{
 | 
							logger.Error("usermngmt - Role - Find", logger.LogData{
 | 
				
			||||||
			"cond": cond,
 | 
								Source:  "usermngmt.user.roleFindByCondition",
 | 
				
			||||||
			"opts": opts,
 | 
								Message: err.Error(),
 | 
				
			||||||
			"err":  err.Error(),
 | 
								Data: map[string]interface{}{
 | 
				
			||||||
 | 
									"cond": cond,
 | 
				
			||||||
 | 
									"opts": opts,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer cursor.Close(ctx)
 | 
						defer cursor.Close(ctx)
 | 
				
			||||||
	if err = cursor.All(ctx, &docs); err != nil {
 | 
						if err = cursor.All(ctx, &docs); err != nil {
 | 
				
			||||||
		logger.Error("usermngmt - Role - Decode", logger.LogData{
 | 
							logger.Error("usermngmt - Role - Decode", logger.LogData{
 | 
				
			||||||
			"cond": cond,
 | 
								Source:  "usermngmt.user.roleFindByCondition",
 | 
				
			||||||
			"opts": opts,
 | 
								Message: err.Error(),
 | 
				
			||||||
			"err":  err.Error(),
 | 
								Data: map[string]interface{}{
 | 
				
			||||||
 | 
									"cond": cond,
 | 
				
			||||||
 | 
									"opts": opts,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -115,18 +124,24 @@ func permissionFindByCondition(ctx context.Context, cond interface{}, opts ...*o
 | 
				
			||||||
	cursor, err := col.Find(ctx, cond, opts...)
 | 
						cursor, err := col.Find(ctx, cond, opts...)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Error("usermngmt - Permission - Find", logger.LogData{
 | 
							logger.Error("usermngmt - Permission - Find", logger.LogData{
 | 
				
			||||||
			"cond": cond,
 | 
								Source:  "usermngmt.user.permissionFindByCondition",
 | 
				
			||||||
			"opts": opts,
 | 
								Message: err.Error(),
 | 
				
			||||||
			"err":  err.Error(),
 | 
								Data: map[string]interface{}{
 | 
				
			||||||
 | 
									"cond": cond,
 | 
				
			||||||
 | 
									"opts": opts,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer cursor.Close(ctx)
 | 
						defer cursor.Close(ctx)
 | 
				
			||||||
	if err = cursor.All(ctx, &docs); err != nil {
 | 
						if err = cursor.All(ctx, &docs); err != nil {
 | 
				
			||||||
		logger.Error("usermngmt - Permission - Decode", logger.LogData{
 | 
							logger.Error("usermngmt - Permission - Decode", logger.LogData{
 | 
				
			||||||
			"cond": cond,
 | 
								Source:  "usermngmt.user.permissionFindByCondition",
 | 
				
			||||||
			"opts": opts,
 | 
								Message: err.Error(),
 | 
				
			||||||
			"err":  err.Error(),
 | 
								Data: map[string]interface{}{
 | 
				
			||||||
 | 
									"cond": cond,
 | 
				
			||||||
 | 
									"opts": opts,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -141,8 +156,9 @@ func permissionCountByCondition(ctx context.Context, cond interface{}) int64 {
 | 
				
			||||||
	total, err := col.CountDocuments(ctx, cond)
 | 
						total, err := col.CountDocuments(ctx, cond)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Error("usermngmt - Permission - CountDocuments", logger.LogData{
 | 
							logger.Error("usermngmt - Permission - CountDocuments", logger.LogData{
 | 
				
			||||||
			"err":  err.Error(),
 | 
								Source:  "usermngmt.user.permissionCountByCondition",
 | 
				
			||||||
			"cond": cond,
 | 
								Message: err.Error(),
 | 
				
			||||||
 | 
								Data:    cond,
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return total
 | 
						return total
 | 
				
			||||||
| 
						 | 
					@ -155,8 +171,9 @@ func create(ctx context.Context, doc model.DBUser) error {
 | 
				
			||||||
	_, err := col.InsertOne(ctx, doc)
 | 
						_, err := col.InsertOne(ctx, doc)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Error("usermngmt - User - InsertOne", logger.LogData{
 | 
							logger.Error("usermngmt - User - InsertOne", logger.LogData{
 | 
				
			||||||
			"doc": doc,
 | 
								Source:  "usermngmt.user.create",
 | 
				
			||||||
			"err": err.Error(),
 | 
								Message: err.Error(),
 | 
				
			||||||
 | 
								Data:    doc,
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		return fmt.Errorf("error when create user: %s", err.Error())
 | 
							return fmt.Errorf("error when create user: %s", err.Error())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -171,9 +188,12 @@ func updateOneByCondition(ctx context.Context, cond interface{}, payload interfa
 | 
				
			||||||
	_, err := col.UpdateOne(ctx, cond, payload)
 | 
						_, err := col.UpdateOne(ctx, cond, payload)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Error("usermngmt - User - UpdateOne", logger.LogData{
 | 
							logger.Error("usermngmt - User - UpdateOne", logger.LogData{
 | 
				
			||||||
			"cond":    cond,
 | 
								Source:  "usermngmt.user.updateOneByCondition",
 | 
				
			||||||
			"payload": payload,
 | 
								Message: err.Error(),
 | 
				
			||||||
			"err":     err.Error(),
 | 
								Data: map[string]interface{}{
 | 
				
			||||||
 | 
									"cond":    cond,
 | 
				
			||||||
 | 
									"payload": payload,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		return fmt.Errorf("error when update user: %s", err.Error())
 | 
							return fmt.Errorf("error when update user: %s", err.Error())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -188,9 +208,12 @@ func updateManyByCondition(ctx context.Context, cond interface{}, payload interf
 | 
				
			||||||
	_, err := col.UpdateMany(ctx, cond, payload)
 | 
						_, err := col.UpdateMany(ctx, cond, payload)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Error("usermngmt - User - UpdateMany", logger.LogData{
 | 
							logger.Error("usermngmt - User - UpdateMany", logger.LogData{
 | 
				
			||||||
			"cond":    cond,
 | 
								Source:  "usermngmt.user.updateManyByCondition",
 | 
				
			||||||
			"payload": payload,
 | 
								Message: err.Error(),
 | 
				
			||||||
			"err":     err.Error(),
 | 
								Data: map[string]interface{}{
 | 
				
			||||||
 | 
									"cond":    cond,
 | 
				
			||||||
 | 
									"payload": payload,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		return fmt.Errorf("error when update user: %s", err.Error())
 | 
							return fmt.Errorf("error when update user: %s", err.Error())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -216,18 +239,24 @@ func findByCondition(ctx context.Context, cond interface{}, opts ...*options.Fin
 | 
				
			||||||
	cursor, err := col.Find(ctx, cond, opts...)
 | 
						cursor, err := col.Find(ctx, cond, opts...)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Error("usermngmt - User - Find", logger.LogData{
 | 
							logger.Error("usermngmt - User - Find", logger.LogData{
 | 
				
			||||||
			"cond": cond,
 | 
								Source:  "usermngmt.user.findByCondition",
 | 
				
			||||||
			"opts": opts,
 | 
								Message: err.Error(),
 | 
				
			||||||
			"err":  err.Error(),
 | 
								Data: map[string]interface{}{
 | 
				
			||||||
 | 
									"cond": cond,
 | 
				
			||||||
 | 
									"opts": opts,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer cursor.Close(ctx)
 | 
						defer cursor.Close(ctx)
 | 
				
			||||||
	if err = cursor.All(ctx, &docs); err != nil {
 | 
						if err = cursor.All(ctx, &docs); err != nil {
 | 
				
			||||||
		logger.Error("usermngmt - User - Decode", logger.LogData{
 | 
							logger.Error("usermngmt - User - Decode", logger.LogData{
 | 
				
			||||||
			"cond": cond,
 | 
								Source:  "usermngmt.user.findByCondition",
 | 
				
			||||||
			"opts": opts,
 | 
								Message: err.Error(),
 | 
				
			||||||
			"err":  err.Error(),
 | 
								Data: map[string]interface{}{
 | 
				
			||||||
 | 
									"cond": cond,
 | 
				
			||||||
 | 
									"opts": opts,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -242,8 +271,11 @@ func countByCondition(ctx context.Context, cond interface{}) int64 {
 | 
				
			||||||
	total, err := col.CountDocuments(ctx, cond)
 | 
						total, err := col.CountDocuments(ctx, cond)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Error("usermngmt - Count", logger.LogData{
 | 
							logger.Error("usermngmt - Count", logger.LogData{
 | 
				
			||||||
			"err":  err.Error(),
 | 
								Source:  "usermngmt.user.countByCondition",
 | 
				
			||||||
			"cond": cond,
 | 
								Message: err.Error(),
 | 
				
			||||||
 | 
								Data: map[string]interface{}{
 | 
				
			||||||
 | 
									"cond": cond,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return total
 | 
						return total
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue