-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bernardo Vieira
authored
May 5, 2023
1 parent
21b19f0
commit 1c87731
Showing
21 changed files
with
762 additions
and
210 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,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 }; |
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,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; |
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
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
import { Router } from 'express'; | ||
|
||
import list from './list'; | ||
|
||
export default (app: Router): void => { | ||
const route = Router(); | ||
|
||
app.use('/microcredit', route); | ||
|
||
list(route); | ||
}; |
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 @@ | ||
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 | ||
); | ||
}; |
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,10 @@ | ||
import { Router } from 'express'; | ||
|
||
import microcredit from './microcredit'; | ||
|
||
export default (app: Router): void => { | ||
const route = Router(); | ||
app.use('/protocol', route); | ||
|
||
microcredit(route); | ||
}; |
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 @@ | ||
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 | ||
); | ||
}; |
Oops, something went wrong.