diff --git a/apollo/package.json b/apollo/package.json index cd3834c..5cb9ba1 100644 --- a/apollo/package.json +++ b/apollo/package.json @@ -29,7 +29,7 @@ "generate:schema": "ts-node generate-typings.ts && cp src/graphql.schema.ts src/graphql.ts" }, "dependencies": { - "@helixbridge/helixconf": "1.2.0-beta", + "@helixbridge/helixconf": "1.2.0", "@nestjs/apollo": "^10.0.9", "@nestjs/common": "^8.4.6", "@nestjs/config": "^2.1.0", diff --git a/apollo/src/app.controller.ts b/apollo/src/app.controller.ts index cce879e..191db24 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, Param } from '@nestjs/common'; import { AppService } from './app.service'; @Controller() @@ -9,4 +9,26 @@ export class AppController { getHello(): string { return this.appService.getHello(); } + + @Get('quest/used') + async questUsedHelix(@Query('address') address: string) { + return await this.appService.questUsedHelix( + { + sender: address.toLowerCase(), + }, + 1 + ); + } + + @Get('quest/after/:timestamp/times/:times') + async questUsedAfterAnd3Times( + @Param('timestamp') timestamp: string, + @Param('times') times: string, + @Query('address') address: string) { + const where = { + sender: address.toLowerCase(), + startTime: { gt: Number(timestamp) }, + }; + return await this.appService.questUsedHelix(where, Number(times)); + } } diff --git a/apollo/src/app.service.ts b/apollo/src/app.service.ts index 927d7cc..507d2ac 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 questUsedHelix(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, + }, + }; + } + } } diff --git a/apollo/yarn.lock b/apollo/yarn.lock index d4a4864..2e5cf78 100644 --- a/apollo/yarn.lock +++ b/apollo/yarn.lock @@ -742,10 +742,10 @@ dependencies: tslib "^2.4.0" -"@helixbridge/helixconf@1.2.0-beta": - version "1.2.0-beta" - resolved "https://registry.yarnpkg.com/@helixbridge/helixconf/-/helixconf-1.2.0-beta.tgz#4f46ac1c33af3717710ac3ffe7f036f6ddf244e9" - integrity sha512-YuFOhX33quFUwOvduSzo01ul7SWus2OicDTulJLbPdg000Qs37s0WJ80n1fK8FSDgvBMToC8oaxnimwTl6fT9Q== +"@helixbridge/helixconf@1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@helixbridge/helixconf/-/helixconf-1.2.0.tgz#56fa247ed3286303ae6f8efa65932d5df901595a" + integrity sha512-vZwelfwuDluCKP19xHqatMEPZmCnKpkvWWJBdRTClYYFCva79qpjzKM7SxOcFhOqygbobwFRgNVV4JLDJVg8Qg== "@istanbuljs/load-nyc-config@^1.0.0": version "1.1.0"