func (r *RoleMappingRepo) UpdateByID(id int, roleMapping *domain.RoleMapping, context usecases.QueryContext) (*domain.RoleMapping, error) { query, err := r.store.BuildQuery(context.Filter, context.OwnerRelations) if err != nil { return nil, internalerrors.DatabaseError } dbName := utils.ToDBName("roleMappings") oldRoleMapping := &domain.RoleMapping{} err = query.Where(dbName+".id = ?", id).First(oldRoleMapping).Error if err != nil { if strings.Contains(err.Error(), "record not found") { return nil, internalerrors.NotFound } return nil, internalerrors.DatabaseError } roleMapping.ID = oldRoleMapping.ID roleMapping.CreatedAt = oldRoleMapping.CreatedAt err = r.store.GetDB().Save(&roleMapping).Error if err != nil { if strings.Contains(err.Error(), "constraint") { return nil, internalerrors.NewViolatedConstraint(err.Error()) } return nil, internalerrors.DatabaseError } return roleMapping, nil }
func (i *RoleMappingInter) scopeModel(roleMapping *domain.RoleMapping) error { roleMapping.CreatedAt = time.Time{} roleMapping.UpdatedAt = time.Time{} roleMapping.Account = domain.Account{} roleMapping.Role = domain.Role{} return nil }