dsql-admin/dsql-app/.local_dist/server/pages/api/contact.js
2024-11-05 12:12:42 +01:00

123 lines
4.3 KiB
JavaScript

"use strict";
(() => {
var exports = {};
exports.id = 2091;
exports.ids = [2091];
exports.modules = {
/***/ 5184:
/***/ ((module) => {
module.exports = require("nodemailer");
/***/ }),
/***/ 7147:
/***/ ((module) => {
module.exports = require("fs");
/***/ }),
/***/ 7221:
/***/ ((__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_handleNodemailer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6926);
/* harmony import */ var _functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_handleNodemailer__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__);
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* API handler
* ==============================================================================
* @type {import("next").NextApiHandler}
*/ async function handler(req, res) {
/**
* Check method
*
* @description Check request method and return if invalid
*/ if (req.method !== "POST") return res.json({
msg: "Failed!"
});
/**
* User auth
*
* @description Authenticate user
*/ const sanitizedReqBody = req.body;
const { name , email , message } = sanitizedReqBody;
if (!email.match(/.*@.*\..*/)) return res.json({
success: false,
msg: "Invalid Email"
});
if (!name.match(/./) || !message.match(/./)) return res.json({
success: false,
msg: "Please Fill in all Fields"
});
/**
* Send Response
*
* @description Send a boolean response
*/ try {
/**
* Create new user folder and file
*
* @description Create new user folder and file
*/ const mail = await _functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_0___default()({
to: "benoti.san@gmail.com",
html: `
<h2>Message From ${name}, ${email}</h2>
<p>${message}</p>
`,
subject: "Contact Form Submission",
text: `Message from ${name}, ${email}`
});
////////////////////////////////////////
if (mail.messageId) {
res.json({
success: true
});
} else {
res.json({
success: false,
msg: "Message Sending Failed"
});
}
////////////////////////////////////////
} catch (/** @type {any} */ error) {
////////////////////////////////////////
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
component: "/api/contact/main-catch-error",
message: error.message
});
res.json({
success: false,
msg: "Database Files could not be written!"
});
////////////////////////////////////////
}
}
/***/ })
};
;
// load runtime
var __webpack_require__ = require("../../webpack-api-runtime.js");
__webpack_require__.C(exports);
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
var __webpack_exports__ = __webpack_require__.X(0, [2163,6926], () => (__webpack_exec__(7221)));
module.exports = __webpack_exports__;
})();