Skip to content

Commit 1174563

Browse files
committed
Add token search query
1 parent f30f366 commit 1174563

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

src/app.service.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,15 @@ export class AppService {
7373
this.logger.log(`Set initial blockNumber=${blockNumber}`)
7474
}
7575

76-
await this.userService.addNewUser({ address: '0x98f0c3d42b8dafb1f73d8f105344c6a4434a0109' })
77-
await this.userService.addNewUser({ address: '0x2AB4eF5E937CcC03a9c0eAfC7C00836774B149E0' })
76+
const bootstrapUsers = [
77+
'0x98f0c3d42b8dafb1f73d8f105344c6a4434a0109',
78+
'0x2AB4eF5E937CcC03a9c0eAfC7C00836774B149E0'
79+
]
80+
for(const userAddress of bootstrapUsers) {
81+
if(!(await this.userService.getUserByAddress(userAddress))) {
82+
await this.userService.addNewUser({ address: userAddress })
83+
}
84+
}
7885
} catch (e) {
7986
this.logger.error(`Failed to bootstrap, exit`, e)
8087
process.exit(1)
@@ -246,14 +253,25 @@ export class AppService {
246253
}
247254

248255
async getTokens(dto: GetTokensDto){
249-
return await this.dataSource.manager.find(Token, {
250-
where: {},
251-
take: dto.limit,
252-
skip: dto.offset,
253-
order: {
254-
createdAt: 'desc'
255-
}
256-
})
256+
const { search, offset, limit } = dto
257+
const query = this.dataSource.getRepository(Token)
258+
.createQueryBuilder('token')
259+
.leftJoinAndSelect('token.user', 'user')
260+
.offset(offset)
261+
.limit(limit)
262+
.orderBy({
263+
timestamp: 'DESC'
264+
})
265+
266+
if(search) {
267+
query.where('token.name = :name', { name: search })
268+
.orWhere('token.address = :address', { address: search })
269+
.orWhere('token.symbol = :symbol', { symbol: search })
270+
.orWhere('token.id = :id', { id: search })
271+
.orWhere('token.txnHash = :txnHash', { txnHash: search })
272+
}
273+
274+
return await query.getMany()
257275
}
258276

259277
async getTrades(dto: GetTradesDto){

0 commit comments

Comments
 (0)