fix: resolve MongoDB connection and port configuration issues
- Added dotenv configuration for environment variables - Fixed MongoDB connection string loading - Configured server port to 3005 - Updated cron jobs for expired messages
This commit is contained in:
@@ -1,256 +1,256 @@
|
||||
/* eslint-disable camelcase */
|
||||
const ProjectModel = require('../../../models/ProjectModel')
|
||||
const jMoment = require('moment-jalaali')
|
||||
const RequestModel = require('../../../models/RequestModel')
|
||||
const NotificationModel = require('../../../models/NotificationModel')
|
||||
|
||||
const getProjects = async (req, res, next) => {
|
||||
try {
|
||||
const token = req.header('Authorization').split(' ')[1]
|
||||
if (!token) return res.status(401).send('Access Denied')
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const {
|
||||
page = 1, limit = 10,
|
||||
startDate,
|
||||
endDate,
|
||||
status
|
||||
} = req.query
|
||||
// ساخت فیلتر برای استفاده در جستجوی MongoDB
|
||||
const filter = {
|
||||
} // افزودن شرطهای دیگر برای فیلتر
|
||||
// Date
|
||||
if (startDate || endDate) {
|
||||
filter.createdAt = {}
|
||||
|
||||
if (startDate) {
|
||||
filter.createdAt.$gte = new Date(startDate) // تاریخ شروع
|
||||
}
|
||||
|
||||
if (endDate) {
|
||||
filter.createdAt.$lte = new Date(endDate) // تاریخ پایان
|
||||
}
|
||||
}
|
||||
|
||||
if (status) {
|
||||
filter.status = status
|
||||
}
|
||||
|
||||
// دریافت لیست پروژهها با استفاده از فیلتر و گزینههای صفحهبندی
|
||||
const options = {
|
||||
page: parseInt(page), // تبدیل صفحه به عدد صحیح
|
||||
limit: parseInt(limit), // تبدیل محدودیت به عدد صحیح
|
||||
sort: { createdAt: -1 },
|
||||
populate: [
|
||||
{ path: 'creator_id', select: '_id user_name first_name last_name' },
|
||||
{ path: 'selected_user', select: '_id user_name first_name last_name' }
|
||||
]
|
||||
}
|
||||
const projects = await ProjectModel.paginate(filter, options)
|
||||
const projectsList = projects.docs.map(project => ({
|
||||
_id: project._id,
|
||||
title: project.title,
|
||||
expertise: project.expertise,
|
||||
sub_expertise: project.sub_expertise,
|
||||
offer_time: project.offer_time,
|
||||
offer_price: project.offer_price,
|
||||
final_price: project.final_price,
|
||||
final_time: project.final_time,
|
||||
createdAt: jMoment(project.createdAt).format('jYYYY-jMM-jDD HH:mm'),
|
||||
status: project.status,
|
||||
creator: project.creator_id
|
||||
? {
|
||||
_id: project.creator_id._id,
|
||||
user_name: project.creator_id.user_name,
|
||||
first_name: project.creator_id.first_name,
|
||||
last_name: project.creator_id.last_name
|
||||
}
|
||||
: null,
|
||||
selected_user: project.selected_user
|
||||
? {
|
||||
_id: project.selected_user._id,
|
||||
user_name: project.selected_user.user_name,
|
||||
first_name: project.selected_user.first_name,
|
||||
last_name: project.selected_user.last_name
|
||||
}
|
||||
: null
|
||||
}))
|
||||
|
||||
res.status(200).json({
|
||||
projects: projectsList,
|
||||
totalPages: projects.totalPages, // ارسال تعداد کل صفحات
|
||||
totalItems: projects.totalDocs // ارسال تعداد کل آیتمها
|
||||
})
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
const getProjectDetails = async (req, res, next) => {
|
||||
try {
|
||||
const { project_id } = req.query
|
||||
|
||||
// بررسی وجود projectId
|
||||
if (!project_id) {
|
||||
return res.status(400).send('Project ID is required')
|
||||
}
|
||||
|
||||
// یافتن پروژه و جمعآوری اطلاعات مرتبط با سازنده و کاربر انتخاب شده
|
||||
const project = await ProjectModel.findById(project_id)
|
||||
.populate('creator_id', '_id user_name first_name last_name mobile')
|
||||
.populate('selected_user', '_id user_name first_name last_name mobile')
|
||||
.lean()
|
||||
|
||||
// بررسی وجود پروژه
|
||||
if (!project) {
|
||||
return res.status(404).send('Project not found')
|
||||
}
|
||||
|
||||
// دریافت لیست درخواستهای پروژه
|
||||
const projectRequests = await RequestModel.find({ project: project_id })
|
||||
.populate('user', '_id first_name last_name user_name rate profile_image')
|
||||
.sort({ status: 1 })
|
||||
.lean()
|
||||
|
||||
// ساختاردهی پاسخ نهایی
|
||||
const projectDetails = {
|
||||
_id: project._id,
|
||||
title: project.title,
|
||||
description: project.description,
|
||||
creator: project.creator_id
|
||||
? {
|
||||
_id: project.creator_id._id,
|
||||
first_name: project.creator_id.first_name,
|
||||
last_name: project.creator_id.last_name,
|
||||
user_name: project.creator_id.user_name,
|
||||
mobile: project.creator_id.mobile
|
||||
}
|
||||
: null,
|
||||
selected_user: project.selected_user
|
||||
? {
|
||||
_id: project.selected_user._id,
|
||||
first_name: project.selected_user.first_name,
|
||||
last_name: project.creator_id.last_name,
|
||||
user_name: project.selected_user.user_name,
|
||||
mobile: project.selected_user.mobile
|
||||
}
|
||||
: null,
|
||||
province: project.province,
|
||||
city: project.city,
|
||||
createdAt: jMoment(project.createdAt).format('jYYYY-jMM-jDD HH:mm'),
|
||||
expertise: project.expertise,
|
||||
sub_expertise: project.sub_expertise,
|
||||
offer_time: project.offer_time,
|
||||
offer_price: project.offer_price,
|
||||
final_price: project.final_price,
|
||||
final_time: project.final_time,
|
||||
status: project.status,
|
||||
reject_reason: project.reject_reason,
|
||||
requested_users: projectRequests.map(request => ({
|
||||
_id: request.user._id,
|
||||
first_name: request.user.first_name,
|
||||
last_name: request.user.last_name,
|
||||
user_name: request.user.user_name,
|
||||
profile_image: request.user.profile_image,
|
||||
time: request.time,
|
||||
price: request.price
|
||||
}))
|
||||
}
|
||||
|
||||
res.status(200).json({ project: projectDetails })
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
const acceptProject = async (req, res, next) => {
|
||||
try {
|
||||
const token = req.header('Authorization').split(' ')[1]
|
||||
if (!token) return res.status(401).send('Access Denied')
|
||||
|
||||
const { id, user_name } = req.body
|
||||
|
||||
if (!id) {
|
||||
return res.status(422).json({
|
||||
error: true,
|
||||
message: 'اطلاعات ارسالی اشتباه است'
|
||||
})
|
||||
}
|
||||
|
||||
const project = await ProjectModel.findById(id)
|
||||
|
||||
if (!project) {
|
||||
return res.status(404).json({
|
||||
error: true,
|
||||
message: 'پست مورد نظر یافت نشد'
|
||||
})
|
||||
}
|
||||
project.acceptedAt = new Date()
|
||||
project.status = 'accepted'
|
||||
await project.save()
|
||||
const notification = new NotificationModel({
|
||||
user_id: project?.creator_id,
|
||||
project_post_id: project?._id,
|
||||
type: 'accept-project',
|
||||
title: 'انتشار درخواست',
|
||||
description: `درخواست شما با عنوان: ${project?.title} منتشر شد `
|
||||
})
|
||||
await notification.save()
|
||||
if (project?.public_status === 'private' && project?.created_for_user) {
|
||||
const notification = new NotificationModel({
|
||||
user_id: project?.created_for_user,
|
||||
project_post_id: project?._id,
|
||||
type: 'recive-project',
|
||||
title: 'دعوت به همکاری',
|
||||
description: `کاربر ${user_name} برای شما پروژه ایجاد کرده است ، برای نمایش جزئیات لمس کنید`
|
||||
})
|
||||
await notification.save()
|
||||
}
|
||||
res.status(201).json({ message: 'پروژه با موفقیت تایید شد' })
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
const rejectProject = async (req, res, next) => {
|
||||
try {
|
||||
const token = req.header('Authorization').split(' ')[1]
|
||||
if (!token) return res.status(401).send('Access Denied')
|
||||
|
||||
const { id, rejectReason } = req.body
|
||||
|
||||
if (!id) {
|
||||
return res.status(422).json({
|
||||
error: true,
|
||||
message: 'اطلاعات ارسالی اشتباه است'
|
||||
})
|
||||
}
|
||||
|
||||
const project = await ProjectModel.findById(id)
|
||||
|
||||
if (!project) {
|
||||
return res.status(404).json({
|
||||
error: true,
|
||||
message: 'پست مورد نظر یافت نشد'
|
||||
})
|
||||
}
|
||||
|
||||
project.status = 'rejected'
|
||||
project.reject_reason = rejectReason
|
||||
await project.save()
|
||||
const notification = new NotificationModel({
|
||||
user_id: project?.creator_id,
|
||||
project_post_id: project?._id,
|
||||
type: 'reject-project',
|
||||
title: 'رد درخواست',
|
||||
description: `درخواست شما با عنوان: ${project?.title} رد شد، برای دیدن علت رد، لمس کنید `
|
||||
})
|
||||
await notification.save()
|
||||
res.status(201).json({ message: 'پروژه با موفقیت رد شد' })
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
getProjects,
|
||||
getProjectDetails,
|
||||
acceptProject,
|
||||
rejectProject
|
||||
}
|
||||
/* eslint-disable camelcase */
|
||||
const ProjectModel = require('../../../models/ProjectModel')
|
||||
const jMoment = require('moment-jalaali')
|
||||
const RequestModel = require('../../../models/RequestModel')
|
||||
const NotificationModel = require('../../../models/NotificationModel')
|
||||
|
||||
const getProjects = async (req, res, next) => {
|
||||
try {
|
||||
const token = req.header('Authorization').split(' ')[1]
|
||||
if (!token) return res.status(401).send('Access Denied')
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const {
|
||||
page = 1, limit = 10,
|
||||
startDate,
|
||||
endDate,
|
||||
status
|
||||
} = req.query
|
||||
// ساخت فیلتر برای استفاده در جستجوی MongoDB
|
||||
const filter = {
|
||||
} // افزودن شرطهای دیگر برای فیلتر
|
||||
// Date
|
||||
if (startDate || endDate) {
|
||||
filter.createdAt = {}
|
||||
|
||||
if (startDate) {
|
||||
filter.createdAt.$gte = new Date(startDate) // تاریخ شروع
|
||||
}
|
||||
|
||||
if (endDate) {
|
||||
filter.createdAt.$lte = new Date(endDate) // تاریخ پایان
|
||||
}
|
||||
}
|
||||
|
||||
if (status) {
|
||||
filter.status = status
|
||||
}
|
||||
|
||||
// دریافت لیست پروژهها با استفاده از فیلتر و گزینههای صفحهبندی
|
||||
const options = {
|
||||
page: parseInt(page), // تبدیل صفحه به عدد صحیح
|
||||
limit: parseInt(limit), // تبدیل محدودیت به عدد صحیح
|
||||
sort: { createdAt: -1 },
|
||||
populate: [
|
||||
{ path: 'creator_id', select: '_id user_name first_name last_name' },
|
||||
{ path: 'selected_user', select: '_id user_name first_name last_name' }
|
||||
]
|
||||
}
|
||||
const projects = await ProjectModel.paginate(filter, options)
|
||||
const projectsList = projects.docs.map(project => ({
|
||||
_id: project._id,
|
||||
title: project.title,
|
||||
expertise: project.expertise,
|
||||
sub_expertise: project.sub_expertise,
|
||||
offer_time: project.offer_time,
|
||||
offer_price: project.offer_price,
|
||||
final_price: project.final_price,
|
||||
final_time: project.final_time,
|
||||
createdAt: jMoment(project.createdAt).format('jYYYY-jMM-jDD HH:mm'),
|
||||
status: project.status,
|
||||
creator: project.creator_id
|
||||
? {
|
||||
_id: project.creator_id._id,
|
||||
user_name: project.creator_id.user_name,
|
||||
first_name: project.creator_id.first_name,
|
||||
last_name: project.creator_id.last_name
|
||||
}
|
||||
: null,
|
||||
selected_user: project.selected_user
|
||||
? {
|
||||
_id: project.selected_user._id,
|
||||
user_name: project.selected_user.user_name,
|
||||
first_name: project.selected_user.first_name,
|
||||
last_name: project.selected_user.last_name
|
||||
}
|
||||
: null
|
||||
}))
|
||||
|
||||
res.status(200).json({
|
||||
projects: projectsList,
|
||||
totalPages: projects.totalPages, // ارسال تعداد کل صفحات
|
||||
totalItems: projects.totalDocs // ارسال تعداد کل آیتمها
|
||||
})
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
const getProjectDetails = async (req, res, next) => {
|
||||
try {
|
||||
const { project_id } = req.query
|
||||
|
||||
// بررسی وجود projectId
|
||||
if (!project_id) {
|
||||
return res.status(400).send('Project ID is required')
|
||||
}
|
||||
|
||||
// یافتن پروژه و جمعآوری اطلاعات مرتبط با سازنده و کاربر انتخاب شده
|
||||
const project = await ProjectModel.findById(project_id)
|
||||
.populate('creator_id', '_id user_name first_name last_name mobile')
|
||||
.populate('selected_user', '_id user_name first_name last_name mobile')
|
||||
.lean()
|
||||
|
||||
// بررسی وجود پروژه
|
||||
if (!project) {
|
||||
return res.status(404).send('Project not found')
|
||||
}
|
||||
|
||||
// دریافت لیست درخواستهای پروژه
|
||||
const projectRequests = await RequestModel.find({ project: project_id })
|
||||
.populate('user', '_id first_name last_name user_name rate profile_image')
|
||||
.sort({ status: 1 })
|
||||
.lean()
|
||||
|
||||
// ساختاردهی پاسخ نهایی
|
||||
const projectDetails = {
|
||||
_id: project._id,
|
||||
title: project.title,
|
||||
description: project.description,
|
||||
creator: project.creator_id
|
||||
? {
|
||||
_id: project.creator_id._id,
|
||||
first_name: project.creator_id.first_name,
|
||||
last_name: project.creator_id.last_name,
|
||||
user_name: project.creator_id.user_name,
|
||||
mobile: project.creator_id.mobile
|
||||
}
|
||||
: null,
|
||||
selected_user: project.selected_user
|
||||
? {
|
||||
_id: project.selected_user._id,
|
||||
first_name: project.selected_user.first_name,
|
||||
last_name: project.creator_id.last_name,
|
||||
user_name: project.selected_user.user_name,
|
||||
mobile: project.selected_user.mobile
|
||||
}
|
||||
: null,
|
||||
province: project.province,
|
||||
city: project.city,
|
||||
createdAt: jMoment(project.createdAt).format('jYYYY-jMM-jDD HH:mm'),
|
||||
expertise: project.expertise,
|
||||
sub_expertise: project.sub_expertise,
|
||||
offer_time: project.offer_time,
|
||||
offer_price: project.offer_price,
|
||||
final_price: project.final_price,
|
||||
final_time: project.final_time,
|
||||
status: project.status,
|
||||
reject_reason: project.reject_reason,
|
||||
requested_users: projectRequests.map(request => ({
|
||||
_id: request.user._id,
|
||||
first_name: request.user.first_name,
|
||||
last_name: request.user.last_name,
|
||||
user_name: request.user.user_name,
|
||||
profile_image: request.user.profile_image,
|
||||
time: request.time,
|
||||
price: request.price
|
||||
}))
|
||||
}
|
||||
|
||||
res.status(200).json({ project: projectDetails })
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
const acceptProject = async (req, res, next) => {
|
||||
try {
|
||||
const token = req.header('Authorization').split(' ')[1]
|
||||
if (!token) return res.status(401).send('Access Denied')
|
||||
|
||||
const { id, user_name } = req.body
|
||||
|
||||
if (!id) {
|
||||
return res.status(422).json({
|
||||
error: true,
|
||||
message: 'اطلاعات ارسالی اشتباه است'
|
||||
})
|
||||
}
|
||||
|
||||
const project = await ProjectModel.findById(id)
|
||||
|
||||
if (!project) {
|
||||
return res.status(404).json({
|
||||
error: true,
|
||||
message: 'پست مورد نظر یافت نشد'
|
||||
})
|
||||
}
|
||||
project.acceptedAt = new Date()
|
||||
project.status = 'accepted'
|
||||
await project.save()
|
||||
const notification = new NotificationModel({
|
||||
user_id: project?.creator_id,
|
||||
project_post_id: project?._id,
|
||||
type: 'accept-project',
|
||||
title: 'انتشار درخواست',
|
||||
description: `درخواست شما با عنوان: ${project?.title} منتشر شد `
|
||||
})
|
||||
await notification.save()
|
||||
if (project?.public_status === 'private' && project?.created_for_user) {
|
||||
const notification = new NotificationModel({
|
||||
user_id: project?.created_for_user,
|
||||
project_post_id: project?._id,
|
||||
type: 'recive-project',
|
||||
title: 'دعوت به همکاری',
|
||||
description: `کاربر ${user_name} برای شما پروژه ایجاد کرده است ، برای نمایش جزئیات لمس کنید`
|
||||
})
|
||||
await notification.save()
|
||||
}
|
||||
res.status(201).json({ message: 'پروژه با موفقیت تایید شد' })
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
const rejectProject = async (req, res, next) => {
|
||||
try {
|
||||
const token = req.header('Authorization').split(' ')[1]
|
||||
if (!token) return res.status(401).send('Access Denied')
|
||||
|
||||
const { id, rejectReason } = req.body
|
||||
|
||||
if (!id) {
|
||||
return res.status(422).json({
|
||||
error: true,
|
||||
message: 'اطلاعات ارسالی اشتباه است'
|
||||
})
|
||||
}
|
||||
|
||||
const project = await ProjectModel.findById(id)
|
||||
|
||||
if (!project) {
|
||||
return res.status(404).json({
|
||||
error: true,
|
||||
message: 'پست مورد نظر یافت نشد'
|
||||
})
|
||||
}
|
||||
|
||||
project.status = 'rejected'
|
||||
project.reject_reason = rejectReason
|
||||
await project.save()
|
||||
const notification = new NotificationModel({
|
||||
user_id: project?.creator_id,
|
||||
project_post_id: project?._id,
|
||||
type: 'reject-project',
|
||||
title: 'رد درخواست',
|
||||
description: `درخواست شما با عنوان: ${project?.title} رد شد، برای دیدن علت رد، لمس کنید `
|
||||
})
|
||||
await notification.save()
|
||||
res.status(201).json({ message: 'پروژه با موفقیت رد شد' })
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
getProjects,
|
||||
getProjectDetails,
|
||||
acceptProject,
|
||||
rejectProject
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user