From 62a2180b2c0a29742c48e0476606ca5edba909a3 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Wed, 30 Oct 2024 20:52:29 +0800 Subject: [PATCH 1/4] 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, + }, + }; + } + } } From 7f452364a10b6b5951247f508faa034c5dc26cf5 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Wed, 6 Nov 2024 16:34:59 +0800 Subject: [PATCH 2/4] update api --- apollo/src/app.controller.ts | 28 +++++++++++----------------- apollo/src/app.service.ts | 2 +- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/apollo/src/app.controller.ts b/apollo/src/app.controller.ts index 1b25005b..a6165966 100644 --- a/apollo/src/app.controller.ts +++ b/apollo/src/app.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Query } from '@nestjs/common'; +import { Controller, Get, Query, Param } from '@nestjs/common'; import { AppService } from './app.service'; @Controller() @@ -10,9 +10,9 @@ export class AppController { return this.appService.getHello(); } - @Get('questn/used') - async questNUsedHelix(@Query('address') address: string) { - return await this.appService.questNUsedHelix( + @Get('quest/used') + async questUsedHelix(@Query('address') address: string) { + return await this.appService.questUsedHelix( { sender: address.toLowerCase(), }, @@ -20,21 +20,15 @@ export class AppController { ); } - @Get('questn/usedafter') - async questNUsedAfter(@Query('address') address: string) { + @Get('quest/after/:timestamp/times/:times') + async questUsedAfterAnd3Times( + @Param('timestamp') timestamp: number, + @Param('times') times: number, + @Query('address') address: string) { const where = { sender: address.toLowerCase(), - startTime: { gt: 1729428516 }, + startTime: { gt: timestamp }, }; - 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); + return await this.appService.questUsedHelix(where, times); } } diff --git a/apollo/src/app.service.ts b/apollo/src/app.service.ts index 7b7fed58..507d2aca 100644 --- a/apollo/src/app.service.ts +++ b/apollo/src/app.service.ts @@ -7,7 +7,7 @@ export class AppService extends PrismaClient { return 'Hello World!'; } - async questNUsedHelix(where: Prisma.HistoryRecordWhereInput, times: number) { + async questUsedHelix(where: Prisma.HistoryRecordWhereInput, times: number) { const total = await this.historyRecord.count({ where, }); From 78d359b2a901636e507640fa570c9e97753201a8 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Wed, 6 Nov 2024 17:11:56 +0800 Subject: [PATCH 3/4] bugfix: to number --- apollo/src/app.controller.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apollo/src/app.controller.ts b/apollo/src/app.controller.ts index a6165966..191db24c 100644 --- a/apollo/src/app.controller.ts +++ b/apollo/src/app.controller.ts @@ -22,13 +22,13 @@ export class AppController { @Get('quest/after/:timestamp/times/:times') async questUsedAfterAnd3Times( - @Param('timestamp') timestamp: number, - @Param('times') times: number, + @Param('timestamp') timestamp: string, + @Param('times') times: string, @Query('address') address: string) { const where = { sender: address.toLowerCase(), - startTime: { gt: timestamp }, + startTime: { gt: Number(timestamp) }, }; - return await this.appService.questUsedHelix(where, times); + return await this.appService.questUsedHelix(where, Number(times)); } } From 1f00dd0a0fc4ddd6ae40933c76c7ab6f33f1ba8e Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Fri, 8 Nov 2024 20:27:38 +0800 Subject: [PATCH 4/4] upgrade helixconf --- apollo/package.json | 2 +- apollo/yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apollo/package.json b/apollo/package.json index cd3834cd..5cb9ba13 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/yarn.lock b/apollo/yarn.lock index d4a4864d..2e5cf78f 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"