Skip to content

Commit

Permalink
fix: add special characters support for searching (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirily11 authored May 11, 2022
1 parent da0ff8b commit ebe1717
Show file tree
Hide file tree
Showing 19 changed files with 1,430 additions and 926 deletions.
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
"packages/*"
],
"devDependencies": {
"@types/jest": "27.4.1",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"eslint": "^8.14.0",
"@types/jest": "27.5.0",
"@typescript-eslint/eslint-plugin": "^5.23.0",
"@typescript-eslint/parser": "^5.23.0",
"eslint": "^8.15.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"turbo": "^1.2.5",
"jest": "^28.0.2",
"release-it": "^14.14.2",
"typescript": "^4.6.3",
"@release-it/conventional-changelog": "^4.3.0",
"@release-it/bumper": "^3.0.1",
"turbo": "^1.2.8",
"jest": "^28.1.0",
"release-it": "^15.0.0",
"typescript": "^4.6.4",
"@release-it/conventional-changelog": "^5.0.0",
"@release-it/bumper": "^4.0.0",
"prettier": "^2.6.2",
"ts-jest": "^28.0.0-next.1"
"ts-jest": "^28.0.2"
},
"scripts": {
"build": "turbo run build",
Expand Down
14 changes: 7 additions & 7 deletions packages/etd-block-exporter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
"url": "https://github.com/etherdata-blockchain/packages.git"
},
"devDependencies": {
"@types/cli-progress": "^3.9.2",
"jest": "^28.0.2",
"@types/cli-progress": "^3.11.0",
"jest": "^28.1.0",
"ts-node": "^10.7.0",
"ts-node-dev": "^1.1.8",
"typescript": "^4.6.3",
"ts-jest": "^28.0.0-next.1"
"typescript": "^4.6.4",
"ts-jest": "^28.0.2"
},
"dependencies": {
"@types/jest": "^27.4.1",
"@types/node": "^17.0.29",
"@types/jest": "^27.5.0",
"@types/node": "^17.0.32",
"@types/yaml": "^1.9.7",
"cancelable-promise": "^4.3.0",
"cli-progress": "^3.10.0",
"cli-progress": "^3.11.0",
"etherdata-typescript": "^3.1.9",
"moment": "^2.29.3"
},
Expand Down
14 changes: 7 additions & 7 deletions packages/etd-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"types": "dist/index.d.ts",
"license": "MIT",
"dependencies": {
"@types/dockerode": "^3.3.8",
"@types/dockerode": "^3.3.9",
"@types/json-schema": "^7.0.11",
"bson": "^4.6.3",
"json-schema": "^0.4.0",
"typescript": "^4.6.3",
"typescript": "^4.6.4",
"web3": "^1.7.3",
"yaml": "^2.0.1",
"moment": "^2.29.3",
Expand All @@ -23,15 +23,15 @@
"access": "public"
},
"devDependencies": {
"@etherdata-blockchain/logger": "^3.4.0",
"@etherdata-blockchain/logger": "*",
"@types/glob": "^7.2.0",
"@types/jest": "^27.4.1",
"@types/jest": "^27.5.0",
"glob": "^8.0.1",
"jest": "^28.0.2",
"ts-jest": "^28.0.0-next.1",
"jest": "^28.1.0",
"ts-jest": "^28.0.2",
"ts-json-schema-generator": "1.0.0",
"ts-node": "^10.7.0",
"@types/node": "^17.0.31"
"@types/node": "^17.0.32"
},
"scripts": {
"build": "ts-node src/main.ts && tsc",
Expand Down
14 changes: 7 additions & 7 deletions packages/etd-docker-plan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
"dependencies": {
"@etherdata-blockchain/common": "*",
"@etherdata-blockchain/logger": "*",
"@types/cli-progress": "^3.9.2",
"@types/dockerode": "^3.3.8",
"@types/cli-progress": "^3.11.0",
"@types/dockerode": "^3.3.9",
"@types/jest-when": "^3.5.0",
"cli-progress": "^3.10.0",
"cli-progress": "^3.11.0",
"dockerode": "^3.3.1",
"typescript": "^4.6.3",
"typescript": "^4.6.4",
"yaml": "^2.0.1"
},
"devDependencies": {
"ts-jest": "^28.0.0-next.1",
"ts-jest": "^28.0.2",
"ts-node": "^10.7.0",
"jest": "^28.0.2",
"@types/node": "^17.0.31"
"jest": "^28.1.0",
"@types/node": "^17.0.32"
},
"scripts": {
"test": "jest --silent",
Expand Down
10 changes: 5 additions & 5 deletions packages/etd-history/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "MIT",
"dependencies": {
"moment": "^2.29.3",
"typescript": "^4.6.3"
"typescript": "^4.6.4"
},
"repository": {
"type": "git",
Expand All @@ -20,10 +20,10 @@
"test": "jest"
},
"devDependencies": {
"@types/jest": "^27.4.1",
"@types/node": "^17.0.31",
"jest": "^28.0.2",
"ts-jest": "^28.0.0-next.1"
"@types/jest": "^27.5.0",
"@types/node": "^17.0.32",
"jest": "^28.1.0",
"ts-jest": "^28.0.2"
},
"gitHead": "222c868ef7b50aa6a8fb216019733e971c213a89"
}
8 changes: 4 additions & 4 deletions packages/etd-ip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
},
"devDependencies": {
"@types/glob": "^7.2.0",
"@types/jest": "^27.4.1",
"@types/node": "^17.0.31",
"jest": "^28.0.2",
"ts-jest": "^28.0.0-next.1",
"@types/jest": "^27.5.0",
"@types/node": "^17.0.32",
"jest": "^28.1.0",
"ts-jest": "^28.0.2",
"ts-node": "^10.7.0",
"typescript": "^4.6.4"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/etd-logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "MIT",
"dependencies": {
"chalk": "^5.0.1",
"typescript": "^4.6.3",
"typescript": "^4.6.4",
"moment": "^2.29.3"
},
"repository": {
Expand All @@ -21,9 +21,9 @@
"test": "jest --passWithNoTests"
},
"devDependencies": {
"@types/jest": "^27.4.1",
"jest": "^28.0.2",
"ts-jest": "^28.0.0-next.1"
"@types/jest": "^27.5.0",
"jest": "^28.1.0",
"ts-jest": "^28.0.2"
},
"gitHead": "222c868ef7b50aa6a8fb216019733e971c213a89"
}
6 changes: 3 additions & 3 deletions packages/etd-next-js-handlers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"@etherdata-blockchain/services": "*",
"http-method-enum": "^1.0.0",
"http-status-codes": "^2.2.0",
"next": "^12.1.5",
"typescript": "^4.6.3",
"next": "^12.1.6",
"typescript": "^4.6.4",
"react-dom": "^18.1.0",
"react": "^18.1.0",
"jsonwebtoken": "^8.5.1",
Expand All @@ -21,7 +21,7 @@
"url": "https://github.com/etherdata-blockchain/packages.git"
},
"devDependencies": {
"@etherdata-blockchain/storage-model": "^3.4.0",
"@etherdata-blockchain/storage-model": "*",
"node-mocks-http": "^1.11.0"
},
"publishConfig": {
Expand Down
16 changes: 8 additions & 8 deletions packages/etd-remote-action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@
},
"devDependencies": {
"@etherdata-blockchain/etd-schema-generator": "*",
"jest": "^28.0.2",
"ts-jest": "^28.0.0-next.1",
"jest": "^28.1.0",
"ts-jest": "^28.0.2",
"ts-node": "^10.7.0",
"ts-node-dev": "^1.1.8",
"typescript": "^4.6.3"
"typescript": "^4.6.4"
},
"repository": {
"type": "git",
"url": "https://github.com/etherdata-blockchain/packages.git"
},
"dependencies": {
"@etherdata-blockchain/logger": "^3.4.0",
"@types/cli-progress": "^3.9.2",
"@types/jest": "^27.4.1",
"@types/node": "^17.0.29",
"@etherdata-blockchain/logger": "*",
"@types/cli-progress": "^3.11.0",
"@types/jest": "^27.5.0",
"@types/node": "^17.0.32",
"@types/yaml": "^1.9.7",
"cancelable-promise": "^4.3.0",
"chalk": "^5.0.1",
"cli-progress": "^3.10.0",
"cli-progress": "^3.11.0",
"moment": "^2.29.3",
"node-ssh": "12.0.4",
"yaml": "^2.0.1"
Expand Down
8 changes: 4 additions & 4 deletions packages/etd-schema-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
},
"devDependencies": {
"@etherdata-blockchain/logger": "*",
"jest": "^28.0.2",
"ts-jest": "^28.0.0-next.1",
"jest": "^28.1.0",
"ts-jest": "^28.0.2",
"ts-json-schema-generator": "^1.0.0",
"ts-node": "^10.7.0",
"ts-node-dev": "^1.1.8",
"typescript": "^4.6.3",
"@types/node": "^17.0.31"
"typescript": "^4.6.4",
"@types/node": "^17.0.32"
},
"scripts": {
"test": "jest",
Expand Down
10 changes: 5 additions & 5 deletions packages/etd-services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"moment": "^2.29.3",
"query-string": "^7.1.1",
"socket.io": "^4.5.0",
"typescript": "^4.6.3"
"typescript": "^4.6.4"
},
"repository": {
"type": "git",
Expand All @@ -28,12 +28,12 @@
"access": "public"
},
"devDependencies": {
"@types/jest": "^27.4.1",
"jest": "^28.0.2",
"@types/jest": "^27.5.0",
"jest": "^28.1.0",
"mongodb-memory-server": "^8.5.2",
"socket.io-client": "^4.5.0",
"ts-jest": "^28.0.1",
"mongoose": "^6.3.2"
"ts-jest": "^28.0.2",
"mongoose": "^6.3.3"
},
"gitHead": "222c868ef7b50aa6a8fb216019733e971c213a89"
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,15 @@ export class StorageManagementService extends BaseMongoDBService<schema.IStorage
},
];

const replacedKeyword = key.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");

const query = this.model
.aggregate(pipelines)
.limit(configs.Configurations.numberPerPage);

const query2 = this.model.find({ qr_code: { $regex: ".*" + key + ".*" } });
const query2 = this.model.find({
qr_code: { $regex: ".*" + replacedKeyword + ".*" },
});

const [result1, result2] = await Promise.all([query.exec(), query2.exec()]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,12 @@ export class StorageManagementOwnerService extends BaseMongoDBService<schema.ISt
return [];
}

const replacedKeyword = keyword.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");

const query = this.model.find({
$or: [
{ user_id: { $regex: ".*" + keyword + ".*" } },
{ user_name: { $regex: ".*" + keyword + ".*" } },
{ user_id: { $regex: ".*" + replacedKeyword + ".*" } },
{ user_name: { $regex: ".*" + replacedKeyword + ".*" } },
],
});

Expand Down
29 changes: 29 additions & 0 deletions packages/etd-services/src/tests/mongodb/storage/owner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,33 @@ describe("Given a storage owner", () => {
result = await service.search(mockData.MockUser.user_id);
expect(result).toHaveLength(2);
});

test("When calling search with some symbols", async () => {
await schema.StorageOwnerModel.create({
user_name: "mock_user_1",
user_id: "+852-12345",
});
await schema.StorageOwnerModel.create({
user_name: "mock_user_2",
user_id: "+852-67890",
});

await schema.StorageOwnerModel.create({
user_name: "某人姓名",
user_id: "+852-12456",
});

const service = new StorageManagementOwnerService();
let result = await service.search("+852-12");
expect(result).toHaveLength(2);

result = await service.search("某人");
expect(result).toHaveLength(1);

result = await service.search("");
expect(result).toHaveLength(0);

result = await service.search("+852-67890");
expect(result).toHaveLength(1);
});
});
10 changes: 5 additions & 5 deletions packages/etd-storage-model/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"license": "MIT",
"dependencies": {
"@etherdata-blockchain/common": "*",
"mongoose": "^6.3.2",
"typescript": "4.6.3",
"mongoose": "^6.3.3",
"typescript": "4.6.4",
"web3-eth": "1.7.3",
"moment": "^2.29.3"
},
Expand All @@ -16,9 +16,9 @@
"url": "https://github.com/etherdata-blockchain/packages.git"
},
"devDependencies": {
"jest": "^28.0.2",
"mongodb-memory-server": "^8.5.1",
"ts-jest": "^28.0.0-next.1"
"jest": "^28.1.0",
"mongodb-memory-server": "^8.5.2",
"ts-jest": "^28.0.2"
},
"publishConfig": {
"access": "public"
Expand Down
Loading

0 comments on commit ebe1717

Please sign in to comment.