msg code
This commit is contained in:
@@ -26,10 +26,10 @@ module.exports = {
|
|||||||
id: phone,
|
id: phone,
|
||||||
type: CODE_TYPE[type]
|
type: CODE_TYPE[type]
|
||||||
});
|
});
|
||||||
if (exist) return {
|
// if (exist) return {
|
||||||
code: 1,
|
// code: 1,
|
||||||
error: '请勿多次请求'
|
// error: '请勿多次请求'
|
||||||
};
|
// };
|
||||||
if (phone && type && validCodeType) {
|
if (phone && type && validCodeType) {
|
||||||
const code = Crypto.randomNumber({length: 6});
|
const code = Crypto.randomNumber({length: 6});
|
||||||
const [ sms, save ] = await Promise.all([
|
const [ sms, save ] = await Promise.all([
|
||||||
@@ -42,7 +42,7 @@ module.exports = {
|
|||||||
id: phone,
|
id: phone,
|
||||||
code,
|
code,
|
||||||
type: CODE_TYPE[type]
|
type: CODE_TYPE[type]
|
||||||
})
|
}, exist)
|
||||||
]).catch(err => {
|
]).catch(err => {
|
||||||
mylog.error(err);
|
mylog.error(err);
|
||||||
return [null, null];
|
return [null, null];
|
||||||
@@ -57,8 +57,13 @@ module.exports = {
|
|||||||
error: 'Invalid param'
|
error: 'Invalid param'
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
async saveCode (data) {
|
async saveCode (data, exist) {
|
||||||
const res = await (new Code({ ...data })).save();
|
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) {
|
if(!res) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user