Skip to content

Commit

Permalink
v0.2.0 add search for name or network id
Browse files Browse the repository at this point in the history
  • Loading branch information
mingder78 committed Dec 16, 2023
1 parent e41fddf commit 4070097
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@muzamint/erica-items-db",
"version": "0.1.2",
"version": "0.2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"description": "",
Expand Down Expand Up @@ -33,6 +33,7 @@
"@elysiajs/cors": "^0.7.2",
"@elysiajs/swagger": "^0.7.4",
"elysia": "^0.7.30",
"lodash": "^4.17.21",
"viem": "^1.19.13"
}
}
34 changes: 29 additions & 5 deletions src/items/service/items.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// src/items/items.service.ts

import * as _ from "lodash";
console.log(_.padStart("Hello TypeScript!", 20, " "))
// data model interfaces

import { BaseItem, Item } from "../interface/item";
Expand Down Expand Up @@ -55,9 +56,32 @@ export const remove = async (id: number): Promise<null | void> => {
delete items[id];
};

export const search = async (word: string, testnet: string | undefined): Promise<Item[]> => {
console.log(word)
console.log(testnet)
return [];
export const search = async (word: string, testnet: string | undefined): Promise<Items> => {
/**
* query: query string to match with
* dataArray: data array variable, array or opject to search it
**/
function search(query: string,dataArray: Items){
// search code go here
//console.log(query);
var matched: Item[] = [];
//init null values
if(!query)query='';
const data = Object.entries(dataArray)
data.forEach(function(obj: any,index){

if(!obj.hasOwnProperty('1') || !obj['1']) return;
if((obj['1']['meta']['id'].toString().indexOf(query) !== -1)
|| (obj['1']['meta']['name'].toString().indexOf(query) !== -1))
{
matched.push(obj['1']);
}

});
return matched ;
}

const i: Items = search(word, items)
return i;
};

0 comments on commit 4070097

Please sign in to comment.