2024-11-05 11:12:42 +00:00
"use strict" ;
( ( ) => {
var exports = { } ;
exports . id = 8362 ;
exports . ids = [ 8362 ] ;
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" ) ;
/***/ } ) ,
/***/ 1118 :
/***/ ( ( _ _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 _ _ ) ;
// @ts-check
/ * *
* === === === === === === === === === === === === === === === === === === === === === === === === === ===
* Imports
* === === === === === === === === === === === === === === === === === === === === === === === === === ===
* / c o n s t c h e c k U s e r R i g h t s = _ _ w e b p a c k _ r e q u i r e _ _ ( 8 9 9 9 ) ;
const grabDelegatedUserFromCookie = _ _webpack _require _ _ ( 1352 ) ;
const serverError = _ _webpack _require _ _ ( 2163 ) ;
const userAuth = _ _webpack _require _ _ ( 6825 ) ;
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ / * *
* @ typedef { object } FetchEntriesBasicBody
* @ property { string } tableName
* @ property { string } dbSlug
* @ property { number } dbId
* @ property { boolean } [ isTitle ]
* @ property { boolean } [ isSlug ]
* @ property { boolean } [ isFullName ]
* @ property { string } [ defaultField ]
* / / * *
* 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 u s e r A u t h ( r e q , r e s , t r u e ) ;
if ( ! user ) {
return res . json ( {
success : false ,
msg : "User Auth Failed"
} ) ;
}
/ * *
* User auth
*
* @ description Authenticate user
* / / * * @ type { FetchEntriesBasicBody } * / c o n s t { t a b l e N a m e , d b S l u g , d b I d , i s T i t l e , i s S l u g , i s F u l l N a m e , d e f a u l t F i e l d , } = r e q . b o d y ;
/ * *
* Send Response
*
* @ description Send a boolean response
* / t r y {
/ * *
* Check if user has rights to this table
*
* @ description Check if user has rights to this table
* / c o n s t d e l e g a t e d U s e r = a w a i t g r a b D e l e g a t e d U s e r F r o m C o o k i e ( {
databaseSlug : dbSlug ,
request : req ,
user : user ,
query : req . query
} ) ;
const checkUserRightsBoolean = await checkUserRights ( {
user : user ,
confirmedDelegetedUser : delegatedUser ,
database : dbSlug ,
table : tableName ,
dbId : dbId ,
priviledgeRegex : /Update Entries/i
} ) ;
if ( ! checkUserRightsBoolean ) {
return res . json ( {
success : false ,
msg : "Unauthorized"
} ) ;
}
const dbFullName = delegatedUser ? . rootUserId ? ` datasquirel_user_ ${ delegatedUser . rootUserId } _ ${ dbSlug } ` : ` datasquirel_user_ ${ user . id } _ ${ dbSlug } ` ;
const queryString = ` SELECT id ${ isTitle ? ",title" : isSlug ? ",slug" : isFullName ? ",CONCAT(first_name, ' ', last_name) AS full_name" : defaultField ? "," + defaultField : "" } FROM ${ tableName } ` ;
const entries = await _package _shared _functions _backend _varDatabaseDbHandler _ _WEBPACK _IMPORTED _MODULE _0 _ _ _default ( ) ( {
database : dbFullName ,
queryString : queryString
} ) ;
/ * *
* Create new user folder and file
*
* @ description Create new user folder and file
* / / ///////////////////////////////////////
res . json ( {
success : true ,
entries
} ) ;
////////////////////////////////////////
} catch ( /** @type {any} */ error ) {
////////////////////////////////////////
serverError ( {
component : "/api/addTableEntry/catch-error" ,
message : error . message ,
user : user
} ) ;
res . json ( {
success : false ,
msg : "Database Files could not be written!" ,
err : error . message
} ) ;
////////////////////////////////////////
}
}
/***/ } )
} ;
;
// 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 , 1352 , 8999 ] , ( ) => ( _ _webpack _exec _ _ ( 1118 ) ) ) ;
2024-11-05 11:12:42 +00:00
module . exports = _ _webpack _exports _ _ ;
} ) ( ) ;