import { ApiCall } from "tsrpc";
import { ReqOpen, ResOpen } from "../../../shared/protocols/event/136Gift/PtlOpen";
import { PublicShared } from '../../../shared/public/public';

export default async function (call: ApiCall<ReqOpen, ResOpen>) {

    let db = await G.mongodb.cEvent('136Gift').findOne({ uid: call.uid, type: '136Gift' });

    if (!db || db.refreshTime < PublicShared.getToDayZeroTime()) {
        G.mongodb.cEvent('136Gift').updateOne(
            { uid: call.uid, type: '136Gift' },
            { $set: { recIndex: [], refreshTime: G.time } },
            { upsert: true }
        );
        if (db?.recIndex) {
            db.recIndex = [];
        }
    }

    call.succ({
        recIndex: db?.recIndex || []
    });
}