Skip to content

Commit

Permalink
Merge pull request #67 from undp/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mbelinsky authored Apr 18, 2023
2 parents f7bcf2b + 59db9c7 commit 3195f2b
Show file tree
Hide file tree
Showing 30 changed files with 588 additions and 142 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/frontend-deployment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ jobs:
deploy_front_end:
runs-on: ubuntu-latest
env:
REACT_APP_BACKEND: https://ck5kt5uaw1.execute-api.us-east-1.amazonaws.com/dev
COUNTRY_NAME: 'Antarctic Region Dev'
REACT_APP_BACKEND: https://api.carbreg.org
# https://ck5kt5uaw1.execute-api.us-east-1.amazonaws.com/dev
COUNTRY_NAME: 'Antarctic Region'
COUNTRY_FLAG_URL: 'https://carbon-common-dev.s3.amazonaws.com/flag.png'
COUNTRY_CODE: 'NG'
REACT_APP_MAPBOXGL_ACCESS_TOKEN: ${{ secrets.MAPBOXGL_ACCESS_TOKEN }}
Expand Down
106 changes: 106 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,112 @@ Carbon credit calculation implemented in a separate node module. [Please refer t
### Serial Number Generation
Serial Number generation implemented in a separate node module. [Please refer this](./libs/serial-number-gen/README.md) for more information.

<a name="external"></a>
## External Connectivity

### ITMO Platform
1. Carbon Registry make a daily to the retrieve ITMO platform programmes.
2. Programmes create in the Carbon Registry when programmes are authorized in the ITMO Platform
3. The Carbon Registry update when the programmes are Issued with credits in the ITMO Platform

#### <b>Lifecycle</b>
![alt text](./documention/imgs/ITMOxCARBON_LifeCycle.svg)

#### <b>Programme Creation and Authorisation</b>
- Authorisation of programmes in the ITMO Platform identified by the event name: "ITMO-Design Document (DD) & Validation Report / Upload on National Public Registry".
- If the Company Tax Id doesn’t exist in the Carbon Registry, that company created in the Carbon Registry.
- When creating the programme:
- The programme created with the state “Pending”
- The credit estimate set to 100 by default
- The company percentage set to 100%
- The serial number for the programme generated the same as any other programme in the Carbon Registry.
- Programmes retrieved from the ITMO Platform and created in the Carbon Registry can Authorised/Rejected by a Government user the same as any other programme in the Carbon Registry
- When a programme is authorised, the authorised credits will be the default credit estimate mentioned above. The programme can be issued with credits by a Government user the same as any other programme in the Carbon Registry.

#### <b>Credit Issuance</b>
- Credits can be issued for programmes retrieved from the ITMO Platform and created in the Carbon Registry in two ways;
- By a Government user the same as any other programme.
- Credit issuance in the ITMO Platform which should be reflected in the Carbon Registry.
- In the case of 2 above,
- Credit issuance identified by the event name: "Upload Final Monitoring Report" in the ITMO Platform.


#### <b>Field Mapping</b>

<b>Company</b>
| **Name in the Carbon Registry** | **Mandatory in the Carbon Registry** | **Name in the ITMO Platform** |
| --- | --- | --- |
| Tax ID (_taxId_) | Yes | company |
| Name (_name_) | Yes | company |
| Email (_email_) | Yes | Set default : nce.digital+[_organisation_]@undp.org |
| Phone Number (_phoneNo_) | Yes | Set default : 00 |
| Website | | |
| Address | | Set default : Country if the Registry |
| Logo | | |
| Country (_country_) | | Set default : Country of the Registry |
| Role (_companyRole_) | Yes | Set default : ProgrammeDeveloper |

<br><b>User</b>
| Name in the Carbon Registry | Mandatory in the Carbon Registry | Name in the ITMO Platform |
| --- | --- | --- |
| Email (_email_) | Yes | Set default : nce.digital+[_organisation_]@undp.org |
| Role (_role_) | Yes | Set default : Admin |
| Phone Number (_phoneNo_) | | Set default : 00 |

<br><b>Programme</b>
| **Name in the Carbon Registry** | **Mandatory in the Carbon Registry** | **Name in the ITMO Platform** |
| --- | --- | --- |
| Programme Name (title) | Yes | Name |
| External ID (externalId) | Yes | id |
| Credit Issuance Serial Number | | |
| Current Status | | Set default : Pending |
| Applicant Type | | Set default : Programme Developer |
| Sector (_sector_) | Yes | Sector |
| Sectoral Scope (_sectoralScope_) | Yes | Set default : 1 if ITMO term does not exist |
| Programme Start Date (_startTime_) | Yes | createdAt |
| Programme End Date (_endTime_) | Yes | createdAt + 10 years |
| Geographical Location (Regional) (_geographicalLocation_) | Yes | country _(Name not mentioned as ISO3 or actual name)_ |
| Buyer Country Eligibility | | |
| Programme Cost (USD) (_programmeCostUSD_) | Yes | Set default : Null |
| Financing Type | | |
| Grant Equivalent Amount | | |
| Carbon Price (Dollars per ton) | | |
| Company | | company |
| Company Tax ID (_proponentTaxVatId_) | Yes | company |
| Company Percentage (_proponentPercentage_) | Yes | Set default : 100% |
| Type of Mitigation Action/Activity (_typeOfMitigation_) | Yes | |
| GHGs Covered (_greenHouseGasses_) | Yes | Set default : CO2 |
| Credits Authorised | | Set default : 100 |
| Credits Issued | | Set default : 10 |
| Credits Transferred | | |
| Credits Frozen | | |
| Credits Retired | | |
| Credits authorised for international transfer and use (Total cumulative maximum amount of Mitigation Outcomes for which international transfer and use is authorized) | | |
| Crediting Period (years) | | |
| Programme Materials | | Files \* |
| Project Materials | | Files \* |
| **Credit Calculation Fields / Mitigation Type Calculation** | | |
| **Agriculture** | | |
| Land Area | | |
| Land Area Unit | | |
| **Solar** | | |
| energy generation | | |
| energy generation unit | | |
| consumer group | | |

#### <b>Assumptions</b>
- Programme estimated credit amount is 100.
- Programme issued credit amount is always 10.

#### <b>Docker Integration Setup</b>
1. Append `data-importer` to `docker-compose` file `replicator` service `RUN_MODULE` env variable with comma separated.
2. Update following env variables in the `docker-compose` file `replicator` service.
- ITMO_API_KEY
- ITMO_EMAIL
- ITMO_PASSWORD
- ITMO_ENDPOINT
3. Programmes will import on each docker restart.

<a name="user"></a>
## User Onboarding and Permissions Model

Expand Down
4 changes: 2 additions & 2 deletions backend/services/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ DB_USER=root
DB_NAME=carbondbdev
LOG_LEVEL=debug
carbon_dev_common=carbon-common-dev
SOURCE_EMAIL=info@xeptagon.com
SOURCE_EMAIL=nce.digital@undp.org
IS_EMAIL_DISABLED=false
LEDGER_TYPE=QLDB
FILE_SERVICE=S3
LOCATION_SERVICE=MAPBOX
ASYNC_OPERATIONS_TYPE=Queue
DISABLE_LOW_PRIORITY_EMAIL=true
ASYNC_QUEUE_NAME=https://sqs.us-east-1.amazonaws.com/302213478610/AsyncQueuedev.fifo
DOMAIN_MAP=false
DOMAIN_MAP=true
2 changes: 1 addition & 1 deletion backend/services/.env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ LOCATION_SERVICE=MAPBOX
ASYNC_OPERATIONS_TYPE=Queue
DISABLE_LOW_PRIORITY_EMAIL=true
ASYNC_QUEUE_NAME=https://sqs.us-east-1.amazonaws.com/302213478610/AsyncQueueprod.fifo
DOMAIN_MAP=true
DOMAIN_MAP=false
6 changes: 5 additions & 1 deletion backend/services/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ functions:
timeout: 60
handler: src/data-importer/handler.handler
events:
- schedule: cron(0 5 * * ? *)
- schedule:
rate: cron(0 1 * * ? *)
enabled: true
input:
importTypes: ITMO_SYSTEM
ssmToEnvironment:
- DB_PASSWORD
- ITMO_API_KEY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ export class ITMOSystemImporter implements ImporterInterface {
SectoralScope.EnergyDistribution,
TypeOfMitigation.ENERGY_DISTRIBUTION,
];
case "agriculture":
return [
Sector.Agriculture,
SectoralScope.Agriculture,
TypeOfMitigation.AGRICULTURE
]
default:
return [
Sector.Other,
Expand Down
2 changes: 1 addition & 1 deletion backend/services/src/i18n/en/company.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"noSuspendedCompany": "No suspended company found",
"companyActivationSuccess": "Successfully activated company",
"companyActivationFailed": "Company activate failed. Please try again",
"companyTaxIdExist": "Company tax id already exist",
"companyTaxIdExist": "This Company Tax ID already exists",
"companyUpdateFailed": "Company update failed. Please try again",
"cantSuspendUrOwn": "Can not suspend your own company",
"cantActivateUrOwn": "Can not activate your own company"
Expand Down
3 changes: 1 addition & 2 deletions backend/services/src/i18n/en/programme.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"unExpectedProgOwnerPerc": "Unexpected programme owner percentages",
"notImplementedForMitigationType": "Not implemented for mitigation type {}",
"transferReqNotExist": "Transfer request does not exist",
"transferReqAlreadyCancelled": "This transfer request has already been cancelled",
"acceptOrRejAlreadyCancelled": "This transfer request has been cancelled",
"acceptOrRejCancelledReq": "This transfer request has been cancelled",
"invalidApproverForTransferReq": "Invalid approver for the transfer request",
"invalidApproverForRetirementReq": "Invalid approver for the retirement request",
"noPendReqFound": "This transfer request has been cancelled",
Expand Down
2 changes: 1 addition & 1 deletion backend/services/src/i18n/en/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"companyCreateNotPermittedForTheCompanyRole": "Company create does not permitted for your company role",
"companyUpdateFailed": "Company update failed. Please try again",
"propValueAlreadyExist": "{} already exist",
"taxIdExistAlready": "Company tax id already exist",
"taxIdExistAlready": "This Company Tax ID already exists",
"deleteUserSuccess": "The user has been deleted successfully",
"deleteOneAdminWhenOnlyOneAdmin": "The user cannot be deleted as the user is the only admin",
"userUnAUth": "This action is unauthorised",
Expand Down
28 changes: 28 additions & 0 deletions backend/services/src/setup/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { LedgerDBInterface } from "../shared/ledger-db/ledger.db.interface";
import { Handler } from 'aws-lambda';
import { LocationModule } from "../shared/location/location.module";
import { LocationInterface } from "../shared/location/location.interface";
import { ProgrammeModule } from "../shared/programme/programme.module";
import { ProgrammeService } from "../shared/programme/programme.service";
const fs = require('fs')

export const handler: Handler = async (event) => {
Expand All @@ -27,10 +29,36 @@ export const handler: Handler = async (event) => {
if (!event) {
event = process.env;
}

const userApp = await NestFactory.createApplicationContext(UserModule, {
logger: getLogger(UserModule),
});
const userService = userApp.get(UserService);

if (event.type === 'IMPORT_USERS' && event.body) {
const users = event.body.split('\n');
for (const user of users) {
const fields = user.split(',');
if (fields.length < 7) {
continue;
}
// (name: string, companyRole: CompanyRole, taxId: string, password: string, email: string, userRole: string
const cr = (fields[4] == 'Government' ? CompanyRole.GOVERNMENT : fields[4] == 'Certifier' ? CompanyRole.CERTIFIER : CompanyRole.PROGRAMME_DEVELOPER)
const ur = (fields[5] == 'admin' ? Role.Admin : fields[5] == 'Manager' ? Role.Manager : Role.ViewOnly)
await userService.createUserWithPassword(fields[0], cr, fields[3], fields[6], fields[1], ur, fields[2]);
}
return;
}

if (event.type === 'UPDATE_COORDINATES') {
const prApp = await NestFactory.createApplicationContext(ProgrammeModule, {
logger: getLogger(ProgrammeModule),
});
const programmeService = prApp.get(ProgrammeService);
await programmeService.regenerateRegionCoordinates()
return;
}

const u = await userService.findOne(event['rootEmail']);
if (u != undefined) {
console.log('Root user already created and setup is completed')
Expand Down
Loading

0 comments on commit 3195f2b

Please sign in to comment.