389 lines
18 KiB
JavaScript
389 lines
18 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.router = void 0;
|
|
const express_1 = require("express");
|
|
const express_validator_1 = require("express-validator");
|
|
const dotenv = __importStar(require("dotenv"));
|
|
const crypto_1 = __importDefault(require("crypto"));
|
|
const whatsapp_service_1 = require("./whatsapp.service");
|
|
const path_1 = __importDefault(require("path"));
|
|
const fs_1 = __importDefault(require("fs"));
|
|
const moment = require("moment-timezone");
|
|
dotenv.config();
|
|
exports.router = (0, express_1.Router)();
|
|
exports.router.get("/confirm/", [(0, express_validator_1.query)(["data"]).notEmpty()], (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
var _a, _b;
|
|
const errors = (0, express_validator_1.validationResult)(req);
|
|
if (!errors.isEmpty()) {
|
|
res.status(201).send({
|
|
response: errors.array(),
|
|
metadata: {
|
|
code: 400,
|
|
message: "Validation error",
|
|
},
|
|
});
|
|
return;
|
|
}
|
|
const encryptedData = req.query.data;
|
|
const key = process.env.keyKonfirmasiWa;
|
|
try {
|
|
const [encrypted, iv] = Buffer.from(decodeURIComponent(encryptedData), "base64")
|
|
.toString()
|
|
.split("::")
|
|
.map((part) => Buffer.from(part, "base64"));
|
|
const decipher = crypto_1.default.createDecipheriv("aes-256-cbc", key ? Buffer.from(key) : Buffer.from(""), iv);
|
|
let decrypted = decipher.update(encrypted);
|
|
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
const registrasiUrutId = parseInt(decrypted.toString(), 10);
|
|
const resultConfirm = yield (0, whatsapp_service_1.confirmWhatsappService)(registrasiUrutId);
|
|
let htmlIndex = "";
|
|
if (resultConfirm.code === 200) {
|
|
htmlIndex = `
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Konfirmasi Berhasil</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
background-color: #f0f0f0;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
}
|
|
|
|
.container {
|
|
text-align: center;
|
|
background-color: #ffffff;
|
|
padding: 50px;
|
|
border-radius: 10px;
|
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.message-box {
|
|
border: 3px solid #28a745;
|
|
padding: 20px;
|
|
border-radius: 5px;
|
|
}
|
|
|
|
h1 {
|
|
color: #28a745;
|
|
font-size: 2.5rem;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
p {
|
|
font-size: 1.2rem;
|
|
color: #333333;
|
|
}
|
|
|
|
hr {
|
|
margin: 20px 0;
|
|
}
|
|
|
|
h2 {
|
|
margin-bottom: 10px;
|
|
color: #333333;
|
|
}
|
|
|
|
strong {
|
|
color: #000000;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="container">
|
|
<div class="message-box">
|
|
<h1>Selamat!</h1>
|
|
<p>Konfirmasi WhatsApp Anda berhasil.</p>
|
|
<hr>
|
|
<h2>Detail Kunjungan</h2>
|
|
<table border="1" width="100%" cellspacing="4" cellpadding="4" style="border-collapse: collapse; text-align: left">
|
|
<tr>
|
|
<td>
|
|
<strong>Nama Pasien</strong>
|
|
</td>
|
|
<td>
|
|
<strong>${resultConfirm.data
|
|
.nama_pasien}</strong>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<strong>Dokter</strong>
|
|
</td>
|
|
<td>
|
|
<strong>${((_a = resultConfirm === null || resultConfirm === void 0 ? void 0 : resultConfirm.data) === null || _a === void 0 ? void 0 : _a.nama_pegawai) ? resultConfirm.data.nama_pegawai : ''}</strong>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<strong>Klinik</strong>
|
|
</td>
|
|
<td>
|
|
<strong>${resultConfirm.data
|
|
.nama_bagian}</strong>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<strong>Tanggal Kunjungan</strong>
|
|
</td>
|
|
<td>
|
|
<strong>${moment(resultConfirm.data.tgl_masuk).format("DD-MM-YYYY")}</strong>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
|
|
</html>
|
|
`;
|
|
fs_1.default.writeFileSync(path_1.default.join(__dirname, "./../../../views/whatsappconfirm.html"), htmlIndex);
|
|
res.sendFile(path_1.default.join(__dirname, "./../../../views", "whatsappconfirm.html"));
|
|
}
|
|
else {
|
|
htmlIndex = `
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Konfirmasi Berhasil</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
background-color: #f0f0f0;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
}
|
|
|
|
.container {
|
|
text-align: center;
|
|
background-color: #ffffff;
|
|
padding: 50px;
|
|
border-radius: 10px;
|
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.message-box {
|
|
border: 3px solid #B10F2E;
|
|
padding: 20px;
|
|
border-radius: 5px;
|
|
}
|
|
|
|
h1 {
|
|
color: #B10F2E;
|
|
font-size: 2.5rem;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
p {
|
|
font-size: 1.2rem;
|
|
color: #333333;
|
|
}
|
|
|
|
hr {
|
|
margin: 20px 0;
|
|
}
|
|
|
|
h2 {
|
|
margin-bottom: 10px;
|
|
color: #333333;
|
|
}
|
|
|
|
strong {
|
|
color: #000000;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="container">
|
|
<div class="message-box">
|
|
<h1>Peringatan!</h1>
|
|
<p>Konfirmasi WhatsApp Sudah Dilakukan Sebelumnya.</p>
|
|
<hr>
|
|
<h2>Detail Kunjungan</h2>
|
|
<table border="1" width="100%" cellspacing="4" cellpadding="4" style="border-collapse: collapse; text-align: left">
|
|
<tr>
|
|
<td>
|
|
<strong>Nama Pasien</strong>
|
|
</td>
|
|
<td>
|
|
<strong>${resultConfirm.data
|
|
.nama_pasien}</strong>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<strong>Dokter</strong>
|
|
</td>
|
|
<td>
|
|
<strong>${((_b = resultConfirm === null || resultConfirm === void 0 ? void 0 : resultConfirm.data) === null || _b === void 0 ? void 0 : _b.nama_pegawai) ? resultConfirm.data.nama_pegawai : ''}</strong>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<strong>Klinik</strong>
|
|
</td>
|
|
<td>
|
|
<strong>${resultConfirm.data
|
|
.nama_bagian}</strong>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<strong>Tanggal Kunjungan</strong>
|
|
</td>
|
|
<td>
|
|
<strong>${moment(resultConfirm.data.tgl_masuk).format("DD-MM-YYYY")}</strong>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
|
|
</html>
|
|
`;
|
|
fs_1.default.writeFileSync(path_1.default.join(__dirname, "./../../../views/whatsappconfirm.html"), htmlIndex);
|
|
res.sendFile(path_1.default.join(__dirname, "./../../../views", "whatsappconfirm.html"));
|
|
}
|
|
}
|
|
catch (err) {
|
|
console.log(err.message);
|
|
let htmlIndex = `
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Konfirmasi Berhasil</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
background-color: #f0f0f0;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
}
|
|
|
|
.container {
|
|
text-align: center;
|
|
background-color: #ffffff;
|
|
padding: 50px;
|
|
border-radius: 10px;
|
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.message-box {
|
|
border: 3px solid #B10F2E;
|
|
padding: 20px;
|
|
border-radius: 5px;
|
|
}
|
|
|
|
h1 {
|
|
color: #B10F2E;
|
|
font-size: 2.5rem;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
p {
|
|
font-size: 1.2rem;
|
|
color: #333333;
|
|
}
|
|
|
|
hr {
|
|
margin: 20px 0;
|
|
}
|
|
|
|
h2 {
|
|
margin-bottom: 10px;
|
|
color: #333333;
|
|
}
|
|
|
|
strong {
|
|
color: #000000;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="container">
|
|
<div class="message-box">
|
|
<h1>GAGAL!</h1>
|
|
<p>Konfirmasi WhatsApp Gagal.</p>
|
|
<hr>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
|
|
</html>
|
|
`;
|
|
fs_1.default.writeFileSync(path_1.default.join(__dirname, "./../../../views/whatsappconfirm.html"), htmlIndex);
|
|
res.sendFile(path_1.default.join(__dirname, "./../../../views", "whatsappconfirm.html"));
|
|
}
|
|
}));
|