/**
 * Created by raychen on 16/8/16.
 */

import {userSchema} from '../../models/userSchema'
import {connect_callback} from '../config'

async function getStarRepoByUser(login){
  let t = await new Promise(function (resolve, reject) {
    let ans = [];
    userSchema.findOne({login: login}, (err, user) => {
      if (err) reject(err);
      ans = user.star_repos;
      resolve(ans);
    });
  });
  return t;
}

function findLevel(user, langName){
  for (let lang of user.language){
    if (lang.lang_name == langName) return lang.lang_level;
  }
  return -1;
}

async function getUserAndLevelByLanguage(language){
  //暂时用最简单的取出全部用户
  let promise = await new Promise(function(resolve, reject){
    userSchema.find({}, (err, users) => {
      if (err) reject(err);
      let ans = [];
      for (let user of users){
        let level = findLevel(user, language);
        if (level>=0)
          ans.push({
            login: user.login,
            lan_level: level
          })
      }
      resolve(ans);
    });
  });
  return promise;
}

async function test(){
  connect_callback(async (v) => {
    if (v == 1){
      let t = await getStarRepoByUser("RickChem");
      console.log(t);
    }
  });
}

//test();

@@ -87,16 +87,81 @@
 Schema'%0A
+import %7Bgithub_repoSchema%7D from '../../models/github_repoSchema'%0A
 import %7B
@@ -302,30 +302,247 @@
     
-let ans = %5B%5D;%0A    user
+userSchema.findOne(%7Blogin: login%7D, async (err, user) =%3E %7B%0A      if (err) reject(err);%0A      let ans = %5B%5D;%0A      for (let repo of user.star_repos)%7B%0A        let repo_det = await new Promise(function(resolve2, reject2) %7B%0A          github_repo
 Sche
@@ -553,28 +553,31 @@
 indOne(%7B
-login: login
+full_name: repo
 %7D, (err,
@@ -573,28 +573,32 @@
 epo%7D, (err, 
-user
+repo_one
 ) =%3E %7B%0A     
@@ -590,32 +590,38 @@
 one) =%3E %7B%0A      
+ 
+     
 if (err) reject(
@@ -611,32 +611,33 @@
  if (err) reject
+2
 (err);%0A      ans
@@ -637,30 +637,161 @@
     
+ 
-ans = user.
+     resolve2(repo_one.stars_count);%0A          %7D);%0A        %7D);%0A        ans.push(%7B%0A          fullname: repo,%0A          
 star
-_
+s: 
 repo
-s;
+_det%0A        %7D)%0A      %7D
 %0A   
@@ -1461,24 +1461,79 @@
 promise;%0A%7D%0A%0A
+export %7BgetStarRepoByUser, getUserAndLevelByLanguage%7D%0A%0A
 async functi

add repodao