diff --git a/apollo/src/app.controller.ts b/apollo/src/app.controller.ts index cce879e..1b25005 100644 --- a/apollo/src/app.controller.ts +++ b/apollo/src/app.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get } from '@nestjs/common'; +import { Controller, Get, Query } from '@nestjs/common'; import { AppService } from './app.service'; @Controller() @@ -9,4 +9,32 @@ export class AppController { getHello(): string { return this.appService.getHello(); } + + @Get('questn/used') + async questNUsedHelix(@Query('address') address: string) { + return await this.appService.questNUsedHelix( + { + sender: address.toLowerCase(), + }, + 1 + ); + } + + @Get('questn/usedafter') + async questNUsedAfter(@Query('address') address: string) { + const where = { + sender: address.toLowerCase(), + startTime: { gt: 1729428516 }, + }; + return await this.appService.questNUsedHelix(where, 1); + } + + @Get('questn/afterand3times') + async questNUsedAfterAnd3Times(@Query('address') address: string) { + const where = { + sender: address.toLowerCase(), + startTime: { gt: 1729428516 }, + }; + return await this.appService.questNUsedHelix(where, 3); + } } diff --git a/apollo/src/app.service.ts b/apollo/src/app.service.ts index 927d7cc..7b7fed5 100644 --- a/apollo/src/app.service.ts +++ b/apollo/src/app.service.ts @@ -1,8 +1,32 @@ import { Injectable } from '@nestjs/common'; +import { HistoryRecord, Prisma, PrismaClient } from '@prisma/client'; @Injectable() -export class AppService { +export class AppService extends PrismaClient { getHello(): string { return 'Hello World!'; } + + async questNUsedHelix(where: Prisma.HistoryRecordWhereInput, times: number) { + const total = await this.historyRecord.count({ + where, + }); + if (total >= times) { + return { + data: { + result: true, + }, + }; + } else { + return { + error: { + code: 0, + message: `user sent count ${total}`, + }, + data: { + result: false, + }, + }; + } + } }