"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 = ` Konfirmasi Berhasil

Selamat!

Konfirmasi WhatsApp Anda berhasil.


Detail Kunjungan

Nama Pasien ${resultConfirm.data .nama_pasien}
Dokter ${((_a = resultConfirm === null || resultConfirm === void 0 ? void 0 : resultConfirm.data) === null || _a === void 0 ? void 0 : _a.nama_pegawai) ? resultConfirm.data.nama_pegawai : ''}
Klinik ${resultConfirm.data .nama_bagian}
Tanggal Kunjungan ${moment(resultConfirm.data.tgl_masuk).format("DD-MM-YYYY")}
`; 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 = ` Konfirmasi Berhasil

Peringatan!

Konfirmasi WhatsApp Sudah Dilakukan Sebelumnya.


Detail Kunjungan

Nama Pasien ${resultConfirm.data .nama_pasien}
Dokter ${((_b = resultConfirm === null || resultConfirm === void 0 ? void 0 : resultConfirm.data) === null || _b === void 0 ? void 0 : _b.nama_pegawai) ? resultConfirm.data.nama_pegawai : ''}
Klinik ${resultConfirm.data .nama_bagian}
Tanggal Kunjungan ${moment(resultConfirm.data.tgl_masuk).format("DD-MM-YYYY")}
`; 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 = ` Konfirmasi Berhasil

GAGAL!

Konfirmasi WhatsApp Gagal.


`; fs_1.default.writeFileSync(path_1.default.join(__dirname, "./../../../views/whatsappconfirm.html"), htmlIndex); res.sendFile(path_1.default.join(__dirname, "./../../../views", "whatsappconfirm.html")); } }));