@kontent-ai/delivery-sdk
Version:
Official Kontent.AI Delivery API SDK
87 lines • 2.89 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UsedInQuery = void 0;
const models_1 = require("../../models");
const base_listing_query_class_1 = require("../common/base-listing-query.class");
class UsedInQuery extends base_listing_query_class_1.BaseListingQuery {
constructor(config, queryService, setup) {
super(config, queryService);
this.config = config;
this.queryService = queryService;
this.setup = setup;
this._queryConfig = {};
}
/**
* Gets only item of given type
* @param type Codename of type to get
*/
type(type) {
this.parameters.push(new models_1.Filters.TypeFilter(type));
return this;
}
/**
* Gets items of given types (logical or)
* I.e. get items of either 'Actor' or 'Movie' type
* @param types Types to get
*/
types(types) {
this.parameters.push(new models_1.Filters.TypeFilter(types));
return this;
}
/**
* Gets only item from given collection
* @param collection Codename of collection to get
*/
collection(collection) {
this.parameters.push(new models_1.Filters.CollectionFilter(collection));
return this;
}
/**
* Gets items from given collections (logical or)
* I.e. get items of either 'default' or 'christmas-campaign' collection
* @param collections Collections to get
*/
collections(collections) {
this.parameters.push(new models_1.Filters.CollectionFilter(collections));
return this;
}
/**
* Language codename
* @param languageCodename Codename of the language
*/
languageParameter(languageCodename) {
this.parameters.push(new models_1.Parameters.LanguageParameter(languageCodename));
return this;
}
toPromise() {
var _a;
return this.queryService.getUsedIn(this.getUrl(), (_a = this._queryConfig) !== null && _a !== void 0 ? _a : {});
}
getUrl() {
const action = `/${this.setup.entity === 'asset' ? 'assets' : 'items'}/${this.setup.codename}/used-in`;
// add default language is necessary
this.processDefaultLanguageParameter();
//process client level archived item exclusion
this.processExcludeArchivedItemsParameter();
return super.resolveUrlInternal(action);
}
/**
* Used to configure query
* @param queryConfig Query configuration
*/
queryConfig(queryConfig) {
this._queryConfig = queryConfig;
return this;
}
map(json) {
return this.queryService.mappingService.usedInResponse(json);
}
allResponseFactory(items, responses) {
return {
items: items,
responses: responses
};
}
}
exports.UsedInQuery = UsedInQuery;
//# sourceMappingURL=used-in-query.class.js.map