Initial commit

This commit is contained in:
payacom
2026-07-07 17:50:26 +03:30
parent 525565d685
commit 64eb8c288f
25 changed files with 801 additions and 231 deletions

View File

@@ -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()

View File

@@ -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
}

View File

@@ -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()