mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 11:06:28 +00:00
77 lines
3.6 KiB
JavaScript
77 lines
3.6 KiB
JavaScript
const express = require("express");
|
|
const bodyParser = require("body-parser");
|
|
const cors = require("cors");
|
|
const helper = require("./application/helpers/helper");
|
|
const winston = require("./application/helpers/winston.logger");
|
|
const authRoute = require("./application/routes/auth.routes");
|
|
const dongleOrderRoute = require("./application/routes/dongleorder.routes");
|
|
const reservationRoute = require("./application/routes/reservebalance.routes");
|
|
const loadBalanceRoute = require("./application/routes/loadbalance.routes");
|
|
const hsmRoute = require("./application/routes/hsm.routes");
|
|
const historyRoute = require("./application/routes/history.routes");
|
|
const paymentReconRoute = require("./application/routes/paymentrecon.routes");
|
|
const invoiceRoute = require("./application/routes/invoice.routes");
|
|
const cron = require('node-cron');
|
|
const moment = require('moment')
|
|
require("dotenv").config();
|
|
|
|
const app = express();
|
|
|
|
var corsOptions = {
|
|
origin: ["http://localhost:" + process.env.PORT || 8000, "http://localhost:3000"],
|
|
};
|
|
|
|
// app.use(cors(corsOptions));
|
|
app.use(cors(corsOptions));
|
|
|
|
// parse requests of content-type - application/json
|
|
app.use(bodyParser.json());
|
|
|
|
// parse requests of content-type - application/x-www-form-urlencoded
|
|
app.use(bodyParser.urlencoded({ extended: true }));
|
|
|
|
// ============================== ROUTES API ==============================
|
|
app.get("/", (req, res) => {
|
|
res.json({
|
|
message: "Welcome to Topup Online Service.",
|
|
// data: {
|
|
// text: "0nlinet0pupkci",
|
|
// chiper_text: helper.encryptText("0nlinet0pupkci"),
|
|
// },
|
|
});
|
|
});
|
|
|
|
app.use("/api/", authRoute);
|
|
app.use("/api/", dongleOrderRoute);
|
|
app.use("/api/", historyRoute);
|
|
app.use("/api/", hsmRoute);
|
|
app.use("/api/", loadBalanceRoute);
|
|
app.use("/api/", paymentReconRoute);
|
|
app.use("/api/", reservationRoute);
|
|
app.use("/api/", invoiceRoute);
|
|
|
|
// set port, listen for requests
|
|
const PORT = process.env.PORT || 8000;
|
|
app.listen(PORT, () => {
|
|
winston.logger.info(`Server is running on environment: ${process.env.NODE_ENV.toUpperCase()}`);
|
|
});
|
|
|
|
// winston.logger.info(`Response : ${response()}`);
|
|
|
|
// SCHEDULER FOR POSTING INVOICE
|
|
const invoiceSch = require("./application/modules/invoice/invoice.controller");
|
|
cron.schedule('*/10 * * * * *', async () => { // Every minute offset 30 seconds
|
|
// // console.log()
|
|
try {
|
|
winston.logger.info(`[${moment().format('YYYY-MM-DD hh:mm:ss')}] : `, await invoiceSch.postingInvoice());
|
|
} catch (error) {
|
|
winston.logger.info(`[${moment().format('YYYY-MM-DD hh:mm:ss')}] : `, error.message);
|
|
}
|
|
|
|
});
|
|
|
|
// const soap = `<SOAP:Envelope xmlns:SOAP='http://schemas.xmlsoap.org/soap/envelope/'><SOAP:Header/><SOAP:Body><ns0:ZFMCMS_FI_001.Response xmlns:ns0='urn:sap-com:document:sap:rfc:functions'><E_DOCUMENTNUMBER/><E_DOCUMENTYEAR>0000</E_DOCUMENTYEAR><C_T_RETURN><item><TYPE>E</TYPE><DOC_NUMBER>$</DOC_NUMBER><MESSAGE_1>Error in document: BKPFF $ KAQCLNT100</MESSAGE_1><MESSAGE_2/><MESSAGE_3/><MESSAGE_4/><MESSAGE_5/><MESSAGE_6/><MESSAGE_7/><MESSAGE_8/><MESSAGE_9/><MESSAGE_10/></item><item><TYPE>E</TYPE><DOC_NUMBER>$</DOC_NUMBER><MESSAGE_1>Period 01 is not allowed</MESSAGE_1><MESSAGE_2/><MESSAGE_3/><MESSAGE_4/><MESSAGE_5/><MESSAGE_6/><MESSAGE_7/><MESSAGE_8/><MESSAGE_9/><MESSAGE_10/></item><item><TYPE>E</TYPE><DOC_NUMBER>$</DOC_NUMBER><MESSAGE_1>Period 01 is not valid</MESSAGE_1><MESSAGE_2/><MESSAGE_3/><MESSAGE_4/><MESSAGE_5/><MESSAGE_6/><MESSAGE_7/><MESSAGE_8/><MESSAGE_9/><MESSAGE_10/></item></C_T_RETURN></ns0:ZFMCMS_FI_001.Response></SOAP:Body></SOAP:Envelope>`
|
|
// `
|
|
// let resSAP = helper.getXMLData({status: 200}, soap)
|
|
|
|
// winston.logger.info(`SCHEDULER-FB70 RESPONSE posting to SAP ${JSON.stringify(resSAP)}`);
|