Skip to content

Commit c8b312b

Browse files
authored
Merge pull request #72 from xeptagondev/develop
Sync
2 parents 6d3bbdc + 1dbc981 commit c8b312b

70 files changed

Lines changed: 2375 additions & 957 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ The below diagram demonstrates the the ledger behavior of programme create, auth
178178
- Use `DB_PASSWORD` env variable to change PostgresSQL database password
179179
- Configure system root account email by updating environment variable `ROOT EMAIL`. If the email service is enabled, on the first docker start, this email address will receive a new email with the root user password.
180180
- By default frontend does not show map images on dashboard and programme view. To enable them please update `REACT_APP_MAP_TYPE` env variable to `Mapbox` and add new env variable `REACT_APP_MAPBOXGL_ACCESS_TOKEN` with [MapBox public access token](https://docs.mapbox.com/help/tutorials/get-started-tokens-api/) in web container.
181+
- Add user data
182+
- Update [organisations.csv](./organisations.csv) file to add organisations.
183+
- Update [users.csv](./users.csv) file to add users.
184+
- When updating files keep the header and replace existing dummy data with your data.
185+
- These users and companys add to the system each docker restart.
181186
- Run `docker-compose up -d --build`. This will build and start containers for following services,
182187
- PostgresDB container
183188
- National service
@@ -187,7 +192,7 @@ The below diagram demonstrates the the ledger behavior of programme create, auth
187192
- Web frontend on http://localhost:3030/
188193
- API Endpoints,
189194
- http://localhost:3000/national#/
190-
- http://localhost:3100/stats#/
195+
- http://localhost:3100/stats#/
191196

192197
<a name="local"></a>
193198
## Run Services Locally
@@ -293,8 +298,8 @@ Serial Number generation implemented in a separate node module. [Please refer th
293298
| Credit Issuance Serial Number | | |
294299
| Current Status | | Set default : Pending |
295300
| Applicant Type | | Set default : Programme Developer |
296-
| Sector (_sector_) | Yes | Sector |
297-
| Sectoral Scope (_sectoralScope_) | Yes | Set default : 1 if ITMO term does not exist |
301+
| Sector (_sector_) | Yes | [Sector](#itmo-sector-mapping) |
302+
| Sectoral Scope (_sectoralScope_) | Yes | [Sector](#itmo-sector-mapping)|
298303
| Programme Start Date (_startTime_) | Yes | createdAt |
299304
| Programme End Date (_endTime_) | Yes | createdAt + 10 years |
300305
| Geographical Location (Regional) (_geographicalLocation_) | Yes | country _(Name not mentioned as ISO3 or actual name)_ |
@@ -306,7 +311,7 @@ Serial Number generation implemented in a separate node module. [Please refer th
306311
| Company | | company |
307312
| Company Tax ID (_proponentTaxVatId_) | Yes | company |
308313
| Company Percentage (_proponentPercentage_) | Yes | Set default : 100% |
309-
| Type of Mitigation Action/Activity (_typeOfMitigation_) | Yes | |
314+
| Type of Mitigation Action/Activity (_typeOfMitigation_) | Yes | [Sector](#itmo-sector-mapping) |
310315
| GHGs Covered (_greenHouseGasses_) | Yes | Set default : CO2 |
311316
| Credits Authorised | | Set default : 100 |
312317
| Credits Issued | | Set default : 10 |
@@ -326,6 +331,15 @@ Serial Number generation implemented in a separate node module. [Please refer th
326331
| energy generation unit | | |
327332
| consumer group | | |
328333
334+
#### <b>ITMO Sector Mapping</b>
335+
|ITMO Sector Field Value|Sector|Sectoral Scope|Type Of Mitigation|
336+
| -- | -- | -- | -- |
337+
|energy-distribution|Energy|Energy Distribution|Energy Distribution
338+
|agriculture|Agriculture|Agriculture|Agriculture|
339+
|energy-industries|Energy|Energy Industry|EE Industry
340+
|Default|Other|Energy Industry|EE Industry
341+
342+
329343
#### <b>Assumptions</b>
330344
- Programme estimated credit amount is 100.
331345
- Programme issued credit amount is always 10.

backend/services/.env.dev

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ LOCATION_SERVICE=MAPBOX
1313
ASYNC_OPERATIONS_TYPE=Queue
1414
DISABLE_LOW_PRIORITY_EMAIL=true
1515
ASYNC_QUEUE_NAME=https://sqs.us-east-1.amazonaws.com/302213478610/AsyncQueuedev.fifo
16-
DOMAIN_MAP=true
16+
DOMAIN_MAP=true
17+
EXPIRES_IN=7200

backend/services/.env.prod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ LOCATION_SERVICE=MAPBOX
1313
ASYNC_OPERATIONS_TYPE=Queue
1414
DISABLE_LOW_PRIORITY_EMAIL=true
1515
ASYNC_QUEUE_NAME=https://sqs.us-east-1.amazonaws.com/302213478610/AsyncQueueprod.fifo
16-
DOMAIN_MAP=false
16+
DOMAIN_MAP=false
17+
EXPIRES_IN=7200

backend/services/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"jest": "28.1.3",
8383
"prettier": "^2.3.2",
8484
"serverless": "^3.25.1",
85-
"serverless-offline": "^11.2.3",
85+
"serverless-offline": "^12.0.4",
8686
"serverless-plugin-optimize": "^4.2.1-rc.1",
8787
"serverless-plugin-typescript": "^2.1.4",
8888
"serverless-ssm-fetch": "^2.0.0",

backend/services/src/analytics-api/aggregate.api.service.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export class AggregateAPIService {
115115
issuedCredits: [],
116116
transferredCredits: [],
117117
retiredCredits: [],
118+
frozenCredits: [],
118119
};
119120
const groupedDataFiltered = passedResult?.filter(
120121
(item) => String(item.time_group) !== "0"
@@ -134,6 +135,7 @@ export class AggregateAPIService {
134135
let issuedCreditsSum = 0;
135136
let transferredCreditsSum = 0;
136137
let retiredCreditsSum = 0;
138+
let frozenCreditsSum = 0;
137139
let resultThere: StatusGroupedByTimedataThere = {
138140
awaitingAuthorization: false,
139141
authorised: false,
@@ -151,11 +153,17 @@ export class AggregateAPIService {
151153
authorisedCreditsSum = authorisedCreditsSum + 0;
152154
}
153155
issuedCreditsSum =
154-
issuedCreditsSum + parseFloat(timeGroupItem?.totalbalancecredit);
156+
issuedCreditsSum +
157+
parseFloat(timeGroupItem?.totalissuedcredit) -
158+
parseFloat(timeGroupItem?.totalretiredcredit) -
159+
parseFloat(timeGroupItem?.totaltxcredit) -
160+
parseFloat(timeGroupItem?.totalfreezecredit);
155161
transferredCreditsSum =
156162
transferredCreditsSum + parseFloat(timeGroupItem?.totaltxcredit);
157163
retiredCreditsSum =
158164
retiredCreditsSum + parseFloat(timeGroupItem?.totalretiredcredit);
165+
frozenCreditsSum =
166+
frozenCreditsSum + parseFloat(timeGroupItem?.totalfreezecredit);
159167
statusArray?.map((status) => {
160168
if (timeGroupItem?.currentStage === status) {
161169
resultThere[this.firstLower(timeGroupItem?.currentStage)] = true;
@@ -174,6 +182,7 @@ export class AggregateAPIService {
174182
result["issuedCredits"]?.push(issuedCreditsSum);
175183
result["transferredCredits"]?.push(transferredCreditsSum);
176184
result["retiredCredits"]?.push(retiredCreditsSum);
185+
result["frozenCredits"]?.push(frozenCreditsSum);
177186
});
178187

179188
const resultS = {

backend/services/src/async-operations-handler/async-operations-database-handler.service.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export class AsyncOperationsDatabaseHandlerService
4242
.select(['"actionId"', '"actionType"', '"actionProps"'])
4343
.getRawMany();
4444

45+
if(notExecutedActions.length === 0)
46+
return;
47+
48+
const startedSeq = lastSeq;
4549
notExecutedActions.forEach((action: any) => {
4650
if (action.actionType === AsyncActionType.Email.toString()) {
4751
const emailBody = JSON.parse(action.actionProps);
@@ -50,12 +54,16 @@ export class AsyncOperationsDatabaseHandlerService
5054
lastSeq = action.actionId;
5155
});
5256

53-
await Promise.all(asyncPromises);
54-
55-
await this.counterRepo.save({
56-
id: CounterType.ASYNC_OPERATIONS,
57-
counter: lastSeq,
58-
});
57+
try {
58+
await Promise.all(asyncPromises);
59+
await this.counterRepo.save({
60+
id: CounterType.ASYNC_OPERATIONS,
61+
counter: lastSeq,
62+
});
63+
} catch (exception) {
64+
this.logger.log("database asyncHandler failed", exception);
65+
lastSeq = startedSeq;
66+
}
5967
}, 5000);
6068
}
6169
}

backend/services/src/data-importer/importers/itmo-system.service.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,19 @@ export class ITMOSystemImporter implements ImporterInterface {
139139
const taxId = project.company;
140140
const company = await this.companyService.findByTaxId(taxId);
141141
if (!company) {
142+
143+
const email = `nce.digital+${project.company}@undp.org`.replace(' ', '');
142144
await this.userService.create(
143145
{
144-
email: `nce.digital+${project.company}@undp.org`,
146+
email: email,
145147
role: Role.Admin,
146148
name: project.company,
147149
phoneNo: "00",
148150
company: {
149151
taxId: taxId,
150152
companyId: undefined,
151153
name: project.company,
152-
email: `nce.digital+${project.company}@undp.org`,
154+
email: email,
153155
phoneNo: "00",
154156
website: undefined,
155157
address: this.configService.get("systemCountryName"),
@@ -197,9 +199,9 @@ export class ITMOSystemImporter implements ImporterInterface {
197199
creditEst: 100,
198200
};
199201

200-
if ( step.files && step.files.length > 0) {
201-
pr.programmeProperties['programmeMaterials'] = step.files[0]
202-
pr.programmeProperties['projectMaterial'] = step.files[0]
202+
if (step.files && step.files.length > 0) {
203+
pr.programmeProperties["programmeMaterials"] = step.files;
204+
pr.programmeProperties["projectMaterial"] = step.files;
203205
}
204206

205207
await this.programmeService.create(pr);
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
22
"addAsyncActionDatabaseFailed": "{} functionality failed when adding to database",
3-
"addAsyncActionQueueFailed": "{} functionality failed when adding to queue"
3+
"addAsyncActionQueueFailed": "{} functionality failed when adding to queue",
4+
"settingsSavedMsg": "Settings saved successfully",
5+
"settingsSaveFailedMsg": "Settings saving failed"
46
}

backend/services/src/i18n/en/programme.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@
6767
"issuedCreditCantExceedEstCredit": "Programme issued credit amount can not exceed estimated credit amount",
6868
"transferReqRejectSuccess": "The transfer request has been rejected successfully",
6969
"transferReqCancelSuccess": "The international transfer retire request has been cancelled successfully",
70+
"transferCancelSuccess": "The transfer request has been cancelled successfully",
7071
"certifierCanOnlyCertifiy": "Programme certification can perform only by certifier",
7172
"govOrProgrammeOwnerOnlyCreditRetirement": "Credit retirement can initiate only the government or programme owner",
7273
"issuedCreditCannotExceedEstCredit": "Programme issue credit amount can not exceed estimated credit amount",
7374
"organisationDeactivated": "This action is unauthorised due to the deactivation of your organisation. You will now be logged out of the system. Log in again to access the system with view-only permissions.",
7475
"unAuth": "This action is unauthorised",
75-
"companyIsNotTheOwnerOfProg": "Company {} is not an owner company of the programme"
76+
"companyIsNotTheOwnerOfProg": "Company {} is not an owner company of the programme",
77+
"internalErrorCreditFreezing": "Internal error on credit freezing"
7678
}

backend/services/src/i18n/en/user.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@
3030
"resetPasswordReqExpired": "Your password resetting request has been expired",
3131
"reqIdFound": "Reset request id found",
3232
"resetEmailSent": "User found, An email was sent",
33-
"invalidCountry": "Country is invalid"
33+
"invalidCountry": "Country is invalid",
34+
"editUserSuccess": "The user account has been updated successfully"
3435
}

0 commit comments

Comments
 (0)