Initial commit
This commit is contained in:
@@ -9,7 +9,18 @@ const setAddress = async (req, res, next) => {
|
||||
if (!token) return res.status(401).send('Access Denied')
|
||||
const { province_id, city_id, address, lat, lng, show_location } = req.body
|
||||
// اعتبارسنجی دادهها
|
||||
if (!province_id || !city_id || !address || !lat || !lng || show_location === 'undefined') {
|
||||
if (
|
||||
!province_id ||
|
||||
!city_id ||
|
||||
!address ||
|
||||
lat === undefined ||
|
||||
lat === null ||
|
||||
lat === '' ||
|
||||
lng === undefined ||
|
||||
lng === null ||
|
||||
lng === '' ||
|
||||
show_location === undefined
|
||||
) {
|
||||
return res.status(422).json({
|
||||
error: true,
|
||||
message: 'اطلاعات ارسالی ناقص است'
|
||||
@@ -41,7 +52,8 @@ const setAddress = async (req, res, next) => {
|
||||
user.address = address
|
||||
user.lat = lat
|
||||
user.lng = lng
|
||||
user.show_location = show_location
|
||||
user.show_location =
|
||||
show_location === true || show_location === 'true'
|
||||
|
||||
await user.save()
|
||||
|
||||
@@ -60,7 +72,18 @@ const updateAddress = async (req, res, next) => {
|
||||
const { province_id, city_id, address, lat, lng, show_location } = req.body
|
||||
|
||||
// اعتبارسنجی دادهها
|
||||
if (!province_id || !city_id || !address || !lat || !lng || show_location === undefined) {
|
||||
if (
|
||||
!province_id ||
|
||||
!city_id ||
|
||||
!address ||
|
||||
lat === undefined ||
|
||||
lat === null ||
|
||||
lat === '' ||
|
||||
lng === undefined ||
|
||||
lng === null ||
|
||||
lng === '' ||
|
||||
show_location === undefined
|
||||
) {
|
||||
return res.status(422).json({
|
||||
error: true,
|
||||
message: 'اطلاعات ارسالی ناقص است'
|
||||
@@ -95,7 +118,8 @@ const updateAddress = async (req, res, next) => {
|
||||
user.address = address
|
||||
user.lat = lat
|
||||
user.lng = lng
|
||||
user.show_location = show_location
|
||||
user.show_location =
|
||||
show_location === true || show_location === 'true'
|
||||
|
||||
await user.save()
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
const UserModel = require('../../../models/UserModel')
|
||||
const jwt = require('jsonwebtoken')
|
||||
|
||||
const completeRegistration = async (req, res, next) => {
|
||||
try {
|
||||
const token = req.header('Authorization')?.split(' ')[1]
|
||||
if (!token) return res.status(401).send('Access Denied')
|
||||
|
||||
const decodedToken = jwt.verify(token, process.env.APP_SECRET)
|
||||
const user = await UserModel.findById(decodedToken.id)
|
||||
|
||||
if (!user) {
|
||||
return res.status(404).json({
|
||||
error: true,
|
||||
message: 'کاربر یافت نشد'
|
||||
})
|
||||
}
|
||||
|
||||
user.is_Register = true
|
||||
|
||||
if (!user.is_verified || user.is_verified === 'none') {
|
||||
user.is_verified = 'pending'
|
||||
}
|
||||
|
||||
await user.save()
|
||||
|
||||
return res.json({
|
||||
message: 'ثبت نام تکمیل شد',
|
||||
is_verified: user.is_verified,
|
||||
is_Register: user.is_Register
|
||||
})
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
completeRegistration
|
||||
}
|
||||
@@ -38,6 +38,7 @@ const setNationalCardImage = async (req, res, next) => {
|
||||
|
||||
// ذخیره مسیر فایل در دیتابیس
|
||||
user.national_card_image = `/carts/${uniqueFileName}`
|
||||
user.is_Register = true
|
||||
user.is_verified = 'pending'
|
||||
await user.save()
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ const setProfileImage = async (req, res, next) => {
|
||||
}
|
||||
|
||||
// ذخیره فایل عکس پروفایل
|
||||
const uploadDir = path.join(__dirname, '../../../../storage/profiles')
|
||||
const uploadDir = path.join(__dirname, '../../../storage/profiles')
|
||||
if (!fs.existsSync(uploadDir)) {
|
||||
fs.mkdirSync(uploadDir, { recursive: true })
|
||||
}
|
||||
@@ -78,7 +78,7 @@ const updateProfileImage = async (req, res, next) => {
|
||||
})
|
||||
}
|
||||
|
||||
const uploadDir = path.join(__dirname, '../../../../storage/profiles')
|
||||
const uploadDir = path.join(__dirname, '../../../storage/profiles')
|
||||
|
||||
if (!fs.existsSync(uploadDir)) {
|
||||
fs.mkdirSync(uploadDir, { recursive: true })
|
||||
|
||||
Reference in New Issue
Block a user