@ixily/activ
Version:
Alpha Capture Trade Idea Verification. Blockchain ownership proven trade ideas and strategies.
102 lines • 3.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.postQueryIdeasFilterAndPagination = exports.postQueryIdeasFilterIdeas = exports.postQueryIdeasPagination = exports.voidPaging = exports.getDataWithPaging = void 0;
const env_module_1 = require("../../modules/chunks/env.module");
const DEACTIVATED = env_module_1.EnvModule.get('deactivatePagination');
const getDataWithPaging = (params, bypassPaginationAndGetAll = false) => {
if (bypassPaginationAndGetAll) {
return {
data: params.data,
paging: {
page: 1,
limit: params.data.length,
},
total: params.data.length,
};
}
const array = params.data;
const total = array.length;
const { page, limit } = params.paging;
const startIndex = (page - 1) * limit;
const endIndex = page * limit;
let data;
if (DEACTIVATED) {
data = [...array];
}
else {
data = array.slice(startIndex, endIndex);
}
return {
data,
paging: {
page,
limit,
},
total,
};
};
exports.getDataWithPaging = getDataWithPaging;
const voidPaging = (page = 1, limit = 5) => {
const paging = {
data: [],
paging: {
page,
limit,
},
total: 0,
};
return paging;
};
exports.voidPaging = voidPaging;
const postQueryIdeasPagination = (data, page = 1, limit = 5, bypassPaginationAndGetAll = false) => {
return (0, exports.getDataWithPaging)({
data,
paging: {
page: page || 1,
limit: limit || 5,
},
}, bypassPaginationAndGetAll);
};
exports.postQueryIdeasPagination = postQueryIdeasPagination;
const postQueryIdeasFilterIdeas = (ideas, filterType = 'bypass', filterIncludeEncrypted = true) => {
if (filterType === 'bypass') {
return ideas;
}
const includesOpen = filterType.includes('open');
const includesAdjust = filterType.includes('adjust');
const includesClose = filterType.includes('close');
return ideas.filter((idea) => {
// private
if (typeof idea.idea === 'string') {
if (includesOpen || includesAdjust) {
return filterIncludeEncrypted;
}
else {
false;
}
}
else {
if (idea.idea.kind === 'open') {
return includesOpen;
}
else if (idea.idea.kind === 'adjust') {
return includesAdjust;
}
else if (idea.idea.kind === 'close') {
return includesClose;
}
else {
return false;
}
}
});
};
exports.postQueryIdeasFilterIdeas = postQueryIdeasFilterIdeas;
const postQueryIdeasFilterAndPagination = (data, page = 1, limit = 5, filterType = 'bypass', filterIncludeEncrypted = true, bypassPaginationAndGetAll = false) => {
const filtered = (0, exports.postQueryIdeasFilterIdeas)(data, filterType, filterIncludeEncrypted);
// console.log('filtered')
// console.log(filtered)
return (0, exports.postQueryIdeasPagination)(filtered, page, limit, bypassPaginationAndGetAll);
};
exports.postQueryIdeasFilterAndPagination = postQueryIdeasFilterAndPagination;
//# sourceMappingURL=paging.tool.js.map