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

[feature] add support to cashout individuals #855

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions packages/api/src/controllers/v2/cico/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Request, Response } from 'express';
import { services } from '@impactmarket/core';

import { ListCICOProviderRequestSchema } from '~validators/cico';
import { ValidatedRequest } from '~utils/queryValidator';
import { standardResponse } from '~utils/api';

const { CICOProviderService } = services.app;

export const getCICO = (req: Request & ValidatedRequest<ListCICOProviderRequestSchema>, res: Response) => {
const cicoProviderService = new CICOProviderService();

cicoProviderService
.get(req.query)
.then(r => standardResponse(res, 200, true, r, {}))
.catch(e => standardResponse(res, 400, false, '', { error: e.message }));
};
48 changes: 48 additions & 0 deletions packages/api/src/routes/v2/cico/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Router } from 'express';

import { getCICO } from '~controllers/v2/cico';
import { listCICOProviderValidator } from '~validators/cico';

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

/**
* @swagger
*
* /cico:
* get:
* tags:
* - "cico"
* summary: Get cash-in/cash-out providers
* parameters:
* - in: query
* name: country
* schema:
* type: string
* required: false
* description: filter by country
* - in: query
* name: lat
* schema:
* type: number
* required: false
* description: latitude used for nearest location
* - in: query
* name: lng
* schema:
* type: number
* required: false
* description: longitude used for nearest location
* - in: query
* name: distance
* schema:
* type: number
* required: false
* description: distance in kilometers between the user location and providers
* responses:
* "200":
* description: OK
*/
route.get('/:query?', listCICOProviderValidator, getCICO);
};
2 changes: 2 additions & 0 deletions packages/api/src/routes/v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Router } from 'express';

import attestation from './attestation';
import cico from './cico';
import claimLocation from './claimLocation';
import community from './community';
import generic from './generic';
Expand All @@ -25,6 +26,7 @@ export default (): Router => {
microcredit(app);
protocol(app);
referrals(app);
cico(app);

return app;
};
4 changes: 4 additions & 0 deletions packages/api/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export default (app: express.Application): void => {
description:
'MicroCredit endpoints. In this section, all endpoints are protected by authentication and signature verification. Be sure to be properly authenticated!'
},
{
name: 'learn-and-earn',
description: 'Learn and Earn'
},
{
name: 'referrals',
description: 'impactMarket referral program!'
Expand Down
28 changes: 28 additions & 0 deletions packages/api/src/validators/cico.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Joi } from 'celebrate';

import { ContainerTypes, ValidatedRequestSchema, createValidator } from '../utils/queryValidator';
import { defaultSchema } from './defaultSchema';

const validator = createValidator();

type ListCICOProviderType = {
country?: string;
lat?: number;
lng?: number;
distance?: number;
};

const queryListBorrowersSchema = defaultSchema.object<ListCICOProviderType>({
country: Joi.string().optional(),
lat: Joi.number().optional(),
lng: Joi.number().optional(),
distance: Joi.number().optional()
});

interface ListCICOProviderRequestSchema extends ValidatedRequestSchema {
[ContainerTypes.Query]: ListCICOProviderType;
}

const listCICOProviderValidator = validator.query(queryListBorrowersSchema);

export { listCICOProviderValidator, ListCICOProviderRequestSchema };
2 changes: 2 additions & 0 deletions packages/core/src/database/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ModelStatic, Sequelize } from 'sequelize/types';
import { AirgrabProofModel } from './models/airgrab/airgrabProof';
import { AirgrabUserModel } from './models/airgrab/airgrabUser';
import { AppAnonymousReportModel } from './models/app/anonymousReport';
import { AppCICOProviderModel } from './models/cico/providers';
import { AppClientCredentialModel } from './models/app/appClientCredential';
import { AppExchangeRates } from './models/app/exchangeRates';
import { AppLogModel } from './models/app/appLog';
Expand Down Expand Up @@ -70,6 +71,7 @@ export type DbModels = {
appUserValidationCode: ModelStatic<AppUserValidationCodeModel>;
ubiBeneficiarySurvey: ModelStatic<UbiBeneficiarySurveyModel>;
appReferralCode: ModelStatic<AppReferralCodeModel>;
appCICOProvider: ModelStatic<AppCICOProviderModel>;
//
community: ModelStatic<Community>;
ubiCommunitySuspect: ModelStatic<UbiCommunitySuspectModel>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('app_cico_provider', {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true
},
name: {
type: Sequelize.STRING(64),
allowNull: false
},
description: {
type: Sequelize.STRING(256),
allowNull: false
},
countries: {
type: Sequelize.ARRAY(Sequelize.STRING(2)),
allowNull: false
},
type: {
type: Sequelize.INTEGER,
allowNull: false
},
isCashin: {
type: Sequelize.BOOLEAN,
allowNull: false
},
isCashout: {
type: Sequelize.BOOLEAN,
allowNull: false
},
details: {
type: Sequelize.JSONB,
allowNull: false
},
updatedAt: {
type: Sequelize.DATE,
allowNull: false
}
});
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('app_cico_provider');
}
};
123 changes: 123 additions & 0 deletions packages/core/src/database/models/cico/providers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { DataTypes, Model, Sequelize } from 'sequelize';

type ExchangeDetails = {
fee: number;
min?: number;
max?: number;
logoUrl?: string;
website?: string;
customImplementation?: string;
iframeUrl?: string;
};

type MerchantDetails = {
category: number;
fee: number;
min?: number;
max?: number;
// it's maps address, not wallet address
address: string;
phone: string;
gps: {
latitude: number;
longitude: number;
};
payment: boolean;
};

type IndividualDetails = {
category: number;
fee: number;
min?: number;
max?: number;
phone: string;
};

export interface CICOProviderRegistry {
id: number;
name: string;
description: string;
countries: string[];
type: number;
isCashin: boolean;
isCashout: boolean;
details: ExchangeDetails | MerchantDetails | IndividualDetails;

updatedAt: Date;
}

export interface CICOProviderRegistryCreation {
name: string;
description: string;
countries: string[];
type: number;
isCashin: boolean;
isCashout: boolean;
details: ExchangeDetails | MerchantDetails | IndividualDetails;
}

export class AppCICOProviderModel extends Model<CICOProviderRegistry, CICOProviderRegistryCreation> {
public id!: number;
public name!: string;
public description!: string;
public countries!: string[];
// 0 - exchange, 1 - merchant, 2 - individual
public type!: number;
public isCashin!: boolean;
public isCashout!: boolean;
public details!: ExchangeDetails | MerchantDetails | IndividualDetails;

// timestamps!
public updatedAt!: Date;
}

export function initializeAppCICOProvider(sequelize: Sequelize): typeof AppCICOProviderModel {
AppCICOProviderModel.init(
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
name: {
type: DataTypes.STRING(64),
allowNull: false
},
description: {
type: DataTypes.STRING(256),
allowNull: false
},
countries: {
type: DataTypes.ARRAY(DataTypes.STRING(2)),
allowNull: false
},
type: {
type: DataTypes.INTEGER,
allowNull: false
},
isCashin: {
type: DataTypes.BOOLEAN,
allowNull: false
},
isCashout: {
type: DataTypes.BOOLEAN,
allowNull: false
},
details: {
type: DataTypes.JSONB,
allowNull: false
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false
}
},
{
tableName: 'app_cico_provider',
modelName: 'appCICOProvider',
sequelize,
createdAt: false
}
);
return AppCICOProviderModel;
}
2 changes: 2 additions & 0 deletions packages/core/src/database/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { communityAssociation } from './associations/community';
import { initializeAirgrabProof } from './airgrab/airgrabProof';
import { initializeAirgrabUser } from './airgrab/airgrabUser';
import { initializeAppAnonymousReport } from './app/anonymousReport';
import { initializeAppCICOProvider } from './cico/providers';
import { initializeAppClientCredential } from './app/appClientCredential';
import { initializeAppExchangeRates } from './app/exchangeRates';
import { initializeAppLog } from './app/appLog';
Expand Down Expand Up @@ -76,6 +77,7 @@ export default function initModels(sequelize: Sequelize): void {
initializeAppLog(sequelize);
initializeAppUserValidationCode(sequelize);
initializeAppReferralCode(sequelize);
initializeAppCICOProvider(sequelize);

// ubi
initializeCommunity(sequelize);
Expand Down
Loading
Loading