Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add snapHodlConfigId query param in the getAllSnapShots API #22

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/controllers/snapHodlConfigController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,16 @@ export const getSnapShotBySnapShotIdAndAddress = async (req: Request, res: Respo
// New function to retrieve all documents from DB_COLLECTION_SNAP_CONFIG_BALANCE
export const getAllSnapShots = async (req: Request, res: Response) => {
try {
const query: { [key: string]: any } = {};
if(req.query.snapHodlConfigId){
query.snapHodlConfigId = req.query.snapHodlConfigId;
}
const page = parseInt(req.query.page as string) || 1; // defaults to 1 if not provided
const limit = parseInt(req.query.limit as string) || 10; // defaults to 10 if not provided
const skip = (page - 1) * limit;

// Find all documents in the collection with pagination
const snapHodlConfigBalances = await SnapHodlConfigBalanceModel.find({}).skip(skip).limit(limit);
const snapHodlConfigBalances = await SnapHodlConfigBalanceModel.find(query).skip(skip).limit(limit);

// Send the result as a JSON response
return res.json(snapHodlConfigBalances);
Expand Down