-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from percyps2401/main
added filter for admin , consumer and seller transaction on date
- Loading branch information
Showing
7 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters