import { Injectable } from '@angular/core'; import { Http, Response, URLSearchParams, RequestOptions, Headers, ResponseType } from '@angular/http'; import * as globals from '../core/common'; import { Observable } from 'rxjs'; import { map, catchError } from 'rxjs/operators'; import { IStaff } from '../core/IStaff'; import { IOrganisation } from '../core/IOrganisation'; import { IPersonSocialMedia } from '../core/IPersonSocialMedia'; import { IPlaceLived } from '../core/IPlacesLived'; import { IFamilyRelationship } from '../core/IFamilyRelationship'; import { IFamilyMember } from '../core/IFamilyMember'; import { IAddress } from '../core/IAddress'; import { IState } from '../core/IState'; import { ICountry } from '../core/ICountry'; import { IPersonCustomSocialMedia } from '../core/IPersonCustomSocialMedia'; import { ILocalisation } from '../core/ILocalisation'; import { ILifeEvents } from '../core/ILifeEvents'; import { IStaffMoreDetails } from '../core/IStaffMoreDetails'; import { environment } from '../../environments/environment'; import { IJobTitleSuggetion } from '../core/IJobTitleSuggetion'; import { IFilterKey } from '../core/IFilterKey'; @Injectable({ providedIn: 'root' }) export class StaffService { private getCountryUrl = globals.serverBase + ''; //common url part to be used for backend private baseUrl = globals.serverBase + ''; private getStaffUrl = globals.serverBase + '/api/Staff/GetStaff'; private getStaffByCompanyUrl = globals.serverBase + '/api/Staff/GetStaffByCompany'; private getStaffAddressUrl = globals.serverBase + '/api/Staff/GetStaffAddress'; private getStaffSocialMediaUrl = globals.serverBase + '/api/Staff/GetStaffSocialMedia'; private getStaffCustomSocialMediaUrl = globals.serverBase + '/api/Staff/GetStaffCustomSocialMedia'; private setStaffSocialMediaUrl = globals.serverBase + '/api/Staff/SetStaffSocialMedia'; private getStaffPlacesUrl = globals.serverBase + '/api/Staff/GetStaffPlaceLived'; private setStaffPlacesUrl = globals.serverBase + '/api/Staff/SetStaffPlaceLived'; private getRelationshipUrl = globals.serverBase + '/api/Staff/GetStaffRelationship'; private setRelationshipUrl = globals.serverBase + '/api/Staff/SetStaffRelationship'; private getStaffFamilyMemberUrl = globals.serverBase + '/api/Staff/GetStaffFamilyMember'; private setStaffFamilyMemberUrl = globals.serverBase + '/api/Staff/SetStaffFamilyMember'; private deleteStaffFamilyMemberUrl = globals.serverBase + '/api/Staff/DeleteStaffFamilyMember'; private getStaffLifeEventUrl = globals.serverBase + '/api/Staff/GetStaffLifeEvents'; private setStaffLifeEventUrl = globals.serverBase + '/api/Staff/SetStaffLifeEvents'; private deleteStaffLifeEventsUrl = globals.serverBase + '/api/Staff/DeletetStaffLifeEvents'; private setStaffLocalisationUrl = globals.serverBase + '/api/Staff/SetStaffLocalisation'; private setStaffAddressUrl = globals.serverBase + '/api/Staff/SetStaffAddress'; private setStaffProfileUrl = globals.serverBase + '/api/Staff/SetStaffProfile'; private setStaffMoreDetailsUrl = globals.serverBase + '/api/Staff/SetStaffMoreDetails'; private getStaffMoreDetailsUrl = globals.serverBase + '/api/Staff/GetStaffMoreDetails'; private deletetStaffMoreDetailsUrl = globals.serverBase + '/api/Staff/DeleteStaffMoreDetails'; private setStaffCustomSocialMediaUrl = globals.serverBase + '/api/Staff/SetStaffCustomSocialMedia'; private deleteStaffCustomSocialMediaUrl = globals.serverBase + '/api/Staff/DeleteStaffCustomSocialMedia'; private assignStaffInOrganisationChartUrl = globals.serverBase + '/api/Company/AssignStaffInOrganisationChart'; constructor(private _http: Http) { } getStaffList(id: string,filterKeys:IFilterKey[]): Observable { let myparams = new URLSearchParams(); myparams.append("id", id); myparams.append("filterKeys", JSON.stringify(filterKeys)); let options = new RequestOptions({ params: myparams }); // ------------ uncomment and configure this to call api ----------- if (environment.useDummyData == false) { return this._http.get(this.getStaffUrl, options) .pipe(map((response: Response) => response.json()), catchError(this.handleError)); } //dummy data starts here var org1: IOrganisation = { Id: 1, CompanyName: 'Whytes Chartered Accountants', Staff: 25, Type: 'Internal', Country: 'Australia', Email: 'info@whytes.com.au', Website: 'https://whytes.com.au', Phone: '+6123334', TypeId: 1, IndustryId: 1, Industry: 'Accounting', LogoUrl: "logo.png", PublicProfileNote: "public profile details", PrivateProfileNote: "private profile details", KeyWord: "keyword 1, keyword 2" } var org2: IOrganisation = { Id: 2, CompanyName: 'cloud', Staff: 10, Type: 'Outsource', Country: 'Australia', Email: 'info@cloud.com.au', Website: 'https://cloud.com.au', Phone: '+61212334', TypeId: 2, IndustryId: 2, Industry: 'Accounting', LogoUrl: "www.web.com", PublicProfileNote: "public profile details", PrivateProfileNote: "private profile details", KeyWord: "keyword 1, keyword 2" } var jobTitle1 : IJobTitleSuggetion = { Id :1 , TitleName : "Accountant"} var staffList: IStaff[] = []; var staff1: IStaff = { UniqueIdentifier :'abcd', Id: '14', ProfilePicture: "assets/default.png", FirstName: 'Des', LastName: 'Whyte', Company: org1, RoleName: 'Partner', Email: 'd.whyte@whytes.com.au', MobileCountryCode: '+61', Mobile: '+12586899', Office: '+78797997', PublicProfileNote: 'public note of Des whyte', PrivateProfileNote: '

private profile note of Des whyte

', Role: { Id: 1, RoleName: 'Partner', RoleDescription: 'ddfdfdf', StaffCount: 1, OrganisationId: 1, StaffList: [] }, OfficeExt: "12", Home: "+685478962524", Fax: "+96857412546", SendInvite: false, JobTitle: jobTitle1 } var staff2: IStaff = { UniqueIdentifier :'efgh', Id: '2', ProfilePicture: "assets/default.png", FirstName: 'Van', LastName: 'Le', Company: org2, RoleName: 'Manager', Email: 'v.le@whytes.com.au', Mobile: '+12586559', Office: '+787557997', PublicProfileNote: 'public note of van len', PrivateProfileNote: '

private profile note of van len

' } staffList.push(staff1); staffList.push(staff2); //return organisations; return this._http.get('', options) .pipe(map((response: Response) => staffList), catchError(this.handleError)) } getStaffListByCompany(id?: string): Observable { let myparams = new URLSearchParams(); myparams.append("id", id); let options = new RequestOptions({ params: myparams }); // ------------ uncomment and configure this to call api ----------- if (environment.useDummyData == false) { return this._http.get(this.getStaffByCompanyUrl, options) .pipe(map((response: Response) => response.json()), catchError(this.handleError)); } //dummy data starts here var org1: IOrganisation = { Id: 1, CompanyName: 'Whytes Chartered Accountants', Staff: 25, Type: 'Internal', Country: 'Australia', Email: 'info@whytes.com.au', Website: 'https://whytes.com.au', Phone: '+6123334', TypeId: 1, IndustryId: 1, Industry: 'Accounting', LogoUrl: "logo.png", PublicProfileNote: "public profile details", PrivateProfileNote: "private profile details", KeyWord: "keyword 1, keyword 2" } var org2: IOrganisation = { Id: 2, CompanyName: 'cloud', Staff: 10, Type: 'Outsource', Country: 'Australia', Email: 'info@cloud.com.au', Website: 'https://cloud.com.au', Phone: '+61212334', TypeId: 2, IndustryId: 2, Industry: 'Accounting', LogoUrl: "www.web.com", PublicProfileNote: "public profile details", PrivateProfileNote: "private profile details", KeyWord: "keyword 1, keyword 2" } var jobTitle1 : IJobTitleSuggetion = { Id :1 , TitleName : "Accountant"} var staffList: IStaff[] = []; var staff1: IStaff = { UniqueIdentifier :'abcd', Id: '14', ProfilePicture: "assets/default.png", FirstName: 'Des', LastName: 'Whyte', Company: org1, RoleName: 'Partner', Email: 'd.whyte@whytes.com.au', MobileCountryCode: '+61', Mobile: '+12586899', Office: '+78797997', PublicProfileNote: 'public note of Des whyte', PrivateProfileNote: '

private profile note of Des whyte

', Role: { Id: 1, RoleName: 'Partner', RoleDescription: 'ddfdfdf', StaffCount: 1, OrganisationId: 1, StaffList: [] }, OfficeExt: "12", Home: "+685478962524", Fax: "+96857412546", SendInvite: false, JobTitle: jobTitle1 } var staff2: IStaff = { UniqueIdentifier :'efgh', Id: '2', ProfilePicture: "assets/default.png", FirstName: 'Van', LastName: 'Le', Company: org2, RoleName: 'Manager', Email: 'v.le@whytes.com.au', Mobile: '+12586559', Office: '+787557997', PublicProfileNote: 'public note of van len', PrivateProfileNote: '

private profile note of van len

' } staffList.push(staff1); staffList.push(staff2); //return organisations; return this._http.get('', options) .pipe(map((response: Response) => staffList), catchError(this.handleError)) } // call api and get staff social account details getStaffSocialAccounts(Id?: string): Observable { let apiURL = ''; let myparams = new URLSearchParams(); myparams.append("id", Id); let options = new RequestOptions({ params: myparams }); // ------------ uncomment and configure this to call api ----------- if (environment.useDummyData == false) { return this._http.get(this.getStaffSocialMediaUrl, options) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } //dummy data for staff social accounts let StaffSocialMedia: IPersonSocialMedia; StaffSocialMedia = { Id: 1, StaffId: 14, Staff: null, LinkedIn: "linkedin", Twitter: "twitter", Facebook: "facebook", Google: "google", Website: "website", MessengerName: "messenger name", MessengerType: 1 } //return dummy response to Component return this._http.get(apiURL) .pipe(map((response: Response) => StaffSocialMedia), catchError(this.handleError)) } getStaffCustomSocialAccounts(Id?: string): Observable { let apiURL = ''; let myparams = new URLSearchParams(); myparams.append("id", Id); let options = new RequestOptions({ params: myparams }); // ------------ uncomment and configure this to call api ----------- if (environment.useDummyData == false) { return this._http.get(this.getStaffCustomSocialMediaUrl, options) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } //dummy data for staff social accounts let StaffSocialMedia: IPersonCustomSocialMedia[]; var staff2: IStaff = { UniqueIdentifier :'efgh', Id: '1', ProfilePicture: "assets/default.png", FirstName: 'Van', LastName: 'Le', Company: null, RoleName: 'Manager', Email: 'v.le@whytes.com.au' } StaffSocialMedia = [ { Id: 1, Staff: staff2, StaffId: 1, Name: "type 1", Details: "type 1 details" }, { Id: 2, Staff: staff2, StaffId: 1, Name: "type 2", Details: "type 2 details" }, { Id: 3, Staff: staff2, StaffId: 1, Name: "type 3", Details: "type 3 details" }, ] //return dummy response to Component return this._http.get(apiURL) .pipe(map((response: Response) => StaffSocialMedia), catchError(this.handleError)) } //call api and get staff places lived getStaffPlacesLived(Id?: string): Observable { let apiURL = ''; let myparams = new URLSearchParams(); myparams.append("id", Id); let options = new RequestOptions({ params: myparams }); // ------------ uncomment and configure this to call api ----------- if (environment.useDummyData == false) { return this._http.get(this.getStaffPlacesUrl, options) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } //dummy data for staff social accounts let StaffPalceLived: IPlaceLived; StaffPalceLived = { Id: 1, StaffId: 1, CurrentCity: "Melbourne, Florida, United States of America", HomeTown: "Colombo, Srilanka" } //return dummy response to Component return this._http.get(apiURL) .pipe(map((response: Response) => StaffPalceLived), catchError(this.handleError)) } //call api and get staff fmaily getStaffFamily(Id?: string): Observable { let apiURL = ''; let myparams = new URLSearchParams(); myparams.append("id", Id); let options = new RequestOptions({ params: myparams }); // ------------ uncomment and configure this to call api ----------- // this 'if' will switch services to use actual data and dummy data if (environment.useDummyData == false) { return this._http.get(this.getRelationshipUrl, options) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } //dummy data for staff social accounts let StaffFamily: IFamilyRelationship; StaffFamily = { Id: 1, StaffId: 1, RelationshipId: "3", Relationship: "Married", RelationshipDate: new Date('2018-05-16'), PartnerName: "Alex" } //return dummy response to Component return this._http.get(apiURL) .pipe(map((response: Response) => StaffFamily), catchError(this.handleError)) } //call api and get staff fmaily getStaffMember(Id?: string): Observable { let apiURL = ''; let myparams = new URLSearchParams(); myparams.append("id", Id); let options = new RequestOptions({ params: myparams }); // ------------ uncomment and configure this to call api ----------- if (environment.useDummyData == false) { return this._http.get(this.getStaffFamilyMemberUrl, options) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } //dummy data for staff social accounts let StaffMember: IFamilyMember[]; StaffMember = [ { Id: 1, StaffId: 1, MemberName: "George", MemberTypeId: "Father", EventDate: new Date(), EventTypeId: "Birthday" }, { Id: 2, StaffId: 1, MemberName: "Jennifer", MemberTypeId: "Mother", EventDate: new Date(), EventTypeId: "Birthday" }, { Id: 3, StaffId: 1, MemberName: "John", MemberTypeId: "Grand Father", EventDate: new Date(), EventTypeId: "Memorial" }, { Id: 4, StaffId: 1, MemberName: "Kate", MemberTypeId: "Wife", EventDate: new Date(), EventTypeId: "Anniversary" } ] //return dummy response to Component return this._http.get(apiURL) .pipe(map((response: Response) => StaffMember), catchError(this.handleError)) } //call api and get staff address getStaffAddress(Id: string): Observable { let myparams = new URLSearchParams(); myparams.append("id", Id); let options = new RequestOptions({ params: myparams }); // ------------ uncomment and configure this to call api ----------- if (environment.useDummyData == false) { return this._http.get(this.getStaffAddressUrl, options) .pipe(map((response: Response) => response.json()), catchError(this.handleError)); } //dummy address var staffAddress: IAddress; var state: IState = { Id: 3, CountryId: 2, StateName: "Melbourne" }; var country: ICountry = { Id: 2, CountryName: "Australia" }; staffAddress = { Id: 1, StaffId : 1, DoorNumber: 12, StreetName: "Level 1", StreetName2: "22 Delhi Street", City: "West Perth", PostCode: "6005", StateId: 1, State: state, CountryId: 2, Country: country }; return this._http.get('', options) .pipe(map((response: Response) => staffAddress), catchError(this.handleError)) } getStaffEvents(Id: string): Observable { let myparams = new URLSearchParams(); myparams.append("id", Id); let options = new RequestOptions({ params: myparams }); // ------------ uncomment and configure this to call api ----------- if (environment.useDummyData == false) { return this._http.get(this.getStaffLifeEventUrl, options) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } //dummy address var lifeEvents: ILifeEvents[]; lifeEvents = [ { Id: 1, Staff: null, StaffId: 0, EventCategory: "Education", EventDate: new Date('2010-05-17'), EventType: "New school", EventLable: "Started studying at ", Description: "Tech Education college" }, { Id: 2, Staff: null, StaffId: 0, EventCategory: "Work", EventDate: new Date('2010-07-02'), EventType: "Started a new job", EventLable: "Started new job at ", Description: "applazon Pty Ltd" }, { Id: 3, Staff: null, StaffId: 0, EventCategory: "Work", EventDate: new Date('2011-12-10'), EventType: "Promotion", EventLable: "Promoted as ", Description: "Manager at applazon Pty Ltd" }, { Id: 4, Staff: null, StaffId: 0, EventCategory: "Family", EventDate: new Date('2012-04-30'), EventType: "New pet", EventLable: "Got a new pet, ", Description: "Shelby" }, { Id: 5, Staff: null, StaffId: 0, EventCategory: "Education", EventDate: new Date('2014-07-09'), EventType: "Graduated", EventLable: "Graduated from ", Description: "INITI International University" } ]; return this._http.get('', options) .pipe(map((response: Response) => lifeEvents), catchError(this.handleError)) } //this method will send data to the api to save staff saveStaffProfile(staffProfile: IStaff): Observable { // this 'if' will switch services to use actual data and dummy data //if(environment.useDummyData==false){ return this._http.post(this.setStaffProfileUrl, staffProfile) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) //} } //this method will send staff more details data to backend saveStaffMoreDetails(staffMoreDetails : IStaffMoreDetails[]) : Observable { // this 'if' will switch services to use actual data and dummy data //if(environment.useDummyData==false){ return this._http.post(this.setStaffMoreDetailsUrl, staffMoreDetails) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) //} } saveStaffAddress(staffAddress : IAddress): Observable{ // this 'if' will switch services to use actual data and dummy data //if(environment.useDummyData==false){ return this._http.post(this.setStaffAddressUrl, staffAddress) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) //} } //this method will send data to the api to save staff social media saveStaffSocialMedia(staffSocialMedia: IPersonSocialMedia): Observable { // this 'if' will switch services to use actual data and dummy data //if(environment.useDummyData==false){ return this._http.post(this.setStaffSocialMediaUrl, staffSocialMedia) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) //} } //this method will send data to the api to save staff social media saveStaffRelationship(familyRelationship: IFamilyRelationship): Observable { // this 'if' will switch services to use actual data and dummy data //if(environment.useDummyData==false){ return this._http.post(this.setRelationshipUrl, familyRelationship) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) //} } //this method will send data to the api to save staff social media saveStaffPlacesLived(staffPlaceLived: IPlaceLived): Observable { // this 'if' will switch services to use actual data and dummy data //if(environment.useDummyData==false){ return this._http.post(this.setStaffPlacesUrl, staffPlaceLived) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) //} } //this method will send data to the api to save staff social media saveStaffFamilyMembers(staffFamilyMember: IFamilyMember[]): Observable { // this 'if' will switch services to use actual data and dummy data //if(environment.useDummyData==false){ return this._http.post(this.setStaffFamilyMemberUrl, staffFamilyMember) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) //} } saveStaffLifeEvents(staffLifeEvent: ILifeEvents[]): Observable { return this._http.post(this.setStaffLifeEventUrl, staffLifeEvent) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } //this method send staff localisation to the api saveStaffLocalisation(localisation: ILocalisation): Observable { return this._http.post(this.setStaffLocalisationUrl, localisation) .pipe(map((response: Response) => response), catchError(this.handleError)) } //this method will send staff more details data to backend saveStaffCustomSocialMedia(staffCustomSocialMedia : IPersonCustomSocialMedia[]) : Observable { // this 'if' will switch services to use actual data and dummy data //if(environment.useDummyData==false){ return this._http.post(this.setStaffCustomSocialMediaUrl, staffCustomSocialMedia) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) //} } //this method send delete request to api to delete staff more details fields when it applies to all staff deleteStaffMoreDetails(staffmoredetail : IStaffMoreDetails[]): Observable { // ------------ uncomment and configure this to call api ----------- if (environment.useDummyData == false) { return this._http.post(this.deletetStaffMoreDetailsUrl, staffmoredetail) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } } deleteStaffCustomSocialMedia(staffCustomSocial : IPersonCustomSocialMedia[]) : Observable{ // ------------ uncomment and configure this to call api ----------- if (environment.useDummyData == false) { return this._http.post(this.deleteStaffCustomSocialMediaUrl, staffCustomSocial) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } } deleteStaffFamilyMembers(staffFamilyMember: IFamilyMember[]): Observable { // ------------ uncomment and configure this to call api ----------- if (environment.useDummyData == false) { return this._http.post(this.deleteStaffFamilyMemberUrl, staffFamilyMember) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } } deleteStaffLifeEvents(staffLifeEvents: ILifeEvents[]): Observable { // ------------ uncomment and configure this to call api ----------- if (environment.useDummyData == false) { return this._http.post(this.deleteStaffLifeEventsUrl, staffLifeEvents) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } } getStaffMoreDetails(Id?: string): Observable { let myparams = new URLSearchParams(); myparams.append("id", Id); let options = new RequestOptions({ params: myparams }); // ------------ uncomment and configure this to call api ----------- if (environment.useDummyData == false) { return this._http.get(this.getStaffMoreDetailsUrl, options) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } //dummy data for staff social accounts let StaffMoreDetails: IStaffMoreDetails[]; StaffMoreDetails = [ { Id: 0, Staff:null, StaffId: 1, Title: "title 1", Content: "content 1" }, { Id: 0, Staff:null, StaffId: 1, Title: "title 2", Content: "content 2" }, { Id: 0, Staff:null, StaffId: 1, Title: "title 3", Content: "content 3" }, ] //return dummy response to Component return this._http.get('', options) .pipe(map((response: Response) => StaffMoreDetails), catchError(this.handleError)) } assignInOrganisationChart(Id? : string, superiorId?: string) : Observable{ let apiURL = ''; let myparams = new URLSearchParams(); myparams.append("id", Id); myparams.append("superiorId", superiorId); let options = new RequestOptions({ params: myparams }); // ------------ uncomment and configure this to call api ----------- if (environment.useDummyData == false) { return this._http.get(this.assignStaffInOrganisationChartUrl, options) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } } //The function of handling the error private handleError(error: Response) { console.log("Error in staff service"); console.log(error); return Observable.throw(error.json().error || 'Server error'); } }