msg code
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user