明树Git Lab

Commit d428878a authored by zfp1's avatar zfp1

update

parent 96436937
...@@ -44,7 +44,12 @@ async function getUserInfo(req, res, next) { ...@@ -44,7 +44,12 @@ async function getUserInfo(req, res, next) {
) )
console.log(userRes.data) console.log(userRes.data)
// 第三步 存起来 // 第三步 存起来
let user = await userModule.findUser({openid});
if(user&&user._id) {
//
} else {
await userModule.createUser(userRes.data); await userModule.createUser(userRes.data);
}
res.sendData(userRes.data) res.sendData(userRes.data)
} catch (error) { } catch (error) {
console.error(' 微信接口错误:', error) console.error(' 微信接口错误:', error)
......
...@@ -34,5 +34,5 @@ const questionSchema = new Schema({ ...@@ -34,5 +34,5 @@ const questionSchema = new Schema({
}); });
const Question = mongoose.model('Question', questionSchema, 'Question'); const Question = mongoose.model('question', questionSchema, 'Question');
module.exports = Question; module.exports = Question;
\ No newline at end of file
...@@ -4,5 +4,12 @@ async function createUser(obj) { ...@@ -4,5 +4,12 @@ async function createUser(obj) {
const ret = await DB.User.create(obj); const ret = await DB.User.create(obj);
return ret; return ret;
} }
async function findUser(obj) {
if(!obj.openid) {
throw new Error("openid没找到")
}
const ret = await DB.User.findOne({openid: obj && obj.openid});
return ret;
}
module.exports = {createUser} module.exports = {createUser, findUser}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment