Add full project files

This commit is contained in:
root
2026-07-04 19:24:56 +03:30
parent d54f5441a3
commit b245e7b71a
835 changed files with 30149 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
/* eslint-disable camelcase */
const { default: mongoose } = require('mongoose')
const PaymentModel = require('../../../models/PaymentModel')
const jMoment = require('moment-jalaali')
const getFinancial = async (req, res) => {
try {
const token = req.header('Authorization').split(' ')[1]
if (!token) return res.status(401).send('Access Denied')
const {
page = 1, limit = 10,
startDate,
endDate,
status
} = req.query
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: 'user_id',
select: '_id user_name first_name mobile last_name '
},
{
path: 'project_id',
select: '_id title project_type'
}
]
}
const financial = await PaymentModel.paginate(
filter, // فیلتر
options // گزینه‌های پیجینیشن
)
const financialList = financial?.docs.map(financia => {
const jDate = jMoment(financia.createdAt).format('jYYYY-jMM-jDD HH:mm')
return {
...financia._doc,
createdAt: jDate
}
})
res.json({
financials: financialList,
totalPages: financial.totalPages, // ارسال تعداد کل صفحات
totalItems: financial.totalDocs // ارسال تعداد کل آیتم‌ها
})
} catch (error) {
console.error('Error occurred:', error)
res.status(500).json({ error: 'Internal server error' })
}
}
const getFinancialDetail = async (req, res, next) => {
try {
const token = req.header('Authorization').split(' ')[1]
if (!token) return res.status(401).send('Access Denied')
const financial_id = req.query.financial_id
if (!mongoose.Types.ObjectId.isValid(financial_id)) {
return res.status(400).json({ message: 'شناسه تراکنش معتبر نیست' })
}
const financial = await PaymentModel.findById(financial_id).populate([
{
path: 'user_id',
select: '_id user_name first_name mobile last_name shaba'
},
{
path: 'project_id',
select: '_id title project_type',
populate: {
path: 'selected_user',
select: '_id user_name first_name mobile last_name shaba'
}
}
])
if (!financial) {
return res.status(404).json({ message: 'تراکنش مورد نظر یافت نشد' })
}
const newfinancial = {
...financial._doc,
createdAt: jMoment(financial.createdAt).format('jYYYY-jMM-jDD HH:mm')
}
return res.status(200).json({ financial: newfinancial })
} catch (error) {
console.error('Error occurred:', error)
res.status(500).json({ error: 'Internal server error' })
}
}
module.exports = { getFinancial, getFinancialDetail }