-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [contracts] Fetch more data from ONGHub to accomodate template …
…generation
- Loading branch information
1 parent
c35e38e
commit ff94be9
Showing
17 changed files
with
269 additions
and
20 deletions.
There are no files selected for viewing
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 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
27 changes: 27 additions & 0 deletions
27
backend/src/migrations/1725349961532-AddOrganizationNewFields.ts
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 { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class AddOrganizationNewFields1725349961532 | ||
implements MigrationInterface | ||
{ | ||
name = 'AddOrganizationNewFields1725349961532'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "organization" ADD "cui" text`); | ||
await queryRunner.query( | ||
`ALTER TABLE "organization" ADD "legal_representative_full_name" text`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "organization" ADD "legal_representative_role" text`, | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`ALTER TABLE "organization" DROP COLUMN "legal_representative_role"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "organization" DROP COLUMN "legal_representative_full_name"`, | ||
); | ||
await queryRunner.query(`ALTER TABLE "organization" DROP COLUMN "cui"`); | ||
} | ||
} |
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 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 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 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 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 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
69 changes: 69 additions & 0 deletions
69
backend/src/usecases/organization/sync-with-ngohub.usecase.ts
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,69 @@ | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
import { IUseCaseService } from 'src/common/interfaces/use-case-service.interface'; | ||
import { ExceptionsService } from 'src/infrastructure/exceptions/exceptions.service'; | ||
import { OngHubExceptionMessages } from 'src/modules/onghub/exceptions/exceptions'; | ||
import { OngHubService } from 'src/modules/onghub/services/ong-hub.service'; | ||
import { IOrganizationModel } from 'src/modules/organization/models/organization.model'; | ||
import { OrganizationFacadeService } from 'src/modules/organization/services/organization.facade'; | ||
|
||
@Injectable() | ||
export class SyncWithOngHubUseCaseService | ||
implements IUseCaseService<IOrganizationModel> | ||
{ | ||
private readonly logger = new Logger(SyncWithOngHubUseCaseService.name); | ||
|
||
constructor( | ||
private readonly ongHubService: OngHubService, | ||
private readonly organizationService: OrganizationFacadeService, | ||
private readonly exceptionService: ExceptionsService, | ||
) {} | ||
|
||
/** | ||
* Synchronizes the organization data with ONG Hub. | ||
* | ||
* @param organizationId - The ID of the organization to be synchronized. | ||
* @param token - The authentication token for ONG Hub which is the same as the one from VIC because we share the same Cognito User Pool. | ||
* @returns A Promise that resolves to the updated IOrganizationModel. | ||
* @throws InternalServerErrorException if there's an error fetching data from ONG Hub or updating the organization. | ||
*/ | ||
async execute( | ||
organizationId: string, | ||
token: string, | ||
): Promise<IOrganizationModel> { | ||
const userWithOrganization = | ||
await this.ongHubService.getUserAndOrganizationDataFromOngHub(token); | ||
|
||
if (!userWithOrganization || !userWithOrganization.organization) { | ||
this.exceptionService.internalServerErrorException( | ||
OngHubExceptionMessages.ONG_002, | ||
); | ||
} | ||
|
||
try { | ||
const organization = await this.organizationService.updateOrganization( | ||
organizationId, | ||
{ | ||
name: userWithOrganization.organization.name, | ||
email: userWithOrganization.organization.email, | ||
phone: userWithOrganization.organization.phone, | ||
address: userWithOrganization.organization.address, | ||
activityArea: userWithOrganization.organization.activityArea, | ||
logo: userWithOrganization.organization.logo, | ||
description: userWithOrganization.organization.description, | ||
cui: userWithOrganization.organization.cui, | ||
legalReprezentativeFullName: | ||
userWithOrganization.organization.legalReprezentativeFullName, | ||
legalReprezentativeRole: | ||
userWithOrganization.organization.legalReprezentativeRole, | ||
}, | ||
); | ||
|
||
return organization; | ||
} catch (error) { | ||
console.log('[ONGHub Sync] Error updating organization:', error); | ||
this.exceptionService.internalServerErrorException( | ||
OngHubExceptionMessages.ONG_004, | ||
); | ||
} | ||
} | ||
} |
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 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
Oops, something went wrong.