File

projects/congarevenuecloud/ecommerce/src/lib/modules/crm/services/user.service.ts

Description

The User service provides methods for getting current user related details.

Usage

import { UserService, AObjectService } from '@congarevenuecloud/ecommerce';

constructor(private userService: UserService) {}

// or

export class MyService extends AObjectService {
private userService: UserService = this.injector.get(UserService);
}

Extends

AObjectService

Index

Properties
Methods

Methods

getBrowserLocale
getBrowserLocale(underscore: boolean)

Retrieves the browser locale for the current user

Example:

import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
lang:string;
constructor(private userService: UserService){}

getBrowserLocale(){
this.lang = this.userService.getBrowserLocale();
}
}
Parameters :
Name Type Optional Default value Description
underscore boolean No true

when set to true, will replace dash ('-') with an underscore ('_')

Returns : any
getCurrentUser
getCurrentUser()

Method gets active user.

Example:

import { UserService, User } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';
export class MyComponent implements OnInit{
user: User;
user$: Observable<User>
constructor(private userService: UserService){}

this.userService.getCurrentUser().subscribe(user => this.user = user);
// or
this.user$ = this.userService.getCurrentUser();

}
Returns : Observable<User>

observable instance of the active user.

getCurrentUserLocale
getCurrentUserLocale(underscore: boolean)

Retrieves the current user locale to support salesforce and other environment

Example:

import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
lang:string;
constructor(private userService: UserService){}

getCurrentUserLanguage(){
this.lang = this.userService.getCurrentUserLocale();
}

}
Parameters :
Name Type Optional Default value Description
underscore boolean No true

when set to true, will replace dash ('-') with an underscore ('_')

Returns : Observable<string>

return an observable string for current user locale.

getUserInitials
getUserInitials()

Retrieves the initials of the current user by extracting the first letter of their first and last names.

Returns : Observable<string>

An observable emits the user's initials.

initializeGuestUser
initializeGuestUser()

Method is used to create a guest user record prior to registration. Will set the defaults on the record to browser defaults.

Example:

import { UserService, User } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';
export class MyComponent implements OnInit{
guestUser: User;
guestUser$: Observable<User>
constructor(private userService: UserService){}

this.userService.initializeGuestUser().subscribe(user => this.user = user);
// or
this.user$ = this.userService.initializeGuestUser();

}
Returns : Observable<User>

a user record containing the browser defaults (will not be committed to db).

isGuest
isGuest()

Used for determining if the current user is a guest user or not.

Example:

import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
isGuest: boolean;
constructor(private userService: UserService){}

this.isGuest = this.userService.isGuest();

}
Returns : Observable<boolean>

a boolean observable. Will be true if the user is a guest user.

isLoggedIn
isLoggedIn()

Method is used to determine if the user has authenticated and successfully logged in or not.

Example:

import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
isUserLoggedIn:boolean;
isUserLoggedIn$:Observable<boolean>;
constructor(private userService: UserService){}

checkLoginState():boolean {
this.userService.isLoggedIn().subscribe(res=> isUserLoggedIn = res);
// or
isUserLoggedIn$ = this.userService.isLoggedIn();
}
}
Returns : Observable<boolean>

a boolean observable. Returns true if the user is successfully logged in.

login
login()

Primary method responsible to log a user in to the Conga platform

Example:

import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
constructor(private userService: UserService){}
login(){
this.userService.login();
}
}
Returns : void
logout
logout()

Primary method responsible to log a user out of the Conga platform

  • Example:

import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
constructor(private userService: UserService){}
logout(){
this.userService.logout();
}
}
Returns : void
me
me()

Primary method for retrieving the current user record.

Example:

import { UserService, User } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';
export class MyComponent implements OnInit{
user: User;
user$: Observable<User>
constructor(private userService: UserService){}

this.userService.me().subscribe(user => this.user = user);
// or
this.user$ = this.userService.me();

}
Returns : Observable<User>

an observable of type User.

onInit
onInit()
Returns : void
searchUsersByName
searchUsersByName(searchString: string, pageSize: number, pageNumber: number, sortDirection: "DESC" | "ASC", sortField?: string)

This method is used to search User records based on the user name passed.

  • Example:

import { UserService, User } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{

user: User;
user$: Observable<Array<User>>
constructor(private userService: UserService){}

searchUsersByName(searchString:string) {
this.userService.searchUsersByName(searchString).subscribe(user => this.user = user);
// or
this.user$ = this.userService.searchUsersByName();
}
}
Parameters :
Name Type Optional Default value Description
searchString string No

A string used to search for user records, Minimum characters in the search string must be 3.

pageSize number No 10

The number of user records to include in the result set. Defaults to 10.

pageNumber number No 1

The page number to retrieve. Defaults to 1.

sortDirection "DESC" | "ASC" No 'DESC'

The sorting direction for user records, either 'ASC' or 'DESC'. Defaults to 'DESC'.

sortField string Yes

The field by which to sort the user records (optional).

An Observable containing a list of User records that match the search criteria.

setCurrency
setCurrency(currencyIsoCode: string, commit: boolean)

Method sets the currency for the current user.

Example:

import { UserService, User } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';
export class MyComponent implements OnInit{
user: User;
user$: Observable<User>
constructor(private userService: UserService){}

this.userService.setCurrency(value).subscribe(user => this.user = user);
// or
this.user$ = this.userService.setCurrency(value);

}
Parameters :
Name Type Optional Default value Description
currencyIsoCode string No

the iso code of the currency to set (i.e. 'USD')

commit boolean No false

set to true to commit the change to the DataBase.

Returns : Observable<User>

observable instance of current user with updated currency.

setLocale
setLocale(locale: string)

Method sets the locale for the current user.

Example:

import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
constructor(private userService: UserService){}

setLocale(value:string){
this.userService.setLocale(value);
}
}
Parameters :
Name Type Optional Description
locale string No

locale to set on current user

Returns : Observable<void>

an empty observable.

setUserDefaults
setUserDefaults(user: User)

Method sets the defaults like language, locale & email encoding type for user

Example:

import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
constructor(private userService: UserService){}

setDefaultUserData(value) {
this.userService.setUserDefaults(value);
}
}
Parameters :
Name Type Optional Description
user User No

the user record to set the defaults on

Returns : void
updateCurrentUser
updateCurrentUser(user: User)

Method updates the user details.

Example:

import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
constructor(private userService: UserService){}

updateUserInfo(value) {
this.userService.updateCurrentUser(value);
}
}
Parameters :
Name Type Optional Description
user User No

the user record to update.

Returns : Observable<User>

an observable of the updated user.

Properties

apiService
Type : ApiService
Default value : this.injector.get(ApiService)
Protected CACHE_KEY
Type : string
Default value : 'User'
securityService
Type : OidcSecurityService
Default value : this.injector.get(OidcSecurityService)
type
Default value : User

results matching ""

    No results matching ""