This commit is contained in:
Mr Swift
2024-08-26 21:16:52 +03:30
parent 01a2871103
commit b120ae1708
5 changed files with 21 additions and 11 deletions
+15 -6
View File
@@ -239,6 +239,12 @@ module.exports.update_user = [
address,
cell_number
}
if (req.files?.image) {
const image = req.files?.image
const fileName = 'profile' + Date.now() + '.' + image.name
await image.mv(`./static/uploads/images/${fileName}`)
data.profilePic = `/uploads/images/${fileName}`
}
data.first_name = nameOptimizer(first_name)
await User.findByIdAndUpdate(
req.params.id,
@@ -247,7 +253,7 @@ module.exports.update_user = [
return res.json({ message: _faSr.response.success_save })
} catch (err) {
const registerFailurMsg = 'مشکلی در به روز رسانی پیش آمده، لطفا مجددا تلاش کنید'
res500(res, registerFailurMsg)
throw new Error(registerFailurMsg)
}
}
]
@@ -280,7 +286,7 @@ module.exports.update_user_password = [
await user.save()
return res.json({ message: _faSr.response.success_save })
} catch (err) {
if (err) return res500(res, err)
throw new Error(err.message)
}
}
]
@@ -296,11 +302,14 @@ module.exports.send_otp = [
try {
const { mobile_number } = req.body
const user = await User.findOne({ mobile_number })
if (!user) throw new Error(_sr.fa.not_found.user_id)
if (!user) {
res.status(404)
throw new Error(_sr.fa.not_found.user_id)
}
await sendConfirmationSMS(user.id)
res.status(200).json({ msg: "ok" })
} catch (err) {
if (err) return res500(res, err)
throw new Error(err.message)
}
}
]
@@ -323,7 +332,7 @@ module.exports.check_otp = [
if (user.otp !== otp) throw new Error("کد اشتباه است")
if (user.otp === otp) res.status(200).json({ msg: "ok" })
} catch (err) {
if (err) return res500(res, err.message)
throw new Error(err.message)
}
}
]
@@ -360,7 +369,7 @@ module.exports.resetpass_otp = [
res.status(200).json({ msg: _sr.fa.response.success_save })
}
} catch (err) {
if (err) return res500(res, err.message)
throw new Error(err.message)
}
}
]
+3 -1
View File
@@ -156,4 +156,6 @@ module.exports.updateReq = [
}
}
}
]
]
+2 -2
View File
@@ -1575,9 +1575,9 @@ module.exports.getUser = [
const user = await User.findById(decoded?._id).select(
'-token -appToken -emailConfirmationKey -mobileConfirmationKey -password -resetPassToken'
)
return res.json({ user })
return res.status(200).json({ user })
} catch (err) {
console.log('🚀 ~ file: userController.js ~ line 1070 ~ err', err)
console.log('🚀 ~ file: userController.js ~ line 1580 ~ err', err)
return res.status(401).json({ message: 'unauthenticated' })
}
}
+1 -1
View File
@@ -5,7 +5,7 @@ const inHostUrl = 'mongodb://root:KPTt76tImNBBMm4Kor8QA9gB@asan-service:27017/as
const outHostUrl = 'mongodb://root:KPTt76tImNBBMm4Kor8QA9gB@hotaka.liara.cloud:33794/asanserv_database?authSource=admin'
const init = ()=>{
try {
mongoose.connect(outHostUrl, {
mongoose.connect(inHostUrl, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
@@ -24,7 +24,6 @@ const serialChecker = (serial, type = 'guaranteeSerial', g = 1) => {
serialFiles.forEach(async (file, i) => {
if (file.split('.').some(item => ['xlsx', 'xltx', 'xlsm', 'xlsb'].includes(item))) {
const exelFile = await readXlsxFile(`${exelsPath}/${file}`);
console.log(file);
for (const row of exelFile) {
// eslint-disable-next-line eqeqeq