---
# System prepended metadata

title: Create getTotalEarned API

---

# Create getTotalEarned API

```typescript=
router.get(
  "/details/totalEarned",
  (req: Request, res: Response, next: NextFunction) => {
    donationController
      .getTotalEarnedByDonationId(parseInt(req.query.donationId as string))
      .then((data) => res.status(200).send(data))
      .catch((error) => {
        var errorMessage = errorHandler(error);
        res.status(errorMessage.httpStatusCode).send(errorMessage);
      });
  }
);

getTotalEarnedByDonationId = (donationId: number) => {
    return new Promise((resolve, reject) => {
      db.oneOrNone(getTotalEarnedByDonationIdSql, [donationId])
        .then((data: any) => resolve(data))
        .catch((error: any) => reject(error));
    });
  };
```