# Conflicts:
#	controllers/application/projects/getProjectController.js
#	controllers/application/stories/storyController.js
#	controllers/application/users/getUserController.js
#	controllers/panel/projects/projectController.js
#	index.js
This commit is contained in:
payacom
2026-08-31 20:32:29 +03:30
173 changed files with 21806 additions and 18680 deletions

View File

@@ -1,63 +1,63 @@
const TypeAndPriceModel = require('../../../models/TypeAndPriceModel')
const jwt = require('jsonwebtoken')
const UserModel = require('../../../models/UserModel')
const getProjectTypes = 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 userId = decodedToken.id
const user = await UserModel.findById(userId)
if (!user) {
return res.status(422).json({
error: true,
message: 'کاربر یافت نشد'
})
}
// درخواست انواع پروژه از دیتابیس
let projectTypes = await TypeAndPriceModel.find({}, 'name price')
// بررسی برای مواردی مانند پیدا نشدن انواع پروژه
if (!projectTypes) {
return res.status(404).json({ message: 'انواع پروژه یافت نشد.' })
}
// اگر کاربر درخواست رایگان روزانه نداشته باشد، نوع پروژه رایگان را حذف کنید
if (user.daily_free_request <= 0) {
projectTypes = projectTypes.filter(projectType => projectType.name !== 'free')
}
// ارسال انواع پروژه به کاربر
res.status(200).json({ projectTypes })
} catch (error) {
// در صورت بروز خطا، ارسال پیام خطا به کاربر
console.error('Error in getProjectTypes:', error)
res.status(500).json({ message: 'خطا در دریافت انواع پروژه.' })
}
}
const createProjectTypes = async (req, res, next) => {
try {
const { name, price } = req.body
// بررسی اعتبار ورودی‌ها
if (!name || price == null || price === undefined) {
return res.status(400).json({ message: 'لطفا نام و قیمت پروژه را وارد کنید.' })
}
// ایجاد نوع پروژه جدید
const newType = new TypeAndPriceModel({ name, price })
await newType.save()
// ارسال پیام موفقیت آمیز به کاربر
res.status(201).json({ message: 'نوع پروژه جدید با موفقیت ایجاد شد.' })
} catch (error) {
// در صورت بروز خطا، ارسال پیام خطا به کاربر
console.error('Error in createProjectTypes:', error)
res.status(500).json({ message: 'خطا در ایجاد نوع پروژه.' })
}
}
module.exports = {
getProjectTypes,
createProjectTypes
}
const TypeAndPriceModel = require('../../../models/TypeAndPriceModel')
const jwt = require('jsonwebtoken')
const UserModel = require('../../../models/UserModel')
const getProjectTypes = 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 userId = decodedToken.id
const user = await UserModel.findById(userId)
if (!user) {
return res.status(422).json({
error: true,
message: 'کاربر یافت نشد'
})
}
// درخواست انواع پروژه از دیتابیس
let projectTypes = await TypeAndPriceModel.find({}, 'name price')
// بررسی برای مواردی مانند پیدا نشدن انواع پروژه
if (!projectTypes) {
return res.status(404).json({ message: 'انواع پروژه یافت نشد.' })
}
// اگر کاربر درخواست رایگان روزانه نداشته باشد، نوع پروژه رایگان را حذف کنید
if (user.daily_free_request <= 0) {
projectTypes = projectTypes.filter(projectType => projectType.name !== 'free')
}
// ارسال انواع پروژه به کاربر
res.status(200).json({ projectTypes })
} catch (error) {
// در صورت بروز خطا، ارسال پیام خطا به کاربر
console.error('Error in getProjectTypes:', error)
res.status(500).json({ message: 'خطا در دریافت انواع پروژه.' })
}
}
const createProjectTypes = async (req, res, next) => {
try {
const { name, price } = req.body
// بررسی اعتبار ورودی‌ها
if (!name || price == null || price === undefined) {
return res.status(400).json({ message: 'لطفا نام و قیمت پروژه را وارد کنید.' })
}
// ایجاد نوع پروژه جدید
const newType = new TypeAndPriceModel({ name, price })
await newType.save()
// ارسال پیام موفقیت آمیز به کاربر
res.status(201).json({ message: 'نوع پروژه جدید با موفقیت ایجاد شد.' })
} catch (error) {
// در صورت بروز خطا، ارسال پیام خطا به کاربر
console.error('Error in createProjectTypes:', error)
res.status(500).json({ message: 'خطا در ایجاد نوع پروژه.' })
}
}
module.exports = {
getProjectTypes,
createProjectTypes
}