2024-11-05 11:12:42 +00:00
"use strict" ;
( ( ) => {
var exports = { } ;
exports . id = 590 ;
exports . ids = [ 590 ] ;
exports . modules = {
/***/ 2261 :
/***/ ( ( module ) => {
module . exports = require ( "serverless-mysql" ) ;
/***/ } ) ,
/***/ 4300 :
/***/ ( ( module ) => {
module . exports = require ( "buffer" ) ;
/***/ } ) ,
/***/ 6113 :
/***/ ( ( module ) => {
module . exports = require ( "crypto" ) ;
/***/ } ) ,
/***/ 7147 :
/***/ ( ( module ) => {
module . exports = require ( "fs" ) ;
/***/ } ) ,
/***/ 3685 :
/***/ ( ( module ) => {
module . exports = require ( "http" ) ;
/***/ } ) ,
/***/ 1017 :
/***/ ( ( module ) => {
module . exports = require ( "path" ) ;
/***/ } ) ,
/***/ 6772 :
/***/ ( ( _ _unused _webpack _module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) => {
_ _webpack _require _ _ . r ( _ _webpack _exports _ _ ) ;
/* harmony export */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , {
/* harmony export */ "default" : ( ) => ( /* binding */ handler )
/* harmony export */ } ) ;
/* harmony import */ var _package _shared _functions _backend _varDatabaseDbHandler _ _WEBPACK _IMPORTED _MODULE _0 _ _ = _ _webpack _require _ _ ( 1311 ) ;
/* harmony import */ var _package _shared _functions _backend _varDatabaseDbHandler _ _WEBPACK _IMPORTED _MODULE _0 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _package _shared _functions _backend _varDatabaseDbHandler _ _WEBPACK _IMPORTED _MODULE _0 _ _ ) ;
/* harmony import */ var _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ = _ _webpack _require _ _ ( 2163 ) ;
/* harmony import */ var _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ ) ;
/* harmony import */ var _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _2 _ _ = _ _webpack _require _ _ ( 6825 ) ;
/* harmony import */ var _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _2 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _2 _ _ ) ;
/* harmony import */ var _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _3 _ _ = _ _webpack _require _ _ ( 2224 ) ;
/* harmony import */ var _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _3 _ _ ) ;
// @ts-check
/ * *
* === === === === === === === === === === === === === === === === === === === === === === === === === ===
* Imports
* === === === === === === === === === === === === === === === === === === === === === === === === === ===
* / c o n s t f s = _ _ w e b p a c k _ r e q u i r e _ _ ( 7 1 4 7 ) ;
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ / * *
* API handler
* === === === === === === === === === === === === === === === === === === === === === === === === === ===
* @ type { import ( "next" ) . NextApiHandler }
* / a s y n c f u n c t i o n h a n d l e r ( r e q , r e s ) {
/ * *
* Check method
*
* @ description Check request method and return if invalid
* / i f ( r e q . m e t h o d ! = = " P O S T " ) r e t u r n r e s . j s o n ( {
msg : "Failed!"
} ) ;
/ * *
* User auth
*
* @ description Authenticate user
* / c o n s t u s e r = a w a i t _ f u n c t i o n s _ b a c k e n d _ u s e r A u t h _ _ W E B P A C K _ I M P O R T E D _ M O D U L E _ 2 _ _ _ d e f a u l t ( ) ( r e q , r e s , t r u e ) ;
if ( ! user ) {
return res . json ( {
success : false ,
msg : "Unauthorized"
} ) ;
}
/ * *
* User auth
*
* @ description Authenticate user
* / c o n s t s a n i t i z e d R e q B o d y = r e q . b o d y ;
const { id , user _id , table _name , table _slug , table _description } = sanitizedReqBody . table ;
const { db _full _name } = sanitizedReqBody . database ;
await _package _shared _functions _backend _varDatabaseDbHandler _ _WEBPACK _IMPORTED _MODULE _0 _ _ _default ( ) ( {
database : db _full _name ,
queryString : ` DROP TABLE \` ${ table _slug } \` `
} ) ;
const deleteTableQuery = id ? ` DELETE FROM user_database_tables WHERE id=? ` : ` DELETE FROM user_database_tables WHERE table_slug=? AND user_id=? AND db_id=? ` ;
const deleteTableQueryValues = id ? [
id
] : [
table _slug ,
user . id ,
sanitizedReqBody . database . id
] ;
await _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default ( ) ( deleteTableQuery , deleteTableQueryValues ) ;
try {
/ * *
* Send Response
*
* @ description Send a boolean response
2024-11-05 14:18:40 +00:00
* / c o n s t u s e r S c h e m a M a i n F i l e P a t h = ` $ { p r o c e s s . e n v . D S Q L _ U S E R _ D B _ S C H E M A _ P A T H } / u s e r - $ { u s e r . i d } / m a i n . j s o n ` ;
2024-11-05 11:12:42 +00:00
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType[]} */ let userSchemaData = JSON . parse ( fs . readFileSync ( userSchemaMainFilePath , "utf8" ) ) ;
let targetDatabaseIndex ;
let targetDatabase = userSchemaData . filter ( ( databaseObject , index ) => {
if ( databaseObject . dbFullName === db _full _name ) {
targetDatabaseIndex = index ;
return true ;
}
} ) ;
/** @type {any} */ let targetTableIndex ;
let targetTable = targetDatabase [ 0 ] . tables . filter ( ( tableObject , index ) => {
if ( tableObject ? . tableName === table _slug ) {
targetTableIndex = index ;
return true ;
}
} ) ;
if ( targetTable [ 0 ] . childTable ) {
const parentDb = userSchemaData . filter ( ( db ) => db . dbFullName === targetTable [ 0 ] . childTableDbFullName ) [ 0 ] ;
const parentTableObject = parentDb . tables . filter ( ( table ) => {
if ( table . tableName === targetTable [ 0 ] . childTableName ) {
return true ;
}
} ) [ 0 ] ;
let targetChildIndex ;
const parentTableChildObject = parentTableObject . childrenTables ? . filter ( ( childTable , index ) => {
if ( childTable . tableName === table _slug ) {
targetChildIndex = index ;
}
} ) ;
if ( typeof targetChildIndex === "number" ) parentTableObject . childrenTables ? . splice ( targetChildIndex , 1 ) ;
}
targetDatabase [ 0 ] . tables . splice ( targetTableIndex , 1 ) ;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/ * *
* Check Children Databases
*
* @ description Check Children Databases
* / i f ( t a r g e t D a t a b a s e [ 0 ] . c h i l d r e n D a t a b a s e s ) {
for ( let i = 0 ; i < targetDatabase [ 0 ] . childrenDatabases . length ; i ++ ) {
const childDb = targetDatabase [ 0 ] . childrenDatabases [ i ] ;
try {
const targetChild = userSchemaData . filter ( ( db ) => db . dbFullName === childDb . dbFullName ) [ 0 ] ;
targetChild . tables = targetDatabase [ 0 ] . tables ;
await _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default ( ) ( ` DELETE FROM user_database_tables WHERE table_slug=? AND user_id=? AND db_slug=? ` , [
table _slug ,
user . id ,
targetChild . dbSlug
] ) ;
} catch ( /** @type {any} */ error ) {
_functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default ( ) ( {
component : "/api/deleteUserTable/lines-125-128" ,
message : error . message ,
user : user
} ) ;
}
}
}
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
fs . writeFileSync ( ` ${ userSchemaMainFilePath } ` , JSON . stringify ( userSchemaData ) , "utf8" ) ;
////////////////////////////////////////
res . json ( {
success : true
} ) ;
////////////////////////////////////////
} catch ( /** @type {any} */ error1 ) {
////////////////////////////////////////
_functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default ( ) ( {
component : "/api/deleteUserTable/main-catch-error" ,
message : error1 . message ,
user : user
} ) ;
res . json ( {
success : false ,
msg : "File Updates Failed"
} ) ;
}
}
/***/ } )
} ;
;
// load runtime
var _ _webpack _require _ _ = require ( "../../webpack-api-runtime.js" ) ;
_ _webpack _require _ _ . C ( exports ) ;
var _ _webpack _exec _ _ = ( moduleId ) => ( _ _webpack _require _ _ ( _ _webpack _require _ _ . s = moduleId ) )
2024-11-05 14:18:40 +00:00
var _ _webpack _exports _ _ = _ _webpack _require _ _ . X ( 0 , [ 2224 , 2163 , 6825 , 3017 , 3403 , 8326 , 1311 ] , ( ) => ( _ _webpack _exec _ _ ( 6772 ) ) ) ;
2024-11-05 11:12:42 +00:00
module . exports = _ _webpack _exports _ _ ;
} ) ( ) ;