From 0af44deba0c25ea470adab749f5cd464f2f1fe3b Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Fri, 5 Jan 2024 19:16:37 +0800 Subject: [PATCH] add one api for fetch checkin list --- src/controllers/task.controllers.ts | 25 +++++++++++++++++++++++++ src/models/CheckIn.ts | 12 ++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/controllers/task.controllers.ts diff --git a/src/controllers/task.controllers.ts b/src/controllers/task.controllers.ts new file mode 100644 index 0000000..9d432c3 --- /dev/null +++ b/src/controllers/task.controllers.ts @@ -0,0 +1,25 @@ +import { ZError } from 'common/ZError' +import BaseController from 'common/base.controller' +import { role, router } from 'decorators/router' +import { ChainTask, ChainTaskClass } from 'models/ChainTask' +import { CheckIn } from 'models/CheckIn' +import { RequestTask } from 'models/RequestTask' + + +class TaskController extends BaseController { + @role('anon') + @router('post /task/check_in') + async checkDailyCheckIn(req, res) { + let { address, days } = req.params + if (!address || !days) { + throw new ZError(10, 'address is required') + } + let records = await CheckIn.find({ from: address, dateTag: {$in: days}}) + let result = [] + for (let record of records) { + result.push(record.toJson()) + } + return result + } +} +export default TaskController diff --git a/src/models/CheckIn.ts b/src/models/CheckIn.ts index 25b843c..30690f3 100644 --- a/src/models/CheckIn.ts +++ b/src/models/CheckIn.ts @@ -3,8 +3,8 @@ import { dbconn } from 'decorators/dbconn' import { BaseModule } from './Base' @dbconn() -@index({ address: 1 }, { unique: false }) -@index({ transactionHash: 1, from: 1, to: 1 }, { unique: true }) +@index({ from: 1 }, { unique: false }) +@index({ from: 1, dateTag: 1}, { unique: true }) @modelOptions({ schemaOptions: { collection: 'check_in_event', timestamps: true }, }) @@ -31,6 +31,14 @@ export class CheckInClass extends BaseModule { public static async saveEvent(event: any) { return CheckIn.insertOrUpdate({ hash: event.hash }, event) } + + public toJson() { + return { + address: this.from, + day: this.dateTag, + time: this.blockTime, + } + } } export const CheckIn = getModelForClass(CheckInClass, {