Guest User

Untitled

a guest
Sep 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. type contactPredicate = (contact: Contact) => boolean;
  2. type contactLike = Contact | string | SelectedContact;
  3.  
  4. @Injectable()
  5. export class ContactService {
  6. private selectedContactId: string = '';
  7. public selectedContactSubject: BehaviorSubject<contactLike>;
  8.  
  9. public get SelectedContact(): contactLike {
  10. const contact: Contact = this.contactList.find((v) => v.Id === this.selectedContactId);
  11.  
  12. return contact ? contact : null;
  13. }
  14.  
  15. public set SelectedContact(value: contactLike) {
  16. this.selectedContactId = typeof value === 'string' ? value as string : value.Id;
  17. this.selectedContactSubject.next(this.findContact(this.selectedContactId));
  18. }
  19.  
  20. constructor() {
  21. this.selectedContactSubject = new BehaviorSubject<Contact>(this.findContact(this.selectedContactId));
  22. }
  23.  
  24. }
  25.  
  26. import { ContactService } from './contact.service';
  27.  
  28. @Injectable()
  29. export class FileService {
  30.  
  31. constructor(
  32. private httpServiceProvider: HttpServiceProvider,
  33. private userService: UserService,
  34. private contactService: ContactService) {
  35. }
  36.  
  37. getFiles(fileType: string, contactType: ContactType, skip: number, pageSize: number, organisationId: string): Observable<any> {
  38. let myUserId = this.userService.userId;
  39.  
  40. let selectedContact: SelectedContact;
  41. this.contactService.selectedContactSubject.subscribe(v => {
  42. selectedContact = (v as SelectedContact);
  43. });
  44. let selectedContactId = selectedContact.Id;
  45. let params: HttpParams = new HttpParams();
  46.  
  47. params = params.set('category', fileType)
  48. .append('senderId', myUserId)
  49. .append('receiverId', selectedContactId)
  50. .append('Skip', skip.toString())
  51. .append('PageSize', pageSize.toString())
  52. .append('contactType', String(contactType))
  53. .append('organisationId', organisationId);
  54.  
  55. return this.httpServiceProvider.httpGet(CONFIGURATION.GetFiles.url, params);
  56. }
  57.  
  58. }
Add Comment
Please, Sign In to add comment