import { ApiCall } from "tsrpc";
import { ReqJxOpen, ResJxOpen } from "../../shared/protocols/gonghui/PtlJxOpen";
import { PublicShared } from '../../shared/public/public';

export default async function (call: ApiCall<ReqJxOpen, ResJxOpen>) {

    const data = await G.mongodb.collection('gonghuiUser').findOne({ uid: call.uid });
    const jx = data?.jx || { record: {}, refreshTime: -1 };

    if (PublicShared.getToDayZeroTime() > jx.refreshTime) {
        jx.record = {};
        jx.refreshTime = G.time;
        G.mongodb.collection('gonghuiUser').updateOne({ uid: call.uid }, { $set: { jx: jx } }, { upsert: true });
    }

    call.succ(jx);
}