const Parse = require("parse/node")
Parse.serverURL = "http://web2023.fmode.cn:9999/parse" // 配置服务器地址
Parse.initialize("dev") // 配置应用名称

let { StudentList } = require("./student-list")
main()
async function main() {
    // await registerAll()
    testCount()
}


async function updateSchoolClass() {
    let query = new Parse.Query("Profile");
    let list = await query.find();
    list.forEach(student => {
        student.set("schoolClass", { __type: "Pointer", className: "Department", objectId: "DGnxrAMgJD" })
        student.save();
    })
    // UPDATE "Profile" SET "schoolClass"='DGnxrAMgJD';
}
async function testCount() {
    let query = new Parse.Query("Profile");
    let count = await query.count();
    console.log(count);
}
async function registerAll() {
    StudentList.forEach(async student => {
        let user = new Parse.User();
        user.set("username", student.studentID);
        user.set("password", "666");
        user.set("name", student.name)
        try {
            user = await user.signUp();
        } catch (err) { }
        user = await Parse.User.logIn(student.studentID, "666");
        let Profile = Parse.Object.extend("Profile")
        let profile
        let query = new Parse.Query("Profile");
        query.equalTo("studentID", student.studentID);
        profile = await query.first();
        if (!profile?.id) profile = new Profile();
        console.log(profile)
        profile.set("user", user)
        profile.set("name", student.name)
        profile.set("studentID", student.studentID)
        profile.save();
    })
}