Skip to content

Commit

Permalink
fix(core-api): businesses/bridgechains search by name (#3313)
Browse files Browse the repository at this point in the history
  • Loading branch information
dated authored and faustbrian committed Dec 5, 2019
1 parent ee1a131 commit 33256db
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 156 deletions.
24 changes: 7 additions & 17 deletions packages/core-api/src/handlers/blocks/schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Joi from "@hapi/joi";
import { blockId, orderBy, pagination } from "../shared/schemas";
import { address, blockId, orderBy, pagination, publicKey } from "../shared/schemas";

export const index: object = {
query: {
Expand Down Expand Up @@ -33,9 +33,7 @@ export const index: object = {
.integer()
.positive(),
payloadHash: Joi.string().hex(),
generatorPublicKey: Joi.string()
.hex()
.length(66),
generatorPublicKey: publicKey,
blockSignature: Joi.string().hex(),
transform: Joi.bool().default(true),
},
Expand Down Expand Up @@ -73,23 +71,17 @@ export const transactions: object = {
orderBy,
id: Joi.string()
.hex()
.length(66),
.length(64),
blockId,
type: Joi.number()
.integer()
.min(0),
version: Joi.number()
.integer()
.min(0),
senderPublicKey: Joi.string()
.hex()
.length(66),
senderId: Joi.string()
.alphanum()
.length(34),
recipientId: Joi.string()
.alphanum()
.length(34),
senderPublicKey: publicKey,
senderId: address,
recipientId: address,
timestamp: Joi.number()
.integer()
.min(0),
Expand Down Expand Up @@ -119,9 +111,7 @@ export const search: object = {
.min(0),
previousBlock: blockId,
payloadHash: Joi.string().hex(),
generatorPublicKey: Joi.string()
.hex()
.length(66),
generatorPublicKey: publicKey,
blockSignature: Joi.string().hex(),
timestamp: Joi.object().keys({
from: Joi.number()
Expand Down
15 changes: 5 additions & 10 deletions packages/core-api/src/handlers/bridgechains/schema.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import Joi from "@hapi/joi";
import { orderBy, pagination } from "../shared/schemas";
import { address, genericName, orderBy, pagination, publicKey } from "../shared/schemas";

export const index: object = {
query: {
...pagination,
...{
orderBy,
publicKey: Joi.string()
.hex()
.length(66),
publicKey,
isResigned: Joi.bool(),
},
},
Expand All @@ -30,16 +28,13 @@ export const search: object = {
},
},
payload: {
address,
publicKey,
bridgechainRepository: Joi.string().max(80),
publicKey: Joi.string()
.hex()
.length(66),
genesisHash: Joi.string()
.hex()
.length(64),
name: Joi.string()
.regex(/^[a-zA-Z0-9_-]+$/)
.max(40),
name: genericName,
seedNodes: Joi.array()
.unique()
.min(1)
Expand Down
15 changes: 5 additions & 10 deletions packages/core-api/src/handlers/businesses/schema.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import Joi from "@hapi/joi";
import { orderBy, pagination, walletId } from "../shared/schemas";
import { address, genericName, orderBy, pagination, publicKey, walletId } from "../shared/schemas";

export const index: object = {
query: {
...pagination,
...{
orderBy,
publicKey: Joi.string()
.hex()
.length(66),
publicKey,
isResigned: Joi.bool(),
},
},
Expand Down Expand Up @@ -41,12 +39,9 @@ export const search: object = {
},
},
payload: {
publicKey: Joi.string()
.hex()
.length(66),
name: Joi.string()
.regex(/^[a-zA-Z0-9_-]+$/)
.max(40),
address,
publicKey,
name: genericName,
website: Joi.string().max(80),
vat: Joi.string()
.alphanum()
Expand Down
57 changes: 15 additions & 42 deletions packages/core-api/src/handlers/delegates/schema.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { app } from "@arkecosystem/core-container";
import Joi from "@hapi/joi";
import { blockId, orderBy, pagination } from "../shared/schemas";
import { address, blockId, orderBy, pagination, publicKey, walletId } from "../shared/schemas";

const config = app.getConfig();

const schemaIdentifier = Joi.string()
.regex(/^[a-zA-Z0-9!@$&_.]+$/)
.min(1)
.max(66);

const schemaUsername = Joi.string()
.regex(/^[a-z0-9!@$&_.]+$/)
.min(1)
Expand Down Expand Up @@ -40,18 +35,10 @@ export const index: object = {
...{
orderBy,
type: Joi.string().valid("resigned", "never-forged"),
address: Joi.string()
.alphanum()
.length(34),
publicKey: Joi.string()
.hex()
.length(66),
secondPublicKey: Joi.string()
.hex()
.length(66),
vote: Joi.string()
.hex()
.length(66),
address,
publicKey,
secondPublicKey: publicKey,
vote: publicKey,
username: schemaUsername,
balance: Joi.number()
.integer()
Expand All @@ -68,7 +55,7 @@ export const index: object = {

export const show: object = {
params: {
id: schemaIdentifier,
id: walletId,
},
};

Expand All @@ -80,12 +67,8 @@ export const search: object = {
},
},
payload: {
address: Joi.string()
.alphanum()
.length(34),
publicKey: Joi.string()
.hex()
.length(66),
address,
publicKey,
username: schemaUsername,
usernames: Joi.array()
.unique()
Expand All @@ -103,7 +86,7 @@ export const search: object = {

export const blocks: object = {
params: {
id: schemaIdentifier,
id: walletId,
},
query: {
...pagination,
Expand Down Expand Up @@ -136,9 +119,7 @@ export const blocks: object = {
.integer()
.min(0),
payloadHash: Joi.string().hex(),
generatorPublicKey: Joi.string()
.hex()
.length(66),
generatorPublicKey: publicKey,
blockSignature: Joi.string().hex(),
transform: Joi.bool().default(true),
},
Expand All @@ -147,24 +128,16 @@ export const blocks: object = {

export const voters: object = {
params: {
id: schemaIdentifier,
id: walletId,
},
query: {
...pagination,
...{
orderBy,
address: Joi.string()
.alphanum()
.length(34),
publicKey: Joi.string()
.hex()
.length(66),
secondPublicKey: Joi.string()
.hex()
.length(66),
vote: Joi.string()
.hex()
.length(66),
address,
publicKey,
secondPublicKey: publicKey,
vote: publicKey,
username: schemaUsername,
balance: Joi.number()
.integer()
Expand Down
18 changes: 5 additions & 13 deletions packages/core-api/src/handlers/locks/schema.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { Enums } from "@arkecosystem/crypto";
import Joi from "@hapi/joi";
import { orderBy, pagination } from "../shared/schemas";
import { address, orderBy, pagination, publicKey } from "../shared/schemas";

export const index: object = {
query: {
...pagination,
...{
orderBy,
recipientId: Joi.string()
.alphanum()
.length(34),
senderPublicKey: Joi.string()
.hex()
.length(66),
recipientId: address,
senderPublicKey: publicKey,
lockId: Joi.string()
.hex()
.length(64),
Expand Down Expand Up @@ -47,12 +43,8 @@ export const search: object = {
},
},
payload: {
recipientId: Joi.string()
.alphanum()
.length(34),
senderPublicKey: Joi.string()
.hex()
.length(66),
recipientId: address,
senderPublicKey: publicKey,
lockId: Joi.string()
.hex()
.length(64),
Expand Down
5 changes: 5 additions & 0 deletions packages/core-api/src/handlers/shared/schemas/address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Joi from "@hapi/joi";

export const address = Joi.string()
.alphanum()
.length(34);
6 changes: 6 additions & 0 deletions packages/core-api/src/handlers/shared/schemas/generic-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Joi from "@hapi/joi";

export const genericName = Joi.string()
.regex(/^[a-zA-Z0-9]+(( - |[ ._-])[a-zA-Z0-9]+)*[.]?$/)
.min(1)
.max(40);
5 changes: 4 additions & 1 deletion packages/core-api/src/handlers/shared/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { address } from "./address";
import { blockId } from "./block-id";
import { genericName } from "./generic-name";
import { orderBy } from "./order-by";
import { pagination } from "./pagination";
import { publicKey } from "./public-key";
import { walletId } from "./wallet-id";

export { blockId, orderBy, pagination, walletId };
export { address, blockId, genericName, orderBy, pagination, publicKey, walletId };
5 changes: 5 additions & 0 deletions packages/core-api/src/handlers/shared/schemas/public-key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Joi from "@hapi/joi";

export const publicKey = Joi.string()
.hex()
.length(66);
22 changes: 5 additions & 17 deletions packages/core-api/src/handlers/transactions/schema.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { app } from "@arkecosystem/core-container";
import Joi from "@hapi/joi";
import { blockId, orderBy, pagination } from "../shared/schemas";

const address: object = Joi.string()
.alphanum()
.length(34);
import { address, blockId, orderBy, pagination, publicKey } from "../shared/schemas";

export const index: object = {
query: {
Expand All @@ -24,15 +20,9 @@ export const index: object = {
version: Joi.number()
.integer()
.positive(),
senderPublicKey: Joi.string()
.hex()
.length(66),
senderId: Joi.string()
.alphanum()
.length(34),
recipientId: Joi.string()
.alphanum()
.length(34),
senderPublicKey: publicKey,
senderId: address,
recipientId: address,
timestamp: Joi.number()
.integer()
.min(0),
Expand Down Expand Up @@ -114,9 +104,7 @@ export const search: object = {
version: Joi.number()
.integer()
.positive(),
senderPublicKey: Joi.string()
.hex()
.length(66),
senderPublicKey: publicKey,
senderId: address,
recipientId: address,
addresses: Joi.array()
Expand Down
14 changes: 4 additions & 10 deletions packages/core-api/src/handlers/votes/schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Joi from "@hapi/joi";
import { blockId, orderBy, pagination } from "../shared/schemas";
import { address, blockId, orderBy, pagination, publicKey } from "../shared/schemas";

export const index: object = {
query: {
Expand All @@ -13,15 +13,9 @@ export const index: object = {
version: Joi.number()
.integer()
.positive(),
senderPublicKey: Joi.string()
.hex()
.length(66),
senderId: Joi.string()
.alphanum()
.length(34),
recipientId: Joi.string()
.alphanum()
.length(34),
senderPublicKey: publicKey,
senderId: address,
recipientId: address,
timestamp: Joi.number()
.integer()
.min(0),
Expand Down
Loading

0 comments on commit 33256db

Please sign in to comment.