This commit is contained in:
chaosBreaking
2019-10-09 22:47:33 +08:00
parent 6d7e094022
commit 4da8a11bea

View File

@@ -26,10 +26,10 @@ module.exports = {
id: phone,
type: CODE_TYPE[type]
});
if (exist) return {
code: 1,
error: '请勿多次请求'
};
// if (exist) return {
// code: 1,
// error: '请勿多次请求'
// };
if (phone && type && validCodeType) {
const code = Crypto.randomNumber({length: 6});
const [ sms, save ] = await Promise.all([
@@ -42,7 +42,7 @@ module.exports = {
id: phone,
code,
type: CODE_TYPE[type]
})
}, exist)
]).catch(err => {
mylog.error(err);
return [null, null];
@@ -57,8 +57,13 @@ module.exports = {
error: 'Invalid param'
};
},
async saveCode (data) {
const res = await (new Code({ ...data })).save();
async saveCode (data, exist) {
let res;
if (!exist) {
res = await (new Code({ ...data })).save();
} else {
res = await Code.findOneAndUpdate({ id: data.id, type: data.type }, { code: data.code });
}
if(!res) {
return false;
} else {