src/lib/services/discussion.service.ts
constructor(http: HttpClient, csModule: CsModule)
|
|||||||||
Defined in src/lib/services/discussion.service.ts:40
|
|||||||||
Parameters :
|
appendPage |
appendPage(page: any, url: string)
|
Defined in src/lib/services/discussion.service.ts:66
|
Returns :
string
|
bookmarkPost | ||||||
bookmarkPost(pid: number)
|
||||||
Defined in src/lib/services/discussion.service.ts:141
|
||||||
Parameters :
Returns :
any
|
contextBasedTags | ||||
contextBasedTags(data)
|
||||
Defined in src/lib/services/discussion.service.ts:119
|
||||
Parameters :
Returns :
any
|
createForum | ||||
createForum(data)
|
||||
Defined in src/lib/services/discussion.service.ts:237
|
||||
Parameters :
Returns :
any
|
createPost | ||||||
createPost(data: any)
|
||||||
Defined in src/lib/services/discussion.service.ts:81
|
||||||
Parameters :
Returns :
any
|
deleteBookmarkPost | ||||||
deleteBookmarkPost(pid: number)
|
||||||
Defined in src/lib/services/discussion.service.ts:147
|
||||||
Parameters :
Returns :
any
|
deletePost |
deletePost(pid: number, uid: number)
|
Defined in src/lib/services/discussion.service.ts:285
|
Returns :
any
|
deleteTopic | ||||||
deleteTopic(tid: number)
|
||||||
Defined in src/lib/services/discussion.service.ts:293
|
||||||
Parameters :
Returns :
any
|
deleteVotePost | ||||||
deleteVotePost(pid: number)
|
||||||
Defined in src/lib/services/discussion.service.ts:135
|
||||||
Parameters :
Returns :
any
|
editPost |
editPost(pid: number, data: any)
|
Defined in src/lib/services/discussion.service.ts:281
|
Returns :
any
|
editTopic |
editTopic(tid: number, data: any)
|
Defined in src/lib/services/discussion.service.ts:289
|
Returns :
any
|
fetchAllCategories |
fetchAllCategories()
|
Defined in src/lib/services/discussion.service.ts:89
|
Returns :
any
|
fetchAllTag |
fetchAllTag()
|
Defined in src/lib/services/discussion.service.ts:114
|
Returns :
any
|
fetchAllTags |
fetchAllTags()
|
Defined in src/lib/services/discussion.service.ts:73
|
Returns :
any
|
fetchBestPost | ||||||
fetchBestPost(pageId: number)
|
||||||
Defined in src/lib/services/discussion.service.ts:219
|
||||||
Parameters :
Returns :
any
|
fetchDownvoted | ||||||
fetchDownvoted(pageId: number)
|
||||||
Defined in src/lib/services/discussion.service.ts:210
|
||||||
Parameters :
Returns :
any
|
fetchPopularD | ||||||
fetchPopularD(page?: any)
|
||||||
Defined in src/lib/services/discussion.service.ts:175
|
||||||
Parameters :
Returns :
any
|
fetchPostDetails |
fetchPostDetails()
|
Defined in src/lib/services/discussion.service.ts:124
|
Returns :
any
|
fetchProfileInfo | ||||||
fetchProfileInfo(slug: string)
|
||||||
Defined in src/lib/services/discussion.service.ts:202
|
||||||
Parameters :
Returns :
any
|
fetchRecentPost | ||||
fetchRecentPost(pageId?)
|
||||
Defined in src/lib/services/discussion.service.ts:159
|
||||
Parameters :
Returns :
any
|
fetchSaved | ||||||
fetchSaved(pageId: number)
|
||||||
Defined in src/lib/services/discussion.service.ts:214
|
||||||
Parameters :
Returns :
any
|
fetchSingleCategoryDetails | ||||||
fetchSingleCategoryDetails(cid: any)
|
||||||
Defined in src/lib/services/discussion.service.ts:106
|
||||||
Parameters :
Returns :
any
|
fetchSingleCategoryDetailsSort |
fetchSingleCategoryDetailsSort(cid: number, sort: any, page?: any)
|
Defined in src/lib/services/discussion.service.ts:110
|
Returns :
any
|
fetchTopicById |
fetchTopicById(topicId: number, slug?: any, page?: any)
|
Defined in src/lib/services/discussion.service.ts:179
|
Returns :
any
|
fetchTopicByIdSort |
fetchTopicByIdSort(topicId: number, sort: any, page?: any)
|
Defined in src/lib/services/discussion.service.ts:186
|
Returns :
any
|
fetchUnreadCOunt |
fetchUnreadCOunt()
|
Defined in src/lib/services/discussion.service.ts:193
|
Returns :
any
|
fetchUpvoted | ||||||
fetchUpvoted(pageId: number)
|
||||||
Defined in src/lib/services/discussion.service.ts:206
|
||||||
Parameters :
Returns :
any
|
fetchUserProfile | ||||
fetchUserProfile(userId)
|
||||
Defined in src/lib/services/discussion.service.ts:223
|
||||
Parameters :
Returns :
any
|
getContext | ||||||
getContext(key?: string)
|
||||||
Defined in src/lib/services/discussion.service.ts:277
|
||||||
Parameters :
Returns :
any
|
getContextBasedDiscussion | ||||
getContextBasedDiscussion(data)
|
||||
Defined in src/lib/services/discussion.service.ts:167
|
||||
Parameters :
Returns :
any
|
getContextBasedTagDiscussion | ||||
getContextBasedTagDiscussion(data)
|
||||
Defined in src/lib/services/discussion.service.ts:171
|
||||
Parameters :
Returns :
any
|
getContextBasedTopic |
getContextBasedTopic(slug: string, pageId: number)
|
Defined in src/lib/services/discussion.service.ts:228
|
Returns :
any
|
getForumIds | ||||
getForumIds(data)
|
||||
Defined in src/lib/services/discussion.service.ts:241
|
||||
Parameters :
Returns :
any
|
getTagBasedDiscussion |
getTagBasedDiscussion(tag?: string, page?: any)
|
Defined in src/lib/services/discussion.service.ts:163
|
Returns :
any
|
initializeUserDetails | ||||
initializeUserDetails(userId)
|
||||
Defined in src/lib/services/discussion.service.ts:54
|
||||
Parameters :
Returns :
void
|
registerUser | ||||
registerUser(data)
|
||||
Defined in src/lib/services/discussion.service.ts:233
|
||||
Parameters :
Returns :
any
|
replyPost |
replyPost(tid: number, data: any)
|
Defined in src/lib/services/discussion.service.ts:153
|
Returns :
any
|
setContext | ||||||
setContext(key, value)
|
||||||
Defined in src/lib/services/discussion.service.ts:269
|
||||||
Parameters :
Returns :
void
|
showTrafficAlert | ||||
showTrafficAlert(errorObject)
|
||||
Defined in src/lib/services/discussion.service.ts:300
|
||||
To check the error code and show alert message if it is 502 - error
Parameters :
Returns :
void
|
votePost |
votePost(pid: number, data: any)
|
Defined in src/lib/services/discussion.service.ts:129
|
Returns :
any
|
Private _context |
Type : any
|
Default value : {}
|
Defined in src/lib/services/discussion.service.ts:36
|
Private _forumIds |
Type : any
|
Defined in src/lib/services/discussion.service.ts:32
|
Private _userDetails |
Type : any
|
Defined in src/lib/services/discussion.service.ts:26
|
Private _userId |
Type : any
|
Defined in src/lib/services/discussion.service.ts:29
|
Public alertEvent |
Default value : new Subject()
|
Defined in src/lib/services/discussion.service.ts:38
|
Private csDiscussionService |
Type : CsDiscussionService
|
Defined in src/lib/services/discussion.service.ts:33
|
usr |
Type : any
|
Defined in src/lib/services/discussion.service.ts:40
|
userDetails | ||||
getuserDetails()
|
||||
Defined in src/lib/services/discussion.service.ts:249
|
||||
setuserDetails(userDetails)
|
||||
Defined in src/lib/services/discussion.service.ts:245
|
||||
Parameters :
Returns :
void
|
userId | ||||
getuserId()
|
||||
Defined in src/lib/services/discussion.service.ts:257
|
||||
setuserId(userId)
|
||||
Defined in src/lib/services/discussion.service.ts:253
|
||||
Parameters :
Returns :
void
|
forumIds | ||||
getforumIds()
|
||||
Defined in src/lib/services/discussion.service.ts:265
|
||||
setforumIds(ids)
|
||||
Defined in src/lib/services/discussion.service.ts:261
|
||||
Parameters :
Returns :
void
|
import { Inject, Injectable } from '@angular/core';
import { of as observableOf, throwError as observableThrowError, Observable, throwError, Subject } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { urlConfig } from './../config/url.config';
import { NSDiscussData } from '../models/discuss.model';
/* tslint:disable */
import * as _ from 'lodash'
import { CsDiscussionService } from '@project-sunbird/client-services/services/discussion';
import { CsModule } from '@project-sunbird/client-services';
/* tslint:enable */
export const CONTEXT_PROPS = {
cid: 'cid',
tid: 'tid',
uid: 'uid'
};
@Injectable({
providedIn: 'root'
})
export class DiscussionService {
// tslint:disable-next-line:variable-name
private _userDetails: any;
// tslint:disable-next-line:variable-name
private _userId: any;
// tslint:disable-next-line:variable-name
private _forumIds: any;
private csDiscussionService: CsDiscussionService;
// tslint:disable-next-line:variable-name
private _context: any = {};
public alertEvent = new Subject();
usr: any;
constructor(
private http: HttpClient,
@Inject('CsModule') private csModule: CsModule
) {
// TODO: Take from the logged in user data;
// this.usr = this.configSvc.userProfile
this.usr = { userId: '1234' };
console.log('CsModule init---', CsModule.instance);
this.csDiscussionService = CsModule.instance.discussionService;
}
initializeUserDetails(userId) {
userId = userId
this.userDetails = JSON.parse(sessionStorage.getItem('dFUserDetails'))
this.fetchUserProfile(userId).subscribe(response => {
this.userDetails = response;
sessionStorage.setItem('dFUserDetails', JSON.stringify(response));
}, (error) => {
// TODO: toaster error
console.log('error fetching user details');
});
}
appendPage(page: any, url: string) {
if (page) {
return `${url}?page=${page}`;
}
return `${url}?page=1`;
}
fetchAllTags() {
// const tags = this.http.get(urlConfig.getAllTags())
// .toPromise();
// return tags;
console.log('innn fetchAllTags');
return this.csDiscussionService.fetchAllTags();
}
createPost(data: any) {
// return this.http.post(urlConfig.createPost(), data);
return this.csDiscussionService.createPost(data);
}
/**
* @description To get all the categories
*/
fetchAllCategories() {
// return this.http.get<NSDiscussData.ICategorie[]>(urlConfig.getAllCategories()).pipe(
// map((data: any) => {
// // Taking only "categories" from the response
// const resp = (data as any).categories;
// return resp;
// }),
// catchError( error => {
// return throwError( 'Something went wrong!' );
// })
// );
console.log('in fetchall categories');
return this.csDiscussionService.fetchAllCategories().pipe(
map((data: any) => data.categories)
);
}
fetchSingleCategoryDetails(cid: any) {
return this.csDiscussionService.fetchSingleCategoryDetails(cid);
// return this.http.get<NSDiscussData.ICategorie>(urlConfig.getSingleCategoryDetails(cid));
}
fetchSingleCategoryDetailsSort(cid: number, sort: any, page?: any) {
return this.csDiscussionService.fetchSingleCategoryDetails(cid);
}
fetchAllTag() {
return this.csDiscussionService.fetchAllTags();
// return this.http.get(urlConfig.getAllTags());
}
contextBasedTags(data) {
return this.csDiscussionService.contextBasedTags(data);
// return this.http.get(urlConfig.getAllTags());
}
fetchPostDetails() {
return this.csDiscussionService.fetchAllTags();
// return this.http.get(urlConfig.getAllTags());
}
votePost(pid: number, data: any) {
return this.csDiscussionService.votePost(pid, data);
// const url = urlConfig.votePost(pid);
// return this.http.post(url, data);
}
deleteVotePost(pid: number) {
// const url = urlConfig.votePost(pid);
// return this.http.delete(url);
return this.csDiscussionService.deleteVotePost(pid);
}
bookmarkPost(pid: number) {
// const url = urlConfig.bookmarkPost(pid);
// return this.http.post(url, {});
return this.csDiscussionService.bookmarkPost(pid);
}
deleteBookmarkPost(pid: number) {
// const url = urlConfig.bookmarkPost(pid);
// return this.http.delete(url);
return this.csDiscussionService.deleteBookmarkPost(pid);
}
replyPost(tid: number, data: any) {
// const url = urlConfig.replyPost(tid);
// return this.http.post(url, data);
return this.csDiscussionService.replyPost(tid, data);
}
fetchRecentPost(pageId?) {
return this.csDiscussionService.recentPost(_.get(this._userDetails, 'username'), pageId);
}
getTagBasedDiscussion(tag?: string, page?: any) {
return this.csDiscussionService.getTagBasedDiscussion(tag);
}
getContextBasedDiscussion(data) {
return this.csDiscussionService.getContextBasedDiscussion(data);
}
getContextBasedTagDiscussion(data) {
return this.csDiscussionService.getContextBasedTagDiscussion(data);
}
fetchPopularD(page?: any) {
return this.csDiscussionService.popularPost(page);
}
fetchTopicById(topicId: number, slug?: any, page?: any) {
// let url = urlConfig.getTopic() + '/' + topicId.toString() + '/' + slug;
// url = this.appendPage(page, url);
// return this.http.get(url);
return this.csDiscussionService.fetchTopicById(topicId, slug, page);
}
fetchTopicByIdSort(topicId: number, sort: any, page?: any) {
// let url = urlConfig.getTopic + topicId.toString();
// url = this.appendPage(page, url);
// return this.http.get(`${url}&sort=${sort}`);
return this.csDiscussionService.fetchTopicById(topicId, sort, page);
}
fetchUnreadCOunt() {
// return this.http.get<any>(urlConfig.unread());
return this.csDiscussionService.fetchUnreadCOunt();
}
// fetchProfile() {
// // return this.http.get(urlConfig.profile());
// return this.csDiscussionService.fetchProfile();
// }
fetchProfileInfo(slug: string) {
// return this.http.get(urlConfig.fetchProfile(slug));
return this.csDiscussionService.fetchProfileInfo(slug);
}
fetchUpvoted(pageId: number) {// 0
// return this.http.get(urlConfig.listUpVote(_.get(this._userDetails, 'username')));
return this.csDiscussionService.fetchUpvoted(_.get(this._userDetails, 'username'), pageId);
}
fetchDownvoted(pageId: number) { // 0
// return this.http.get(urlConfig.listDownVoted(_.get(this._userDetails, 'username')));
return this.csDiscussionService.fetchDownvoted(_.get(this._userDetails, 'username'), pageId);
}
fetchSaved(pageId: number) { // 0 this.usr.userId
// return this.http.get(urlConfig.listSaved(_.get(this._userDetails, 'username')));
return this.csDiscussionService.fetchSaved(_.get(this._userDetails, 'username'), pageId);
}
fetchBestPost(pageId: number) {
return this.csDiscussionService.fetchBestPost(_.get(this._userDetails, 'username'), pageId);
}
fetchUserProfile(userId) {
// return this.http.get<any>(urlConfig.userDetails(userName));
return this.csDiscussionService.getUserDetails(userId);
}
getContextBasedTopic(slug: string, pageId: number) {
// return this.http.get(urlConfig.getContextBasedTopics(slug));
return this.csDiscussionService.getContextBasedTopic(slug, pageId);
}
registerUser(data) {
return this.http.post(urlConfig.registerUser(), data);
}
createForum(data){
return this.csDiscussionService.createForum(data)
}
getForumIds(data){
return this.csDiscussionService.getForumIds(data).toPromise()
}
set userDetails(userDetails) {
this._userDetails = userDetails;
}
get userDetails() {
return this._userDetails;
}
set userId(userId) {
this._userId = userId;
}
get userId() {
return this._userId;
}
set forumIds(ids) {
this._forumIds = ids;
}
get forumIds() {
return this._forumIds;
}
setContext(key, value) {
if (CONTEXT_PROPS[key]) {
this._context[key] = value;
} else {
console.log('Context can not be set for this key: ', key);
}
}
getContext(key?: string) {
return key ? this._context[key] : this._context;
}
editPost(pid: number, data: any) {
return this.csDiscussionService.editPost(pid, data);
}
deletePost(pid: number, uid: number) {
return this.csDiscussionService.deletePost(pid, uid);
}
editTopic(tid: number, data: any) {
return this.csDiscussionService.editTopic(tid, data);
}
deleteTopic(tid: number) {
return this.csDiscussionService.deleteTopic(tid);
}
/** To check the error code and show alert message
* if it is 502 - error
*/
showTrafficAlert(errorObject) {
const errorCode = _.get(errorObject, 'response.responseCode')
if(errorCode) {
if([502, '502'].includes(errorCode)) {
this.alertEvent.next();
}
}
}
}