From 825b6ae505786d66a0cfcadef03ba4680548e379 Mon Sep 17 00:00:00 2001 From: Dmitryii Osipov Date: Thu, 11 Apr 2024 15:32:17 +0400 Subject: [PATCH] feat(voucher/indexer): search vouchers by id (#1527) --- idea/voucher-indexer/src/service.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/idea/voucher-indexer/src/service.ts b/idea/voucher-indexer/src/service.ts index 554cac5a4d..f2f88199c0 100644 --- a/idea/voucher-indexer/src/service.ts +++ b/idea/voucher-indexer/src/service.ts @@ -2,12 +2,8 @@ import { DataSource, Repository } from 'typeorm'; import { config } from './config'; import { Voucher } from './model'; -interface GetVouchersParams { - owner?: string; - spender?: string; +interface GetVouchersParams extends Partial> { declined?: boolean; - codeUploading?: boolean; - programs?: string[]; expired?: boolean; limit?: number; offset?: number; @@ -38,6 +34,7 @@ export class VoucherService { } public async getVouchers({ + id, owner, spender, declined, @@ -49,6 +46,14 @@ export class VoucherService { }: GetVouchersParams) { const qb = this._repo.createQueryBuilder('v'); + if (id) { + if (id.length === 66) { + qb.andWhere('v.id = :id', { id }); + } else { + qb.andWhere('v.id LIKE :id', { id: `%${id}%` }); + } + } + if (declined !== undefined) { qb.andWhere('v.isDeclined = :declined', { declined }); }