"use strict";(()=>{vare={};e.id=4105,e.ids=[4105],e.modules={39908:e=>{e.exports=require("@moduletrace/datasquirel/dist/users/user-auth")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},9973:e=>{e.exports=require("serverless-mysql")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){returnfunctione(r,s){returnsinr?r[s]:"then"inr&&"function"==typeofr.then?r.then(r=>e(r,s)):"function"==typeofr&&"default"===s?r:void0}}})},55096:(e,r,s)=>{s.r(r),s.d(r,{config:()=>A,default:()=>f,routeModule:()=>v});vart={};s.r(t),s.d(t,{default:()=>S});vara=s(89947),n=s(2706),o=s(96762),i=s(29021),c=s.n(i),u=s(69842),d=s(67619),l=s(48786),_=s(33873),D=s.n(_),p=s(76856);asyncfunctionS(e,r){if("POST"!==e.method)returnr.json({user:null,msg:"Registration Failed!"});lets=await(0,u.A)(e,r,!0);if(!s)returnr.json({success:!1,msg:"Unauthorized"});lett=e.body.schema,a=e.body.dbId;try{lete=await(0,l.A)("SELECT * FROM user_databases WHERE user_id = ? AND id = ?",[s.id,a]);if(!e?.[0])throwError("Invalid Database");letn=e[0],o=D().resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.id}/main.json`),i=JSON.parse(c().readFileSync(o,"utf-8")),u=i.find(e=>e.dbFullName==n.db_full_name);if(!u)throwError("This Database doesn't exist");if(u.tables=t.tables,u.childrenDatabases)for(lete=0;e<u.childrenDatabases.length;e++){let{dbFullName:r}=u.childrenDatabases[e],s=i.find(e=>e.dbFullName===r);if(!s||!s.tables){u.childrenDatabases?.splice(e,1);continue}s.tables=t.tables}c().writeFileSync(`${o}`,JSON.stringify(i),"utf8"),await(0,p.A)({userId:s.id,targetDatabase:n.db_full_name}),r.json({success:!0})}catch(t){(0,d.A)({component:"/api/acceptUserInvitation/catch-error",message:t.message,user:s,req:e}),r.json({success:!1})}}letf=(0,o.M)(t,"default"),A=(0,o.M)(t,"config"),v=newa.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/user-schema/replace-database-schema",pathname:"/api/user-schema/replace-database-schema",bundlePath:"",filename:""},userland:t})},69842:(e,r,s)=>{s.d(r,{A:()=>n});vart=s(39908),a=s.n(t);asyncfunctionn(e,r,s){lett=a()({req:e,level:s?"deep":void0});returnconsole.log(t),t.payload}},48786:(e,r,s)=>{s.d(r,{A:()=>a});vart=s(7447);asyncfunctiona(...e){letr=(0,t.A)();try{if(!r)throwError("No Connection provided to DB_HANDLER function!");lets=awaitr.query(...e);returnJSON.parse(JSON.stringify(s))}catch(e){returnconsole.log("DB Error =>",e),{success:!1,error:e.message}}finally{awaitr?.end()}}},7447:(e,r,s)=>{s.d(r,{A:()=>n});vart=s(9973),a=s.n(t);functionn(e){returne?.ro?DSQL_READ_ONLY_DB_CONN||a()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void0,charset:"utf8mb4"}}):e?.fa?global.DSQL_FULL_ACCESS_DB_CONN||a()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void0,charset:"utf8mb4"}}):global.DSQL_DB_CONN||a()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void0,charset:"utf8mb4"}})}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){returns}});vars=function(e){returne.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})},89947:(e,r,s)=>{e.exports=s(75600)}};varr=require("../../../webpack-api-runtime.js");r.C(e);vars=e=>r(r.s=e),t=r.X(0,[9814],()=>s(55096));module.exports=t})();