2024-11-05 11:12:42 +00:00
"use strict" ;
( ( ) => {
var exports = { } ;
exports . id = 9361 ;
exports . ids = [ 9361 ] ;
exports . modules = {
/***/ 6517 :
/***/ ( ( module ) => {
module . exports = require ( "lodash" ) ;
/***/ } ) ,
/***/ 6109 :
/***/ ( ( module ) => {
module . exports = require ( "sanitize-html" ) ;
/***/ } ) ,
/***/ 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" ) ;
/***/ } ) ,
/***/ 6765 :
/***/ ( ( _ _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 _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _0 _ _ = _ _webpack _require _ _ ( 6825 ) ;
/* harmony import */ var _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _0 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _functions _backend _userAuth _ _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 lodash _ _WEBPACK _IMPORTED _MODULE _2 _ _ = _ _webpack _require _ _ ( 6517 ) ;
/* harmony import */ var lodash _ _WEBPACK _IMPORTED _MODULE _2 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( lodash _ _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 _ _ ) ;
/* harmony import */ var _package _shared _functions _backend _db _addDbEntry _ _WEBPACK _IMPORTED _MODULE _4 _ _ = _ _webpack _require _ _ ( 5338 ) ;
/* harmony import */ var _package _shared _functions _backend _db _addDbEntry _ _WEBPACK _IMPORTED _MODULE _4 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _package _shared _functions _backend _db _addDbEntry _ _WEBPACK _IMPORTED _MODULE _4 _ _ ) ;
// @ts-check
const fs = _ _webpack _require _ _ ( 7147 ) ;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ / * *
* 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 ( {
user : null ,
msg : "Registration Failed!"
} ) ;
/ * *
* User Auth
*
* @ description User Auth
* / 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 _ 0 _ _ _ 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"
} ) ;
}
/ * *
* Validate Form
*
* @ description Check if request body is valid
* / / / const { id , inviting _user _id , invited _user _email , invitation _status , database _access , priviledge } = req . body ;
const sanitizedReqBody = lodash _ _WEBPACK _IMPORTED _MODULE _2 _ _ _default ( ) . cloneDeep ( req . body ) ;
const inviting _user _id = sanitizedReqBody . inviting _user _id ;
const invited _user _email = sanitizedReqBody . invited _user _email ;
const database _access = sanitizedReqBody . database _access ;
const priviledge = sanitizedReqBody . priviledge ;
/ * *
* Validate Form
*
* @ description Check if request body is valid
* / t r y {
const existingUserUser = await _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default ( ) ( ` SELECT email FROM user_users WHERE user_id=? AND invited_user_id=? AND user_type='admin' AND email=? ` , [
inviting _user _id ,
user . id ,
user . email
] ) ;
if ( existingUserUser && existingUserUser [ 0 ] ) {
return res . json ( {
success : false
} ) ;
}
/** @type {any} */ const newUserUser = await _package _shared _functions _backend _db _addDbEntry _ _WEBPACK _IMPORTED _MODULE _4 _ _ _default ( ) ( {
dbFullName : "datasquirel" ,
tableName : "user_users" ,
data : {
user _id : inviting _user _id ,
invited _user _id : user . id ,
database _access : database _access ,
user _priviledge : priviledge ,
user _type : "admin" ,
first _name : user . first _name ,
last _name : user . last _name ,
email : user . email ,
username : user . first _name ,
image : user . image ,
image _thumbnail : user . image _thumbnail
}
} ) ;
const inviteAccepted = await _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default ( ) ( ` UPDATE invitations SET invitation_status='Accepted' WHERE inviting_user_id=? AND invited_user_email=? ` , [
inviting _user _id ,
invited _user _email
] ) ;
const dbTableData = await _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default ( ) ( ` SELECT db_tables_data FROM invitations WHERE inviting_user_id=? ` , [
inviting _user _id
] ) ;
// const dbTableData = await DB_HANDLER(`SELECT db_tables_data FROM invitations WHERE inviting_user_id='${inviting_user_id}' AND invited_user_email='${invited_user_email}'`);
const clearEntries = await _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default ( ) ( ` DELETE FROM delegated_user_tables WHERE root_user_id=' ${ inviting _user _id } ' AND delegated_user_id=' ${ user . id } ' ` ) ;
if ( dbTableData && dbTableData [ 0 ] ) {
const dbTableEntries = dbTableData [ 0 ] . db _tables _data . split ( "|" ) ;
for ( let i = 0 ; i < dbTableEntries . length ; i ++ ) {
const dbTableEntry = dbTableEntries [ i ] ;
const dbTableEntryArray = dbTableEntry . split ( "-" ) ;
const [ db _slug , table _slug ] = dbTableEntryArray ;
const newEntry = await _package _shared _functions _backend _db _addDbEntry _ _WEBPACK _IMPORTED _MODULE _4 _ _ _default ( ) ( {
dbFullName : "datasquirel" ,
tableName : "delegated_user_tables" ,
data : {
delegated _user _id : user . id ,
root _user _id : inviting _user _id ,
database : db _slug ,
table : table _slug ,
priviledge : priviledge
}
} ) ;
}
}
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
res . json ( {
success : newUserUser ? . insertId ? true : false
} ) ;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} catch ( /** @type {any} */ error ) {
_functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default ( ) ( {
component : "/api/acceptUserInvitation/catch-error" ,
message : error . message ,
user : user
} ) ;
res . json ( {
success : false
} ) ;
}
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
/***/ } )
} ;
;
// 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 , 7547 , 5886 , 5338 ] , ( ) => ( _ _webpack _exec _ _ ( 6765 ) ) ) ;
2024-11-05 11:12:42 +00:00
module . exports = _ _webpack _exports _ _ ;
} ) ( ) ;