src/app/modules/workspace/services/editors/editor.service.ts
Service to provides CRUD methods to make content api request by extending DataService.
Properties |
|
Methods |
constructor(configService: ConfigService, contentService: ContentService, publicDataService: PublicDataService, workspaceService: WorkSpaceService, userService: UserService)
|
||||||||||||||||||
constructor
Parameters :
|
create | ||||||
create(req)
|
||||||
Create content Id for the editor
Parameters :
Returns :
Observable<ServerResponse>
|
getContent |
getContent(contentId: string, option: any)
|
get content details by id and query param
Returns :
Observable<ServerResponse>
|
getOwnershipType |
getOwnershipType()
|
Returns :
any
|
baseUrl |
Type : string
|
base Url for content api |
Public configService |
Type : ConfigService
|
reference of config service. |
Public contentService |
Type : ContentService
|
reference of content service. |
Public publicDataService |
Type : PublicDataService
|
reference of lerner service. |
Public userService |
Type : UserService
|
Public workspaceService |
Type : WorkSpaceService
|
import { ContentService, PublicDataService, UserService } from '@sunbird/core';
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { ConfigService, ServerResponse } from '@sunbird/shared';
import { map, catchError } from 'rxjs/operators';
import * as _ from 'lodash-es';
import { WorkSpaceService } from './../work-space/workspace.service';
/**
* Service to provides CRUD methods to make content api request by extending DataService.
*/
@Injectable()
export class EditorService {
/**
* base Url for content api
*/
baseUrl: string;
/**
* reference of config service.
*/
public configService: ConfigService;
/**
* reference of content service.
*/
public contentService: ContentService;
/**
* reference of lerner service.
*/
public publicDataService: PublicDataService;
/**
* constructor
* @param {ConfigService} config ConfigService reference
*/
constructor(configService: ConfigService, contentService: ContentService, publicDataService: PublicDataService,
public workspaceService: WorkSpaceService, public userService: UserService) {
this.configService = configService;
this.contentService = contentService;
this.baseUrl = this.configService.urlConFig.URLS.CONTENT_PREFIX;
this.publicDataService = publicDataService;
}
/**
* Create content Id for the editor
* @param req OBJECT
*/
create(req): Observable<ServerResponse> {
if (_.get(req, 'content.subject') && !_.isArray(_.get(req, 'content.subject'))) {
const subject = [];
subject.push(req.content.subject);
req.content.subject = subject;
}
if (_.get(req, 'content.medium') && !_.isArray(_.get(req, 'content.medium'))) {
const medium = [];
medium.push(req.content.medium);
req.content.medium = medium;
}
const option = {
url: this.configService.urlConFig.URLS.CONTENT.CREATE,
data: {
'request': req
}
};
return this.contentService.post(option);
}
/**
* get content details by id and query param
*/
getContent(contentId: string, option: any = { params: {} }): Observable<ServerResponse> {
const param = { fields: this.configService.editorConfig.DEFAULT_PARAMS_FIELDS };
const req = {
url: `${this.configService.urlConFig.URLS.CONTENT.GET}/${contentId}`,
param: { ...param, ...option.params }
};
return this.publicDataService.get(req).pipe(map((response: ServerResponse) => {
return response;
}));
}
getOwnershipType() {
const formServiceInputParams = {
formType: 'content',
subType: 'all',
formAction: 'ownership',
rootOrgId: this.userService.userProfile.rootOrgId
};
return this.workspaceService.getFormData(formServiceInputParams).pipe(
map(data => {
return _.get(data, 'result.form.data.fields[0].ownershipType') ?
data.result.form.data.fields[0].ownershipType : ['createdBy'];
}), catchError(error => {
return of(['createdBy']);
})
);
}
}