import { ApiCall } from "tsrpc";
import { ReqUpLoad, ResUpLoad } from "../../cross/protocols/clsl/PtlUpLoad";
import { Rank } from '../../public/rank/rank';

export default async function (call: ApiCall<ReqUpLoad, ResUpLoad>) {
    let { allStar, uid, ...ops } = call.req;

    let a = await G.mongodb.collection('clslCrossUser').findOneAndUpdate(
        { uid: uid },
        {
            $inc: { allStar: allStar || 0 },
            $set: ops
        },
        { upsert: true }
    );

    if (allStar != undefined && ops.info) {
        Rank.list.clslCross.addNew({
            player: a.value.info.player,
            valArr: [(await G.mongodb.collection('clslCrossUser').findOne({ uid: uid })).allStar]
        });
    }
}