add one api for fetch checkin list

This commit is contained in:
CounterFire2023 2024-01-05 19:16:37 +08:00
parent 4cd2b54a7d
commit 0af44deba0
2 changed files with 35 additions and 2 deletions

View File

@ -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

View File

@ -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, {