pressit-api-interface
v0.1.10
Published
Pressit common types and query helpers
Readme
pressit-api-interface
Usage exemple with Angular
src/services/common.service.ts
import { HttpClient, HttpParams } from '@angular/common/http';
import {
TagsTagsUrlsQuery,
TagTagUrl,
TagsTagsUrlsArgs,
TagVisibility,
LabelTree,
Tag,
} from 'pressit-api-interface';
@Injectable({
providedIn: 'root',
})
export class CommonService {
constructor(private http: HttpClient) {}
getNodes(args?: TagsTagsUrlsArgs): Observable<ApiGetResponse<TagTagUrl>> {
let { tagTagUrlId } = args;
if (tagTagUrlId) {
const tagTagUrlIds = (Array.isArray(tagTagUrlId)
? tagTagUrlId
: [tagTagUrlId]
).filter((e) => e);
if (tagTagUrlIds.length === 1) {
delete args.tagTagUrlId;
tagTagUrlId = tagTagUrlIds[0];
} else {
tagTagUrlId = null;
}
}
return this.http.get<ApiGetResponse<TagTagUrl>>(
`${environment.apiUrl}/tags-tags-urls/${
(tagTagUrlId ? tagTagUrlId : '') +
'?' +
this.tagsTagsUrlsQuery.httpParams(args)
}`
);
}
getPosts(
parentTagId?: number | null,
limit?: number | null,
skip?: number | null,
excludeTagId?: number | number[] | null,
minVisibility?: TagVisibility | null,
args?: TagsTagsUrlsArgs
): Observable<ApiGetResponse<TagTagUrl>> {
const defaultArgs: TagsTagsUrlsArgs = {
parentTagId,
limit,
skip,
excludeTagId,
minVisibility,
tagType: 'post',
sort: { by: 'publishedAt' },
};
args = Object.assign({}, defaultArgs, args);
return this.getNodes(args);
}
}Updating
- change version in package.json
- build before commit
# update package-lock.json
$ npm i
# build library in ./dist
$ npm run build
$ git add .
$ git commit
# one liner
$ npm i && npm run build && git add . && git committype definitions
'pressit-api-interface'
- Tag
- TagVisibility
- TagStatus
- TagTag
- TagTagUrl
- LabelTree
- Medium
- Option
- OptionValue
- TagsTagsUrlsArgs
- Redirect
'pressit-api-interface/editorjs-json-to-html'
- EditorJsBlock
- EditorJsJSON
Helpers
TagsTagsUrlsQueryParams
import pressitApiInterface, {
TagTagUrl,
TagsTagsUrlsArgs,
TagVisibility,
LabelTree,
Tag,
tagsTagsUrlsQueryParams,
} from 'pressit-api-interface';
const tagsTagsUrlsQuery = new pressitApiInterface.TagsTagsUrlsQuery(
'100000.100001'
);
const httpParams = tagsTagsUrlsQuery.httpParams({ args... })
// httpParam.toString()
// tagIdTree[$regexp]=100000.100001.*&args...tagsTagsUrlsQueryParams
editorjsJsonToHtml
import editorjsJsonToHtml, {
EditorJsJSON,
} from 'pressit-api-interface/editorjs-json-to-html';
// editorjsJsonToHtml(<EditorJsJSON>): string
this.content = editorjsJsonToHtml(<EditorJsJSON>this.tag.tag.contentJson);