@fabric-es/fabric-cqrs
Version:
Hyperledger Fabric middleware for event sourcing and cqrs pattern
39 lines • 2.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.queryFullTextSearch = void 0;
const query_1 = require("../store/query");
const dispatcher_1 = require("./dispatcher");
const getPaginated_1 = require("./getPaginated");
const dispatchSearch = ({ logger, store }) => dispatcher_1.dispatcher((arg) => { var _a; return (((_a = arg === null || arg === void 0 ? void 0 : arg.args) === null || _a === void 0 ? void 0 : _a.entityName) ? query_1.action.eIdxSearch(arg) : query_1.action.cIdxSearch(arg)); }, {
name: `search`,
store,
slice: 'query',
SuccessAction: query_1.action.SEARCH_SUCCESS,
ErrorAction: query_1.action.SEARCH_ERROR,
logger,
});
const queryFullTextSearch = async ({ entityName, store, logger, query, param, cursor, pagesize, }) => {
const total = await dispatchSearch({ store, logger })({
entityName,
query,
param: { limit: { first: 0, num: 0 } },
countTotalOnly: true,
});
const _param = entityName
? Object.assign(Object.assign({ sortBy: { sort: 'DESC', field: 'ts' } }, param), { limit: { first: cursor, num: pagesize } }) : Object.assign(Object.assign({ sortBy: { sort: 'DESC', field: 'ts' } }, param), { limit: { first: cursor, num: pagesize } });
const paginated = await dispatchSearch({ store, logger })({
entityName,
query,
param: _param,
});
return (total === null || total === void 0 ? void 0 : total.status) !== 'OK'
? { status: 'ERROR', error: total === null || total === void 0 ? void 0 : total.error, message: total === null || total === void 0 ? void 0 : total.message }
: (paginated === null || paginated === void 0 ? void 0 : paginated.status) !== 'OK'
? { status: 'ERROR', error: paginated === null || paginated === void 0 ? void 0 : paginated.error, message: paginated === null || paginated === void 0 ? void 0 : paginated.message }
: {
status: 'OK',
data: getPaginated_1.getPaginated(paginated.data, total.data, cursor),
};
};
exports.queryFullTextSearch = queryFullTextSearch;
//# sourceMappingURL=queryFullTextSearch.js.map