// const { CloudQuery, CloudObject } = require("../ncloud"); // const { UserList, PlanList, CoachList } = require("./data"); // inportDapartAndDoctor() // DataMap = { // fitUser: {}, // fitPlan: {}, // Coach: {} // } // async function inportDapartAndDoctor() { // // 导入科室数据 // let departList = CoachList // for (let index = 0; index < departList.length; index++) { // let depart = departList[index]; // depart = await importObject("Coach", depart) // } // // 导入医生数据 // // let doctorList = PlanList // // for (let index = 0; index < doctorList.length; index++) { // // let doctor = doctorList[index]; // // doctor = await importObject("fitPlan", doctor) // // } // // console.log(DataMap["Doctor"]) // } // 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 == "depart") { // data[key] = DataMap?.["Department"]?.[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("../ncloud"); // testCRUD() // testQuery() // async function testQuery(){ // let query= new CloudQuery("Post") // // 把用户填写的内容传入对象 // query.equalTo("content","ccc") // // 对象和数据库内容对比 // let list=await query.find() // console.log(list); // } // async function testCRUD(){ // // 增删查改测试 // let query=new CloudQuery("Post") // let UserList=await query.find(); // console.log(UserList?.length); // let newUser=new CloudObject("Post") // // 把数据传入对象的data // newUser.set({"content":"8888"}); // // 数据保存到数据库 // newUser= await newUser.save() // console.log(newUser); // // 数据库删除操作 // await newUser.destroy() // console.log("shanchu",newUser); // } // // 得到数据 // async function getUser(){ // let response=await fetch("http://dev.fmode.cn:1337/parse/classes/Post?", { // "headers": { // "if-none-match": "W/\"ab-2gNtNZqRYX93fdbIaSj6z5h571k\"", // "x-parse-application-id": "dev" // }, // "body": null, // "method": "GET", // "mode": "cors", // "credentials": "omit" // }); // let json=await response?.json(); // // console.log(json); // return json?.results || [] // } // async function createUser(userInfo){ // let body=JSON.stringify(userInfo) // let response=await fetch("http://dev.fmode.cn:1337/parse/classes/Post", { // "headers": { // "content-type": "application/json;charset=UTF-8", // "x-parse-application-id": "dev" // }, // "body": body, // "method": "POST", // "mode": "cors", // "credentials": "omit" // }); // let json= await response?.json(); // return json?.objectId // } // async function updateUser(id,userInfo) { // let body=JSON.stringify(userInfo) // let response=await fetch("http://dev.fmode.cn:1337/parse/classes/Post/"+id, { // "headers": { // "content-type": "application/json;charset=UTF-8", // "x-parse-application-id": "dev" // }, // "body": body, // "method": "PUT", // "mode": "cors", // "credentials": "omit" // }); // return await response?.json(); // } // async function deleteUser(id){ // let response=await fetch("http://dev.fmode.cn:1337/parse/classes/Post/"+id, { // "headers": { // "x-parse-application-id": "dev" // }, // "body": null, // "method": "DELETE", // "mode": "cors", // "credentials": "omit" // }); // return await response?.json(); // } const { CloudQuery, CloudObject } = require("../ncloud"); const { User_exer, Post, Like, Comment } = require("./data"); importFourList() async function importFourList(){ // 导入用户数据 let user=User_exer for (let index = 0; index < user.length; index++) { let u = user[index]; u=await importObject("User_exer",u) } // 导入动态数据 let post= Post for (let index = 0; index < post.length; index++) { let p = post[index]; p=await importObject("Post",p) } console.log(map); // 导入点赞数据 // let like=new Like // // 导入评论数据 // let comment=new Comment } map={ User_exer:{}, Post:{}, Like:{}, Comment:{} } async function importObject(ClassName,data) { let query=new CloudQuery(ClassName) // 对象添加了一个属性srcId let srcId=data.objectId query.equalTo("srcId",srcId) let importObj=await query.first() // 导入 // 若未添加,创建新对象并保存 Object.keys(data)?.forEach(key=>{ let field=data[key] let srcId=field?.objectId if(srcId) { if(key=="user_id") { data[key]=map["User_exer"]?.[srcId]?.toPointer(); } } }) if(!importObj?.id) { importObj=new CloudObject(ClassName) } // 保存或更新数据 data.srcId=srcId; importObj.set(data) importObj=await importObj.save() map[ClassName][srcId]=importObj }