Skip to content

Commit

Permalink
list borrowers (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernardo Vieira authored May 5, 2023
1 parent 21b19f0 commit 1c87731
Show file tree
Hide file tree
Showing 21 changed files with 762 additions and 210 deletions.
22 changes: 0 additions & 22 deletions .vscode/settings.json

This file was deleted.

16 changes: 0 additions & 16 deletions packages/api/src/controllers/v2/microcredit.ts

This file was deleted.

36 changes: 36 additions & 0 deletions packages/api/src/controllers/v2/microcredit/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { services } from '@impactmarket/core';
import { Response } from 'express';

import { standardResponse } from '../../../utils/api';
import { ListBorrowersRequestSchema } from '../../../validators/microcredit';
import { ValidatedRequest } from '../../../utils/queryValidator';
import { RequestWithUser } from '../../../middlewares/core';

class MicroCreditController {
private microCreditService: services.MicroCredit.List;
constructor() {
this.microCreditService = new services.MicroCredit.List();
}

// list borrowers using a loan manager account
listBorrowers = (
req: RequestWithUser & ValidatedRequest<ListBorrowersRequestSchema>,
res: Response
) => {
if (req.user === undefined) {
standardResponse(res, 400, false, '', {
error: {
name: 'USER_NOT_FOUND',
message: 'User not identified!',
},
});
return;
}
this.microCreditService
.listBorrowers({ ...req.query, addedBy: req.user.address })
.then((r) => standardResponse(res, 200, true, r))
.catch((e) => standardResponse(res, 400, false, '', { error: e }));
};
}

export { MicroCreditController };
16 changes: 16 additions & 0 deletions packages/api/src/controllers/v2/protocol/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { services } from '@impactmarket/core';
import { Request, Response } from 'express';
import { standardResponse } from '../../../utils/api';

class ProtocolController {
protocolService = new services.Protocol();

getMicroCreditData = async (req: Request, res: Response): Promise<void> => {
this.protocolService
.getMicroCreditData()
.then((r) => standardResponse(res, 200, true, r))
.catch((e) => standardResponse(res, 400, false, '', { error: e }));
};
}

export default ProtocolController;
2 changes: 2 additions & 0 deletions packages/api/src/routes/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import learnAndEarn from './learnAndEarn';
import story from './story';
import user from './user';
import microcredit from './microcredit';
import protocol from './protocol';

export default (): Router => {
const app = Router();
Expand All @@ -21,6 +22,7 @@ export default (): Router => {
global(app);
attestation(app);
microcredit(app);
protocol(app);

return app;
};
32 changes: 0 additions & 32 deletions packages/api/src/routes/v2/microcredit.ts

This file was deleted.

11 changes: 11 additions & 0 deletions packages/api/src/routes/v2/microcredit/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Router } from 'express';

import list from './list';

export default (app: Router): void => {
const route = Router();

app.use('/microcredit', route);

list(route);
};
31 changes: 31 additions & 0 deletions packages/api/src/routes/v2/microcredit/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Router } from 'express';

import { MicroCreditController } from '../../../controllers/v2/microcredit/list';
import { listBorrowersValidator } from '../../../validators/microcredit';
import { authenticateToken } from '../../../middlewares';

export default (route: Router): void => {
const controller = new MicroCreditController();

/**
* @swagger
*
* /microcredit/borrowers:
* get:
* tags:
* - "microcredit"
* summary: "Get List of Borrowers by manager"
* responses:
* "200":
* description: OK
* security:
* - api_auth:
* - "write:modify":
*/
route.get(
'/borrowers/:query?',
authenticateToken,
listBorrowersValidator,
controller.listBorrowers
);
};
10 changes: 10 additions & 0 deletions packages/api/src/routes/v2/protocol/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Router } from 'express';

import microcredit from './microcredit';

export default (app: Router): void => {
const route = Router();
app.use('/protocol', route);

microcredit(route);
};
27 changes: 27 additions & 0 deletions packages/api/src/routes/v2/protocol/microcredit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Router } from 'express';

import ProtocolController from '../../../controllers/v2/protocol';
import { cache } from '../../../middlewares/cache-redis';
import { cacheIntervals } from '../../../utils/api';

export default (route: Router): void => {
const protocolController = new ProtocolController();

/**
* @swagger
*
* /protocol/microcredit:
* get:
* tags:
* - "protocol"
* summary: "Get Global MicroCredit Data"
* responses:
* "200":
* description: OK
*/
route.get(
'/microcredit',
cache(cacheIntervals.oneHour),
protocolController.getMicroCreditData
);
};
Loading

0 comments on commit 1c87731

Please sign in to comment.