Skip to content

Commit

Permalink
feat(voucher/indexer): search vouchers by id (#1527)
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit authored Apr 11, 2024
1 parent 43f68fa commit 825b6ae
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions idea/voucher-indexer/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pick<Voucher, 'owner' | 'spender' | 'codeUploading' | 'id' | 'programs'>> {
declined?: boolean;
codeUploading?: boolean;
programs?: string[];
expired?: boolean;
limit?: number;
offset?: number;
Expand Down Expand Up @@ -38,6 +34,7 @@ export class VoucherService {
}

public async getVouchers({
id,
owner,
spender,
declined,
Expand All @@ -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 });
}
Expand Down

0 comments on commit 825b6ae

Please sign in to comment.