//const { CloudQuery, CloudObject } = require("../lib/ncloud"); // testCRUD() // //testQuery() // async function testQuery(){ // let query = new CloudQuery("Doctor") // // query.equalTo("gender","女") // query.greaterThanAndEqualTo("age",40) // query.lessThan("age",41) // let list = await query.find(); // console.log(list) // } // async function testCRUD(){ // // 基本的增删查改测试 // let query = new CloudQuery("Questions") // let QuestionsList = await query.find(); // console.log("QuestionsList count",QuestionsList?.length) // let newQuestions = new CloudObject("Questions") // newQuestions.set({"questionText":"S"}) // newQuestions = await newQuestions.save(newQuestions) // console.log("newQuestions",newQuestions) // //没有改 // //destory有问题 // await newQuestions.destory() // console.log("newQuestions 已删除",newQuestions) // } const { CloudQuery, CloudObject } = require("../lib/ncloud"); const { Questionslist, optionlist } = require("./data"); inportQuestionAndtion(); let DataMap = { option: {}, Questions: {} }; async function inportQuestionAndtion() { // 导入问题数据 let questionslist = Questionslist; //console.log("导入的问题列表:", questionslist); // 打印问题列表 for (let index = 0; index < questionslist.length; index++) { let questions = questionslist[index]; questions = await importObject("Questions", questions); } // 导入选项数据 let optionslist = optionlist; console.log("导入的选项列表:", optionslist); // 打印选项列表 for (let index = 0; index < optionslist.length; index++) { let options = optionslist[index]; options = await importObject("option", options); } } async function importObject(className, data) { // 查重 srcId 数据源列表中的 objectId 并非数据库生成的唯一 ID,因此需要有一个 srcId 字段进行记录,并查重 let query = new CloudQuery(className); let srcId = data.objectId; query.equalTo("srcId", srcId); let importObj = await query.first(); // console.log(importObj); // 可以在这里打印查重结果 // 导入 // 导入前批量处理 Pointer 类型数据,进行重定向 Object.keys(data)?.forEach(key => { let field = data[key]; let srcId = field?.objectId; if (srcId) { // 是数组字段 if (key == "question") { data[key] = DataMap?.["Questions"]?.[srcId]?.toPointer(); } } }); // 若未添加,则创建新对象并保存 if (!importObj?.id) { importObj = new CloudObject(className); } // 保存或更新数据 data.srcId = srcId; importObj.set(data); importObj = await importObj.save(); DataMap[className][srcId] = importObj; } // const { CloudQuery, CloudObject } = require("../lib/ncloud"); // const { Questionslist, optionlist } = require("./data"); // inportQuestionAndtion() // DataMap = { // option:{}, // Questions:{} // } // async function inportQuestionAndtion(){ // // 导入科室数据 // let questionslist = Questionslist // for (let index = 0; index < questionslist.length; index++) { // let questions = questionslist[index]; // questions = await importObject("Questions",questions) // } // // 导入医生数据 // let optionslist = optionlist // for (let index = 0; index < optionslist.length; index++) { // let options = optionslist[index]; // options = await importObject("option",options) // } // //console.log(DataMap["option"]) // } // async function importObject(className,data){ // // 查重 srcId 数据源列表中的objectId并非数据库生成的唯一ID,因此需要有一个srcId字段进行记录,并查重 // let query = new CloudQuery(className) // let srcId = data.objectId // query.equalTo("srcId",srcId) // let importObj = await query.first() // //console.log(importObj) // // 导入 // // 导入前批量处理Pointer类型数据,进行重定向 // Object.keys(data)?.forEach(key=>{ // let field = data[key] // let srcId = field?.objectId // if(srcId){ // 是数组字段 // if(key=="question"){ // data[key] = DataMap?.["Questions"]?.[srcId]?.toPointer(); // } // } // }) // // 若未添加,则创建新对象并保存 // if(!importObj?.id){ // importObj = new CloudObject(className) // } // // 保存或更新数据 // data.srcId = srcId; // importObj.set(data); // importObj = await importObj.save(); // DataMap[className][srcId] = importObj // } // async function main(){ // let questionsList = await getquestions(); // console.log("questionsList",questionsList); // console.log("questionsList count",questionsList?.length); // let newQuestions = { "questionText":"S" } // let newSavedId = await creatquestions(newQuestions) // newQuestions.objectId = newQuestions // console.log("newQuestions",newQuestions) // // let updateQuestions = { id:"NYoCWM9cNV" , "questionsText":"St" } // // let updateSavedId = await updatequestions(updateQuestions) // // updateQuestions.objectId = updateQuestions // // console.log("updateQuestions",updateQuestions) // await deleteQuestions(newSavedId) // console.log("newSavedId 已删除",newSavedId) // } // main() // async function deleteQuestions(id){ // let response = await fetch("http://dev.fmode.cn:1337/parse/classes/Questions/"+ id, { // "headers": { // "accept": "*/*", // "accept-language": "zh-CN,zh;q=0.9", // "x-parse-application-id": "dev" // }, // "referrer": "http://127.0.0.1:4040/apps/DevServer/api_console/rest", // "referrerPolicy": "no-referrer-when-downgrade", // "body": null, // "method": "DELETE", // "mode": "cors", // "credentials": "omit" // }); // return response?.json(); // } // async function updatequestions(id,questionsInfo){ // let body = JSON.stringify(questionsInfo) // let response = await fetch("http://dev.fmode.cn:1337/parse/classes/Questions/" + id, { // "headers": { // "accept": "*/*", // "accept-language": "zh-CN,zh;q=0.9", // "content-type": "text/plain;charset=UTF-8", // "x-parse-application-id": "dev" // }, // "referrer": "http://127.0.0.1:4040/apps/DevServer/api_console/rest", // "referrerPolicy": "no-referrer-when-downgrade", // "body": body, // "method": "PUT", // "mode": "cors", // "credentials": "omit" // }); // let result = await response?.json() // return result?.objectId // } // async function creatquestions(questionsInfo){ // let body = JSON.stringify(questionsInfo) // let response = await fetch("http://dev.fmode.cn:1337/parse/classes/Questions", { // "headers": { // "accept": "*/*", // "accept-language": "zh-CN,zh;q=0.9", // "content-type": "text/plain;charset=UTF-8", // "x-parse-application-id": "dev" // }, // "referrer": "http://127.0.0.1:4040/apps/DevServer/api_console/rest", // "referrerPolicy": "no-referrer-when-downgrade", // "body": body, // "method": "POST", // "mode": "cors", // "credentials": "omit" // }); // let result = await response?.json() // return result?.objectId // } // async function getquestions(){ // let response = await fetch("http://dev.fmode.cn:1337/parse/classes/Questions?", { // "headers": { // "accept": "*/*", // "accept-language": "zh-CN,zh;q=0.9", // "x-parse-application-id": "dev" // }, // "referrer": "http://127.0.0.1:4040/apps/DevServer/api_console/rest", // "referrerPolicy": "no-referrer-when-downgrade", // "body": null, // "method": "GET", // "mode": "cors", // "credentials": "omit" // }); // let json = await response?.json(); // return json?.results || [] // }