Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate core-api's repos into core-database & core-database-postgres #2107

Merged
merged 20 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c3ce67c
feature: introduce transactions and blocks business repos. The idea i…
paroxysm Feb 12, 2019
00ff55a
feature: implement the BlockBusinessRepo logic. And the search method…
paroxysm Feb 13, 2019
1ebd0c3
Merge remote-tracking branch 'arkecosystem/develop' into feat/refacto…
paroxysm Feb 13, 2019
86cd3b4
Merge remote-tracking branch 'arkecosystem/develop' into feat/refacto…
paroxysm Feb 16, 2019
e4b15d5
feature: implement TransactionsBusinessRepo, along with data-layer si…
paroxysm Feb 16, 2019
15346c6
feature: Use business repos on core-api v2 api
paroxysm Feb 16, 2019
43ad082
refactor: rename repo properties on the databaseService to use camel-…
paroxysm Feb 16, 2019
2d66fd5
refactor: added 'findLastByPublicKey' method that I forgot to add
paroxysm Feb 16, 2019
17e4ec4
fix: a failing test in core-api transactions.test.ts
paroxysm Feb 17, 2019
0dc9b68
fix: failing tests in core-database
paroxysm Feb 17, 2019
4667809
fix: findByTypeAndId
paroxysm Feb 17, 2019
5c2270a
Merge remote-tracking branch 'arkecosystem/develop' into feat/refacto…
paroxysm Feb 17, 2019
f2a5a3a
Merge remote-tracking branch 'arkecosystem/develop' into feat/refacto…
paroxysm Feb 17, 2019
46f7289
fix: compile-error caused by merge
paroxysm Feb 17, 2019
cb8f3d9
refactor: move 'getColumnSet', 'getSearchableFields' and 'getName' to…
paroxysm Feb 19, 2019
4a54279
Merge remote-tracking branch 'arkecosystem/develop' into feat/refacto…
paroxysm Feb 19, 2019
f3daf4a
refactor: inline some variables
paroxysm Feb 19, 2019
1b72e9e
fix: had mistakely removed support for 'senderId' parameter...
paroxysm Feb 19, 2019
a941c8d
Merge remote-tracking branch 'arkecosystem/develop' into feat/refacto…
paroxysm Feb 20, 2019
c16943a
chore: remove comment
paroxysm Feb 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feature: Use business repos on core-api v2 api
feature: mark unknown fields as OP_CUSTOM in SearchParameterConverter
fix: fixing some runtime-errors, default offset : 0,  limit 100, if none provided.
  • Loading branch information
paroxysm committed Feb 16, 2019
commit 15346c658e8560756565ab6cfe7db57587c3ea86
7 changes: 6 additions & 1 deletion packages/core-api/src/versions/2/blocks/methods.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { app } from "@arkecosystem/core-container";
import { Database } from "@arkecosystem/core-interfaces";
import Boom from "boom";
import { blocksRepository, transactionsRepository } from "../../../repositories";
import { ServerCache } from "../../../services";
import { paginate, respondWithResource, toPagination } from "../utils";

const databaseService = app.resolvePlugin<Database.IDatabaseService>("database");
const blocksRepository = databaseService.blocks;
const transactionsRepository = databaseService.transactions;

const index = async request => {
const blocks = await blocksRepository.findAll({
...request.query,
Expand Down
5 changes: 4 additions & 1 deletion packages/core-api/src/versions/2/transactions/methods.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { app } from "@arkecosystem/core-container";
import { Database } from "@arkecosystem/core-interfaces";
import Boom from "boom";
import { transactionsRepository } from "../../../repositories";
import { ServerCache } from "../../../services";
import { paginate, respondWithResource, toPagination } from "../utils";

const transactionsRepository = app.resolvePlugin<Database.IDatabaseService>("database").transactions;

const index = async request => {
const transactions = await transactionsRepository.findAll({
...request.query,
Expand Down
7 changes: 4 additions & 3 deletions packages/core-database-postgres/src/repositories/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ export class BlocksRepository extends Repository implements Database.IBlocksRepo
public async search(params: Database.SearchParameters) {
// TODO: we're selecting all the columns right now. Add support for choosing specific columns, when it proves useful.
const selectQuery = this.q.select().from(this.q);
const parameterList = params.parameters;
// Blocks repo atm, doesn't search using any custom parameters
const parameterList = params.parameters.filter(o => o.operator !== Database.SearchOperator.OP_CUSTOM);
if (parameterList.length) {
let first;
do {
Expand All @@ -128,9 +129,9 @@ export class BlocksRepository extends Repository implements Database.IBlocksRepo
} while (!first.operator && parameterList.length);

if (first) {
selectQuery.where(this.q[first.field][first.operator](first.value));
selectQuery.where(this.q[this.propToColumnName(first.field)][first.operator](first.value));
for (const param of parameterList) {
selectQuery.and(this.q[param.field][param.operator](param.value));
selectQuery.and(this.q[this.propToColumnName(param.field)][param.operator](param.value));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class TransactionsRepository extends Repository implements Database.ITran
const params = parameters.parameters;
if (params.length) {
// custom operators have a null 'operator' prop
const [customOps, simpleOps] = partition(params, param => !param.operator);
const [customOps, simpleOps] = partition(params, param => param.operator === Database.SearchOperator.OP_CUSTOM);

const [participants, rest] = partition(simpleOps, op => ["sender_public_key", "recipient_id"].includes(this.propToColumnName(op.field)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,23 @@ export class TransactionsBusinessRepository implements Database.ITransactionsBus
}

const searchParameters = new SearchParameterConverter(databaseService.connection.transactionsRepository.getModel()).convert(params);

if(!searchParameters.paginate) {
searchParameters.paginate = {
offset: 0,
limit: 100
};
}

searchParameters.orderBy.push({
field: "sequence",
direction: sequenceOrder
});

const result = await databaseService.connection.transactionsRepository.findAll(searchParameters);
return await this.mapBlocksToTransactions(result.rows);
result.rows = await this.mapBlocksToTransactions(result.rows);

return result;
}

public async findAllByBlock(blockId: any, parameters: any = {}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class SearchParameterConverter implements Database.ISearchParameterConver
private parsePaginate(searchParameters: Database.SearchParameters, paginate?: any) {
if (paginate) {
searchParameters.paginate = {
limit: Number.isInteger(paginate.limit) ? paginate.limit : null,
offset: Number.isInteger(paginate.offset) && +paginate.offset > 0 ? paginate.offset : null
limit: Number.isInteger(paginate.limit) ? paginate.limit : 100,
offset: Number.isInteger(paginate.offset) && +paginate.offset > 0 ? paginate.offset : 0
}
}
}
Expand All @@ -59,8 +59,11 @@ export class SearchParameterConverter implements Database.ISearchParameterConver
private parseSearchParameters(searchParameters: Database.SearchParameters, params: any) {
const searchableFields = this.databaseModel.getSearchableFields();
const mapByFieldName = searchableFields.reduce((p, c) => p[c.fieldName] = c, {});
// Only consider fields that this model supports.
Object.keys(params).filter(value => !["orderBy", "limit", "offset"].includes(value))
/*
orderBy, limit and offset are parsed earlier.
page, pagination are added automatically by hapi-pagination
*/
Object.keys(params).filter(value => !["orderBy", "limit", "offset", "page", "pagination"].includes(value))
.forEach(fieldName => {
const fieldDescriptor = mapByFieldName[fieldName] as Database.SearchableField;

Expand All @@ -71,7 +74,7 @@ export class SearchParameterConverter implements Database.ISearchParameterConver
if (!fieldDescriptor) {
searchParameters.parameters.push({
field: fieldName,
operator: null,
operator: Database.SearchOperator.OP_CUSTOM,
value: params[fieldName]
});
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface ITransactionsBusinessRepository {

findAll(params: any, sequenceOrder: "asc" | "desc"): Promise<any>;
findAll(params: any, sequenceOrder?: "asc" | "desc"): Promise<any>;
findAllLegacy(parameters: any): Promise<any>;
findWithVendorField(): Promise<any>;
findAllByWallet(wallet, parameters: any): Promise<any>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ export enum SearchOperator {
OP_IN = 'in',
OP_GTE = 'gte',
OP_LTE = 'lte',
OP_LIKE = 'like'
OP_LIKE = 'like',
// placeholder. For parameters that require custom(not a 1-to-1 field to column mapping) filtering logic on the data-layer repo
OP_CUSTOM = 'custom_operator'
}


Expand Down