From 62a2180b2c0a29742c48e0476606ca5edba909a3 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Wed, 30 Oct 2024 20:52:29 +0800 Subject: [PATCH] adapter questN --- apollo/src/app.controller.ts | 30 +++++++++++++++++++++++++++++- apollo/src/app.service.ts | 26 +++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/apollo/src/app.controller.ts b/apollo/src/app.controller.ts index cce879ee..1b25005b 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 927d7cca..7b7fed58 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, + }, + }; + } + } }