Skip to content

Commit

Permalink
Merge pull request #29 from percyps2401/main
Browse files Browse the repository at this point in the history
added filter for admin , consumer and seller transaction on date
  • Loading branch information
Shay2Shay authored May 1, 2024
2 parents 15fb97f + f6d2b1a commit ebe8ccc
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 1 deletion.
27 changes: 27 additions & 0 deletions server/Controllers/AdminTransactionFilterController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const router = require("express").Router();
const { Transaction } = require("../Models/transaction");

async function AdminTransactionFilterController(req, res) {
try {
const { startDate, endDate } = req.params;

// Convert start and end dates to Date objects
const startDateObj = new Date(startDate);
const endDateObj = new Date(endDate);

// Adjust the end date to include the whole day
const adjustedEndDate = new Date(endDateObj.getTime() + 86400000); // Adding one day in milliseconds

// Query all transactions between startDate and endDate
const data = await Transaction.find({
time: { $gte: startDateObj, $lte: adjustedEndDate }
});

res.status(200).send({ data: data, message: "Transactions fetched successfully" });
} catch (error) {
console.error(error);
res.status(500).send({ message: "Internal server error" });
}
}

module.exports = { AdminTransactionFilterController };
31 changes: 31 additions & 0 deletions server/Controllers/ConsumerTransactionFilterController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const router = require("express").Router();
const { Transaction } = require("../Models/transaction");

async function ConsumerTransactionFilterController(req, res) {
try {
const { startDate, endDate } = req.params;

// Convert start and end dates to Date objects
const startDateObj = new Date(startDate);
const endDateObj = new Date(endDate);

// Adjust the end date to include the whole day
const adjustedEndDate = new Date(endDateObj.getTime() + 86400000); // Adding one day in milliseconds

// Query transactions between startDate and endDate for the logged-in user
const data = await Transaction.find({
customerid: req.user._id,
$and: [
{ time: { $gte: startDateObj } }, // Transactions on or after the start date
{ time: { $lte: adjustedEndDate } } // Transactions on or before the adjusted end date
]
});

res.status(200).send({ data: data, message: "Transactions fetched successfully" });
} catch (error) {
console.error(error);
res.status(500).send({ message: "Internal server error" });
}
}

module.exports = { ConsumerTransactionFilterController };
33 changes: 33 additions & 0 deletions server/Controllers/SellerTransactionFilterController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@


const router = require("express").Router();
const { Transaction } = require("../Models/transaction");

async function SellerTransactionFilterController(req, res) {
try {
const { startDate, endDate } = req.params;

// Convert start and end dates to Date objects
const startDateObj = new Date(startDate);
const endDateObj = new Date(endDate);

// Adjust the end date to include the whole day
const adjustedEndDate = new Date(endDateObj.getTime() + 86400000); // Adding one day in milliseconds

// Query transactions between startDate and endDate for the logged-in user
const data = await Transaction.find({
sellerid: req.user._id,
$and: [
{ time: { $gte: startDateObj } }, // Transactions on or after the start date
{ time: { $lte: adjustedEndDate } } // Transactions on or before the adjusted end date
]
});

res.status(200).send({ data: data, message: "Transactions fetched successfully" });
} catch (error) {
console.error(error);
res.status(500).send({ message: "Internal server error" });
}
}

module.exports = { SellerTransactionFilterController };
7 changes: 7 additions & 0 deletions server/Routes/AdminTransactionFilterRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { AdminTransactionFilterController } = require("../Controllers/AdminTransactionFilterController");
const router = require("express").Router();
const {authenticateToken}=require('../Middleware/CheckTokenAdminLocally');

router.get("/:startDate/:endDate",authenticateToken,AdminTransactionFilterController)

module.exports = router;
7 changes: 7 additions & 0 deletions server/Routes/ConsumerTransactionFilterRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { ConsumerTransactionFilterController } = require("../Controllers/ConsumerTransactionFilterController");
const router = require("express").Router();
const {authenticateToken}=require('../Middleware/CheckTokenLocally');

router.get("/:startDate/:endDate",authenticateToken,ConsumerTransactionFilterController)

module.exports = router;
7 changes: 7 additions & 0 deletions server/Routes/SellerTransactionFilterRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { SellerTransactionFilterController } = require("../Controllers/SellerTransactionFilterController");
const router = require("express").Router();
const {authenticateToken}=require('../Middleware/CheckTokenSellerLocally');

router.get("/:startDate/:endDate",authenticateToken,SellerTransactionFilterController)

module.exports = router;
10 changes: 9 additions & 1 deletion server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const ConsumerChatReadRoute=require("./Routes/ConsumerViewChatRoute")
const MakePaymentConsumer=require("./Routes/ConsumerMakePaymentRoute")
const TransactionHistoryRoute=require("./Routes/TransactionHistoryRoute")
const ConsumerFilterRoute = require("./Routes/ConsumerFilterRoute")
const ConsumerTransactionFilterRoute= require("./Routes/ConsumerTransactionFilterRoute")



const TransactionAdminRoute=require("./Routes/TransactionAdminRoute")
Expand All @@ -56,7 +58,7 @@ const viewBroadcastAdminRoute=require('./Routes/ViewBroadcastAdminRoute')
const viewallServicesRoute=require('./Routes/AdminTotalServiceRoute')
const AdminHistoryRoute=require('./Routes/AdminHistoryRoutes')
const AdminAllServiceRequest=require('./Routes/AdminRequestsListRoute')

const AdminTransactionFilterRoute= require("./Routes/AdminTransactionFilterRoute")

const sellerRegistrationRoutes=require('./Routes/SellerRegistrationRoute')
const sellerLoginRoutes=require('./Routes/SellerLoginRoute')
Expand All @@ -81,6 +83,9 @@ const AcceptedRequestRouter = require('./Routes/AcceptedRequestRoute')
const SellerViewCustomerRequestRoute = require('./Routes/SellerViewCustomerRequestRoute')
const SellerAcceptedRequestRoute = require('./Routes/SellerAcceptedRequestRoute')
const SellerDeleteRequestRoute = require('./Routes/SellerDeleteRequestRoute')
const SellerTransactionFilterRoute= require("./Routes/SellerTransactionFilterRoute")


const CompleteRequestRouter = require('./Routes/CompleteRequestRouter')
const ConsumerViewServicesRoute = require('./Routes/ConsumerViewServicesRoute')

Expand Down Expand Up @@ -141,6 +146,7 @@ app.use('/api/consumer/payment',MakePaymentConsumer)
app.use('/api/consumer/transactionsave',TransactionHistoryRoute)
app.use('/api/consumer/transaction',TransactionConsumerRoute)//left
app.use('/api/customer/viewServices/filter', ConsumerFilterRoute)
app.use('/api/consumer/transaction/filter', ConsumerTransactionFilterRoute)

app.use("/api/admin/register",adminRegistrationRoutes);
app.use("/api/admin/login",adminLoginRoutes);
Expand All @@ -160,6 +166,7 @@ app.use("/api/admin/totalservice",viewallServicesRoute)
app.use("/api/admin/history",AdminHistoryRoute)
app.use('/api/admin/transaction',TransactionAdminRoute)
app.use('/api/admin/allpendingrequest',AdminAllServiceRequest)
app.use('/api/admin/transaction/filter',AdminTransactionFilterRoute)



Expand All @@ -181,6 +188,7 @@ app.use('/api/seller/request/cancel',SellerDeleteRequestRoute)
app.use('/api/seller/chattile',SellerViewChatTileRoute)
app.use('/api/seller/viewchat',SellerViewChatRoute)
app.use('/api/seller/sendchat',SellerSendChatRoute)
app.use('/api/seller/transaction/filter', SellerTransactionFilterRoute)

const swaggerJSdoc = require('swagger-jsdoc')
const swaggerUI = require('swagger-ui-express')
Expand Down

0 comments on commit ebe8ccc

Please sign in to comment.