mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 22:36:27 +00:00
Refactor backend services and preserve transaction contracts
This commit is contained in:
@@ -1,159 +1,14 @@
|
||||
const { default: axios } = require('axios');
|
||||
|
||||
// Kegagalan CTS harus selesai pada jalur error yang sudah dimiliki endpoint.
|
||||
function postWithDeadline(url, data, config) {
|
||||
const timeout = 5000;
|
||||
return axios.post(url, data, { ...config, timeout, signal: AbortSignal.timeout(timeout) });
|
||||
}
|
||||
const { postWithDeadline } = require('./cts-client');
|
||||
const knex = require('../../../infrastructure/database/knex');
|
||||
|
||||
const { param, body, validationResult } = require('express-validator');
|
||||
const { validationResult } = require('express-validator');
|
||||
const validate = require('./pos.validation');
|
||||
const helper = require('../../helpers/helper');
|
||||
const winston = require('../../helpers/winston.logger');
|
||||
const model = require('./pos.model');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
const moment = require('moment');
|
||||
const { Console } = require('winston/lib/winston/transports');
|
||||
moment.locale('id');
|
||||
|
||||
// VALIDATION
|
||||
const validate = (method) => {
|
||||
switch (method) {
|
||||
case 'validateCardSales':
|
||||
return [
|
||||
body('card_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Card number is required'),
|
||||
];
|
||||
case 'validateLastBalance':
|
||||
return [
|
||||
body('card_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Card number is required'),
|
||||
];
|
||||
case 'validateCardTopup':
|
||||
return [
|
||||
body('card_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Card number is required'),
|
||||
body('amount')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Amount is required')
|
||||
.isNumeric()
|
||||
.withMessage('Amount is invalid format'),
|
||||
body('last_balance')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Last Balance is required')
|
||||
.isNumeric()
|
||||
.withMessage('Last Balance is invalid format'),
|
||||
];
|
||||
case 'validateCardRedeem':
|
||||
return [
|
||||
body('card_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Card number is required'),
|
||||
body('station_code')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Station Code is required'),
|
||||
];
|
||||
case 'checkBlacklist':
|
||||
return [
|
||||
body('card_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Card number is required'),
|
||||
];
|
||||
case 'validateCardReplacement':
|
||||
return [
|
||||
body('card_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Card number is required'),
|
||||
body('station_code')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Station Code is required'),
|
||||
];
|
||||
case 'validateNewCardReplacement':
|
||||
return [
|
||||
body('card_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Card number is required'),
|
||||
];
|
||||
|
||||
//card_number, new_card_number, last_balance, security_code, unique_code
|
||||
case 'cardReplacementConfirm':
|
||||
return [
|
||||
body('card_number').not().isEmpty(),
|
||||
body('new_card_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('New Card number is required'),
|
||||
body('last_balance')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Last Balance is required')
|
||||
.isNumeric()
|
||||
.withMessage('Last Balance is invalid format'),
|
||||
body('unique_code')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Unique Code is required'),
|
||||
body('security_code')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Security Code is required'),
|
||||
];
|
||||
case 'confirmCardRedeem':
|
||||
return [
|
||||
body('card_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Card number is required'),
|
||||
body('security_code')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Security Code is required'),
|
||||
];
|
||||
case 'confirmCardSales':
|
||||
return [
|
||||
body('card_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Card number is required'),
|
||||
body('sales_status')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Sales status Code is required'),
|
||||
body('device_code')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Device Code is required'),
|
||||
body('station_code')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Station Code is required'),
|
||||
body('station_name')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Station name is required'),
|
||||
body('created_by')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Created by is required'),
|
||||
];
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
/****************** */
|
||||
/* GLOBAL PARAMETER */
|
||||
|
||||
Reference in New Issue
Block a user