import { Injectable } from '@angular/core'; import { User } from '../../_models/Authentication/user'; import { HttpClient } from '@angular/common/http'; import { JwtHelperService } from '@auth0/angular-jwt'; import { map } from 'rxjs/operators'; import { ApiService } from '../../app.api.service'; import { EnumConfigurationType, EnumRoleType, EnumSystemType, EnumUserType } from '../../_models/enums'; import { HRMNotificationService } from '../../app.notification.service'; import { Role, RolePermission } from '../../_models/Authentication/role'; import { SearchEmployee } from '../../_models/Employee/searchEmployee'; import { PayrollType } from '../../_models/Authentication/payrollType'; import { UserRole } from '../../_models/Authentication/UserRole'; import { UserAccessType } from '../../_models/Authentication/UserAccessType'; import { PasswordHistory } from '../../_models/Authentication/passwordHistory'; import { Router } from '@angular/router'; import { Bookmark } from '../../_models/Basic/bookmark'; import { Subject } from 'rxjs'; import { PendingJobDTO } from 'src/app/_models/Work-Flow/pendingJobDTO'; import { DataPermission } from 'src/app/_models/Basic/DataPermission'; @Injectable() export class AuthService { baseUrl = ApiService.BASE_URL + 'Authentication/'; jwtHelper = new JwtHelperService(); decodedToken: any; subject: Subject; subject2: Subject; // bookmarks: Bookmark[]; constructor(private http: HttpClient, public apiService: ApiService , public notificationService: HRMNotificationService, private router: Router) { this.subject = new Subject(); this.subject2 = new Subject(); // this.loadBookmark(); // console.log(this.bookmarks); } login(model: any) { return this.http.post(this.apiService.base_url + '/Authentication/login', model).pipe( map((response: any) => { const user = response; if (user) { // debugger; localStorage.setItem('token', user); ApiService.AuthenticationToken = user; // this.decodedToken = this.jwtHelper.decodeToken(ApiService.AuthenticationToken); } }) ); } userPayrolltypeSwitch(param: any): any { return this.apiService.httpPost('/Authentication/userPayrolltypeSwitch', param); } SwtichUserMode(param: any): any { return this.apiService.httpPost('/Authentication/switchuser', param); } GetLogInUserType(): any { return this.apiService.httpGet('/Authentication/GetLogInUserType'); } GetCurrentUser(): any { return this.apiService.httpGet('/Authentication/GetCurrentUser'); } getUserByEmail(email: string) { return this.apiService.httpGet('/Authentication/getUserByEmail/' + email); } GetUsers(usertype: EnumUserType, loginidid?: string, name?: string): any { //const params = { // LogInID: loginid == undefined ? '' : loginid, // Name: name == undefined ? '' : name, // userType: usertype //}; const nname = this.apiService.getApiDefaultData(name); const sloginid = this.apiService.getApiDefaultData(loginidid); return this.apiService.httpGet('/Authentication/GetUsers/' + usertype + '/' + loginidid + '/' + name); } GetAllEmpNotYetUser() { return this.apiService.httpGet('/Authentication/GetAllEmpNotYetUser'); } logout() { localStorage.removeItem('forgotpass'); localStorage.removeItem('token'); localStorage.removeItem('menuList'); this.router.navigate(['/login']); } SaveUser(oUser: User): any { return this.apiService.httpPost('/Authentication/SaveUser', oUser); } ApproveUser(oUser: User): any { return this.apiService.httpPost('/Authentication/ApproveUser', oUser); } DoActiveAndIntacive(oUser: User): any { return this.apiService.httpPost('/Authentication/DoActiveAndIntacive', oUser); } GetAllUsers() { return this.apiService.httpGet('/Authentication/getAllUsers'); } getBookmarks() { return this.apiService.httpGet('/Authentication/getBookmarks'); } SaveBookmark(oBookmark: Bookmark): any { return this.apiService.httpPost('/Authentication/SaveBookmark', oBookmark); } deleteBookmark(param: any) { return this.apiService.httpPost('/Authentication/deleteBookmark', param); } deleteBookmarkByMenuKey(param: any) { return this.apiService.httpPost('/Authentication/deleteBookmarkByMenuKey', param); } getPendingJob(employeeId: number) { return this.apiService.httpGet('/Workflow/getPendingJob' + '/' + employeeId); } loggedIn() { const token = localStorage.getItem('token'); ApiService.AuthenticationToken = token; return !this.jwtHelper.isTokenExpired(token); } register(user: User) { return this.http.post(this.baseUrl + 'register', user); } loadMenu() { return this.http.get(this.baseUrl + 'loadMenu'); } getAllRoles() { return this.apiService.httpGet('/Authentication/getAllRoles'); } getRole(roleID: number) { return this.apiService.httpGet('/Authentication/getRole/' + roleID); } getMenuesFromConfig() { return this.apiService.httpGet('/Authentication/getMenuesFromConfig'); } saveRole(params: Role) { return this.apiService.httpPost('/Authentication/saveRole', params); } GetRolePermissionbyUserID() { return this.apiService.httpGet('/Authentication/GetRolePermissionbyUserID'); } getUserRoles(roletype: EnumRoleType, userID?: number, roleid?: number) { const nuserid = this.apiService.getApiDefaultIntData(userID); const nroletype = this.apiService.getApiDefaultIntData(roleid); return this.apiService.httpGet('/Authentication/getUserRoles/' + roletype + '/' + nuserid + '/' + nroletype); } GetEmpUserRole(searchemps: SearchEmployee[]) { return this.apiService.httpPost('/Authentication/GetEmpUserRole', searchemps); } saveUserRole(params: any) { return this.apiService.httpPost('/Authentication/saveUserRole', params); } GetAllPayrollTypes() { return this.apiService.httpGet('/Authentication/GetAllPayrollTypes'); } GetPayrollTypesByLoginID(loginID: string) { return this.apiService.httpGet('/Authentication/GetPayrollTypesByLoginID/' + loginID); } GetBenifitsProcessStatus() { return this.apiService.httpGet('/Authentication/GetBenifitsProcessStatus' ); } getSwitchUserId(usertype: EnumUserType) { return this.apiService.httpGet('/Authentication/getSwitchUserId/'+ usertype); } GetPayrollTypeByLoginID() { return this.apiService.httpGet('/Authentication/GetPayrollTypeByLoginID'); } getAdminPayrollTypes() { return this.apiService.httpGet('/Authentication/getAdminPayrollTypes'); } GetUserAccessType(userid: number) { return this.apiService.httpGet('/Authentication/GetUserAccessType/' + userid); } SaveUserAccessType(acesssTypes: UserAccessType[]) { return this.apiService.httpPost('/Authentication/SaveUserAccessType', acesssTypes); } changePassword(userData: any) { return this.apiService.httpPost('/Authentication/changePassword', userData); } changePasswordbyAdmin(userData: any) { return this.apiService.httpPost('/Authentication/changePasswordbyAdmin', userData); } forgotPassword(data: any) { return this.apiService.httpPost('/Authentication/forgotPassword', data); } getVersionNumber() { return this.apiService.httpGet('/Authentication/getVersionNumber'); } GetUserByLoingID(loginid: string, systemType: EnumSystemType) { return this.apiService.httpGet('/Authentication/GetUserByLoingID/' + loginid + '/' + systemType); } GetUserByID(userid:number) { return this.apiService.httpGet('/Authentication/GetUserByID/' + userid); } //Below code is for Data getUserByUserType(param: any): any { return this.apiService.httpPost('/Authentication/getUserByUserType', param); } addPermission(param: any) { return this.apiService.httpPost('/Authentication/addPermission', param); } loadDataPermission(userid: number, payrolltypeid:number) { return this.apiService.httpGet('/Authentication/loadDataPermission/' + userid + "/" + payrolltypeid); } DeletedataPermission(item:any) { return this.apiService.httpPost ('/Authentication/deletePermission' ,item); } getSSOStatus() { return this.apiService.httpGet('/Authentication/getSSOStatus'); } GetOperationDate() { return this.apiService.httpGet('/Authentication/getOperationDate'); } }