Wednesday, 25 September 2024

Angular Add translater in .ts file

 add translater

  this.translate.get('CMPT_ALRTMSG').subscribe((translatedMessage: string) => {
        this.showwarning(translatedMessage)
      });

Tuesday, 24 September 2024

in live url refresh page getting error resource not found in angular 18

 import { ApplicationConfig, importProvidersFrom, provideZoneChangeDetection } from '@angular/core';

import { provideRouter, withHashLocation } from '@angular/router';

import { routes } from './app.routes';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { BrowserModule } from '@angular/platform-browser';
import { provideHttpClient, withInterceptorsFromDi, HTTP_INTERCEPTORS, withFetch } from '@angular/common/http';
import { provideNoopAnimations } from '@angular/platform-browser/animations';
import { IPublicClientApplication, PublicClientApplication, InteractionType, BrowserCacheLocation, LogLevel } from '@azure/msal-browser';
import { MsalInterceptor, MSAL_INSTANCE, MsalInterceptorConfiguration, MsalGuardConfiguration, MSAL_GUARD_CONFIG, MSAL_INTERCEPTOR_CONFIG, MsalService, MsalGuard, MsalBroadcastService } from '@azure/msal-angular';
import { MatButtonModule } from '@angular/material/button';
import { MatMenuModule } from '@angular/material/menu';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatListModule} from '@angular/material/list';
import { AuthService } from '../shared/services/auth.service';
import { environment } from '../environments/environment';


export function loggerCallback(logLevel: LogLevel, message: string) {

}
export function MSALInstanceFactory(): IPublicClientApplication {
  return new PublicClientApplication({
    auth: {
      clientId: environment.msalConfig.auth.clientId,
      authority: environment.msalConfig.auth.authority,
      redirectUri: '/',
      postLogoutRedirectUri: '/'
    },
    cache: {
      cacheLocation: BrowserCacheLocation.LocalStorage
    },
    system: {
      allowNativeBroker: false, // Disables WAM Broker
      loggerOptions: {
        loggerCallback,
        logLevel: LogLevel.Info,
        piiLoggingEnabled: false
      }
    }
  });
}

export function MSALInterceptorConfigFactory(): MsalInterceptorConfiguration {
  const protectedResourceMap = new Map<string, Array<string>>();
  protectedResourceMap.set(environment.apiConfig.uri, environment.apiConfig.scopes);

  return {
    interactionType: InteractionType.Redirect,
    protectedResourceMap
  };
}

export function MSALGuardConfigFactory(): MsalGuardConfiguration {
  return {
    interactionType: InteractionType.Redirect,
    authRequest: {
      scopes: [...environment.apiConfig.scopes]
    },
    loginFailedRoute: '/login-failed'
  };
}

export const appConfig: ApplicationConfig = {
  providers: [
    provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes, withHashLocation()), provideAnimationsAsync(),
    importProvidersFrom(BrowserModule, MatButtonModule, MatToolbarModule, MatListModule, MatMenuModule),
    provideNoopAnimations(),
    provideHttpClient(withInterceptorsFromDi(), withFetch()),
    {
        provide: HTTP_INTERCEPTORS,
        useClass: MsalInterceptor,
        multi: true
    },
    {
        provide: MSAL_INSTANCE,
        useFactory: MSALInstanceFactory
    },
    {
        provide: MSAL_GUARD_CONFIG,
        useFactory: MSALGuardConfigFactory
    },
    {
        provide: MSAL_INTERCEPTOR_CONFIG,
        useFactory: MSALInterceptorConfigFactory
    },

    MsalService,
    MsalGuard,
    MsalBroadcastService,
    provideAnimationsAsync()
  ]
};
provideRouter(routes, withHashLocation()) added this line to live url reloaded

Friday, 20 September 2024

Remove duplicate worfkflow approvers

 WITH CTE AS (

    SELECT 

        WorkflowProgress_ID,

        Division_ID,

        Country_Code,

        Site_Location,

        AFINumber,

        WorkFlow_ID,

        Approver_userID,

        ROW_NUMBER() OVER (PARTITION BY Division_ID, Country_Code, Site_Location, AFINumber, WorkFlow_ID, Approver_userID ORDER BY WorkflowProgress_ID) AS RowNum

    FROM 

        YourTableName

)

DELETE FROM CTE

WHERE RowNum > 1;


Wednesday, 18 September 2024

triggers in sql for update and insert

 CREATE TRIGGER tr_tbl_EmpCompetencies

ON [dbo].[tbl_EmpCompetencies]

AFTER  UPDATE, DELETE

AS

BEGIN

    IF EXISTS (SELECT 1 FROM DELETED) AND NOT EXISTS (SELECT 1 FROM INSERTED)

    BEGIN

        INSERT INTO [History].[tbl_EmpCompetencies] (

            [Action],  [ID], [LC_ID], [AppraisalID], [AppraisalTypeID], [EmpNumber], 

            [EmpRating], [EmpComment], [MgrRating], [MgrComment], [ApprovalStatusID], 

            [ApproverID], [ModifiedBy], [ModifiedDate], [IsActive])

        SELECT 

            'DELETE', [ID], [LC_ID], [AppraisalID], [AppraisalTypeID], [EmpNumber], 

            [EmpRating], [EmpComment], [MgrRating], [MgrComment], [ApprovalStatusID], 

            [ApproverID], [ModifiedBy], [ModifiedDate], [IsActive]

        FROM DELETED;

    END


    -- Handle UPDATE action (log only the updated/new data)

    IF EXISTS (SELECT 1 FROM INSERTED) AND EXISTS (SELECT 1 FROM DELETED)

    BEGIN

        INSERT INTO [History].[tbl_EmpCompetencies] (

            [Action],  [ID], [LC_ID], [AppraisalID], [AppraisalTypeID], [EmpNumber], 

            [EmpRating], [EmpComment], [MgrRating], [MgrComment], [ApprovalStatusID], 

            [ApproverID], [ModifiedBy], [ModifiedDate], [IsActive])

        SELECT 

            'UPDATE',  [ID], [LC_ID], [AppraisalID], [AppraisalTypeID], [EmpNumber], 

            [EmpRating], [EmpComment], [MgrRating], [MgrComment], [ApprovalStatusID], 

            [ApproverID], [ModifiedBy], [ModifiedDate], [IsActive]

        FROM INSERTED;

    END

END;

Monday, 16 September 2024

5 Essential Techniques for Turbocharging API Performance

 5 Essential Techniques for Turbocharging API Performance


A high-performing API is crucial for a great user experience and efficient application operation.

1. Caching
Store frequently accessed data in a cache (like Redis or Memcached) for rapid retrieval, bypassing the database for repeated requests.

Benefits
- Drastically reduces database load.
- Significantly improves response times.

Challenges
- Deciding on the right caching strategy (time-based, event-based, etc.)
- Managing cache invalidation to ensure data consistency.

2. Scale-out with Load Balancing
Distribute incoming requests across multiple server instances using a load balancer (like Nginx or HAProxy).

Benefits
- Handles increased traffic and prevents a single server from becoming a bottleneck.
- Improves reliability as requests can be routed to healthy instances if one fails.

Considerations
- Stateless applications are easier to scale horizontally.
- Requires infrastructure to manage load balancers.

3. Asynchronous Processing
Acknowledge client requests immediately and process them in the background, sending results later.

Benefits
- Unblocks the client and improves perceived responsiveness.
- Allows the API server to handle long-running tasks without delaying other requests.

Considerations
- Requires careful design to manage background tasks and notifications.
- Not suitable for all API operations (e.g., real-time data updates).

4. Pagination
Limit the number of records returned per request and provide a way to retrieve subsequent pages.

Benefits
- Reduces response sizes, especially for large datasets.
- Prevents excessive memory consumption on both client and server.

Implementation
- Use query parameters for page number and size.
- Include metadata in the response (e.g., total records, next/previous page links).

5. Connection Pooling
Maintain a pool of reusable database connections instead of creating a new one for each request.

Benefits
- Minimizes the overhead of establishing new connections.
- Significantly improves performance under high concurrency.

Implementation
- Most database libraries/frameworks offer built-in connection pooling mechanisms.

**Additional Tips**

- Optimize Database Queries
- Gzip Compression - Reduce response sizes.
- Content Delivery Network (CDN) - Cache static assets globally for faster delivery.
- Monitor and Profile - Use tools like New Relic or Datadog to identify bottlenecks.

HCL healthcare

 hcl health care f2f second round interview asked more uestions on microservice 1.apim manage all apis in one place 2.sql profiler in one fo...