/** Angular Imports */ import { Injectable } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; /** rxjs Imports */ import { Observable } from 'rxjs'; /** * Clients service. */ @Injectable({ providedIn: 'root' }) export class CentersService { /** * @param {HttpClient} http Http Client to send requests. */ constructor(private http: HttpClient) { } /** * @param {any} filterBy Properties by which entries should be filtered. * @param {string} orderBy Property by which entries should be sorted. * @param {string} sortOrder Sort order: ascending or descending. * @param {number} offset Page offset. * @param {number} limit Number of entries within the page. * @returns {Observable} Centers. */ getCenters(filterBy: any, orderBy: string, sortOrder: string, offset: number, limit: number): Observable { let httpParams = new HttpParams() .set('offset', offset.toString()) .set('limit', limit.toString()) .set('sortOrder', sortOrder) .set('orderBy', orderBy) .set('paged', 'true'); // filterBy: name, externalId filterBy.forEach(function (filter: any) { if (filter.value) { console.log(filter.value); httpParams = httpParams.set(filter.type, filter.value); } }); return this.http.get('/centers', { params: httpParams }); } /** * @param {any} center Center to be created. * @returns {Observable} */ createCenter(center: any): Observable { return this.http.post('/centers', center); } /** * @param {number} officeId Office Id of office to get staff for. * @returns {Observable} */ getStaff(officeId: number): Observable { const httpParams = new HttpParams() .set('officeId', officeId.toString()) .set('staffInSelectedOfficeOnly', 'true'); return this.http.get('/centers/template', { params: httpParams }); } /** * @param centerId CenterID * @returns {Observable} Group Data for Center */ getCenterData(centerId: string): Observable { const httpParams = new HttpParams() .set('associations', 'groupMembers,collectionMeetingCalendar'); return this.http.get(`/centers/${centerId}`, { params: httpParams } ); } /** * @param centerId Center ID * @returns {Observable} Returns the entire details of the Center ID */ getCenterSummary(centerId: string): Observable { const httpParams = new HttpParams().set('R_groupId', centerId) .set('genericResultSet', 'false'); return this.http.get(`/runreports/GroupSummaryCounts`, { params: httpParams }); } /** * @param centerId Center ID * @returns {Observable} Returns the saving account for that center */ getSavingsAccountDetails(centerId: string): Observable { return this.http.get(`/centers/${centerId}/accounts`); } /** * @param centerId Center Id * @returns The notes for particular center */ getCenterNotes(centerId: string): Observable { return this.http.get(`/groups/${centerId}/notes`); } /** * Adds a note to the particular Center Id * @param centerId Center ID * @param noteData Note Data to be added * @returns {Observable} */ createCenterNote(centerId: string, noteData: any): Observable { return this.http.post(`/groups/${centerId}/notes`, noteData); } /** * Edits the Center Note * @param centerId Center ID * @param noteId Note ID * @param noteData Note Data */ editCenterNote(centerId: string, noteId: string, noteData: any) { return this.http.put(`/groups/${centerId}/notes/${noteId}`, noteData); } /** * Deletes the particular Note * @param centerId Center ID * @param noteId Note ID */ deleteCenterNote(centerId: string, noteId: string) { return this.http.delete(`/groups/${centerId}/notes/${noteId}`); } /** * Get Center Datatables */ getcenterDatatables() { const httpParams = new HttpParams().set('apptable', 'm_center'); return this.http.get(`/datatables`, { params: httpParams }); } /** * Get Center Datatable * @param centerId Center ID * @param datatableName Datatable Name */ getCenterDatatable(centerId: string, datatableName: string) { const httpParams = new HttpParams().set('genericResultSet', 'true'); return this.http.get(`/datatables/${datatableName}/${centerId}`, { params: httpParams }); } /** * @param centerId Center Id of center to get add datatable entry for. * @param datatableName Data Table name. * @param data Data. * @returns {Observable} */ addCenterDatatableEntry(centerId: string, datatableName: string, data: any): Observable { const httpParams = new HttpParams().set('genericResultSet', 'true'); return this.http.post(`/datatables/${datatableName}/${centerId}`, data, { params: httpParams }); } /** * @param centerId Center Id of center to get add datatable entry for. * @param datatableName Data Table name. * @param data Data. * @returns {Observable} */ editCenterDatatableEntry(centerId: string, datatableName: string, data: any): Observable { const httpParams = new HttpParams().set('genericResultSet', 'true'); return this.http.put(`/datatables/${datatableName}/${centerId}`, data, { params: httpParams }); } /** * @param centerId Center Id of center to get add datatable entry for. * @param datatableName Data Table name. * @returns {Observable} */ deleteDatatableContent(centerId: string, datatableName: string): Observable { const httpParams = new HttpParams().set('genericResultSet', 'true'); return this.http.delete(`/datatables/${datatableName}/${centerId}`, { params: httpParams }); } /** * @param {string} centerId Center Id * @param {string} command Command * @param {any} data Data * @returns {Observable} */ executeCenterActionCommand(centerId: string, command: string, data: any): Observable { const httpParams = new HttpParams().set('command', command); return this.http.post(`/centers/${centerId}`, data, { params: httpParams }); } /** * @param {string} centerId Center Id * @param {string} command Command * @param {any} data Data * @returns {Observable} */ executeGroupActionCommand(centerId: string, command: string, data: any): Observable { const httpParams = new HttpParams().set('command', command); return this.http.post(`/groups/${centerId}`, data, { params: httpParams }); } /** * @param centerId Center Id of center to get data for. * @returns {Observable} Center data. */ getGroupStaffData(centerId: string): Observable { const httpParams = new HttpParams().set('groupOrCenter', 'centers') .set('staffInSelectedOfficeOnly', 'true') .set('template', 'true'); return this.http.get(`/groups/${centerId}`, { params: httpParams }); } deleteCenter(centerId: any): Observable { return this.http.delete(`/centers/${centerId}`); } getCentersData(centerId: string, associations: string, template?: string) { let httpParams = new HttpParams().set('associations', associations); httpParams = template ? httpParams.set('template', template) : httpParams; return this.http.get(`/centers/${centerId}`, {params: httpParams}); } getMeetingsTemplate(centerId: any, calendarId: any): Observable { const httpParams = new HttpParams().set('calenderId', calendarId); return this.http.get(`/centers/${centerId}/meetings/template`); } assignCenterAttendance(centerId: any, calendarId: any, data: any): Observable { const httpParams = new HttpParams().set('calenderId', calendarId); return this.http.post(`/centers/${centerId}/meetings`, data, {params: httpParams}); } getCalendarTemplate(centerId: any): Observable { return this.http.get(`/centers/${centerId}/calendars/template`); } createCenterMeeting(centerId: any, data: any): Observable { return this.http.post(`/centers/${centerId}/calendars`, data); } getCalendarAndTemplate(centerId: any, calendarId: any): Observable { const httpParams = new HttpParams().set('template', 'true'); return this.http.get(`/centers/${centerId}/calendars/${calendarId}`, { params: httpParams }); } updateCenterMeeting(centerId: any, data: any, calendarId: any): Observable { return this.http.put(`/centers/${centerId}/calendars/${calendarId}`, data); } /** * Run Report Data for Staff Assignement History. * @param {any} reportName reportName object containing 'name' of the report * @param {object} centerId CenterId. * @returns {Observable} */ getStaffAssignmentHistoryData(reportName: any, centerId: any, tenantIdentifier: string, locale: string): Observable { const httpParams = new HttpParams() .set('tenantIdentifier', tenantIdentifier) .set('locale', locale) .set('R_centerId', centerId); return this.http.get(`/runreports/${reportName}`, { responseType: 'arraybuffer', observe: 'response', params: httpParams }); } }