import { TABLEENUM } from "./data/models/model";
import { find } from "./data/select";
import { updateOneData } from "./data/update";




export async function test() {
    let conf = ["photoUrl", "cardUrlJust", "cardUrlBack", "academicCERTUrl", "professionalCERTUrl", "uusinessLicenseUrl", "applicationForm"];
    for(let i = 0; i < conf.length; i++) {
        let name = conf[i];
        await updateHttps(name);
    }
}


export async function updateHttps(name) {
    // 查找并更新所有包含http的uusinessLicenseUrl
    let selectParam = {};
    selectParam[name] = {"$regex":"http"};
    let userInfo = await find(TABLEENUM.用户表, selectParam);

    for (let i = 0; i < userInfo.length; i++) {
        let info:any = userInfo[i];
        let str = info[name];
        let newUrl = str.replace(/http:\/\//g, 'https://');
        // 更新文档  
        if (newUrl) {
            let selectParam = {userId:info.userId};
            let formParam = {};
            formParam[name] = newUrl;
            await updateOneData(TABLEENUM.用户表, selectParam, formParam); 
        }
        
    }

    console.log();
}












