Skip to main content

Company identity

Overview

The CreditCardCompanyIdentityService is an Angular service provided at the root level of the application. It is responsible for managing the identification of the current company using its CNPJ (Cadastro Nacional da Pessoa Jurídica). This CNPJ is passed as a parameter in HTTP requests to the backend, allowing it to verify the company's existence in the database and fetch its associated data.

Key Features

  • Singleton Service: Provided at the root level, ensuring a single instance is available across the entire application.
  • CNPJ Retrieval: Provides a method to retrieve the current company's CNPJ for inclusion in HTTP requests.

Dependencies

The service depends on the COMPANY_IDENTITY_CONFIGURATION_TOKEN, which is an optional dependency injected at runtime. This token is expected to provide an implementation of the CompanyIdentity interface.

Injected Dependencies

  • COMPANY_IDENTITY_CONFIGURATION_TOKEN: A token used to inject the CompanyIdentity instance.
  • CompanyIdentity: An interface or class that provides the get and set methods to handle the company's CNPJ.

Methods

set

public set(): string

Description: Set the CNPJ of the current company.

get

public get(): string

Description: Retrieves the CNPJ of the current company.

Returns:

  • A string representing the CNPJ of the current company.

Example Usage

Setting Up the Service

import { COMPANY_IDENTITY_SERVICE } from '@celerofinancas/common-domain';
import { PcpClientUiModule } from '@celerofinancas/pcp-client-ui';

@NgModule({
imports: [
PcpClientUiModule.forRoot(environment, CompanyIdentityService),
],
providers: [
{ provide: COMPANY_IDENTITY_SERVICE, useClass: CompanyIdentityService },
],
})
export class AppModule {}

Example of service implementation with the CompanyIdentity interface

import { Injectable } from '@angular/core';
import { CompanyIdentity } from '@celerofinancas/pcp-client-ui';

/**
* This service is provided in the application root and
* injected into pcp mfe via forRoot
*/
@Injectable({ providedIn: 'root' })
export class CompanyIdentityService implements CompanyIdentity {
/**
* Current company identification
*/
private companyId = undefined;

/**
* Set the current company id
*
* @param id string
*/
public set(id: string): void {
this.companyId = id;
}

/**
* Get the current company id
*
* @returns current company identification
*/
public get(): string {
return this.companyId;
}
}

Notes

  • Ensure that the set method of the service is implemented to automatically update the company whenever the current company is changed.