-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.js
245 lines (240 loc) · 5.81 KB
/
setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
const config = require("./config/config.json");
const mongodbUri = config["database"]["production"]["uri"];
const client = require("mongoose");
const fs = require("fs");
var db = client.connection;
const rmq = require("amqplib");
var knex = require("knex")({
client: "mysql",
connection: {
host: "10.8.0.1",
user: "adminPSTIsql",
password: "PSTIadminSQL93jfxjsZUyQwerty123",
database: "kir",
},
// connection: {
// host: "192.168.18.3",
// user: "kirtanggamus",
// password: "",
// database: "db_kir",
// },
pool: { min: 0, max: 20 },
});
const options = {
// useMongoClient: true,
useNewUrlParser: true,
autoIndex: false, // Don't build indexes
// reconnectTries: Number.MAX_VALUE, // Never stop trying to reconnect
// reconnectInterval: 500, // Reconnect every 500ms
poolSize: 10, // Maintain up to 10 socket connections
// If not connected, return errors immediately rather than waiting for reconnect
// buffemessageaxEntries: 0,
connectTimeoutMS: 10000, // Give up initial connection after 10 seconds
socketTimeoutMS: 45000, // Close sockets after 45 seconds of inactivity
family: 4, // Use IPv4, skip trying IPv6
useUnifiedTopology: true,
};
function dbConnect() {
return new Promise((resolve, reject) => {
client.Promise = global.Promise;
client.connect(mongodbUri, options, (err, database) => {
if (err) {
reject(err);
} else {
knex
.raw("SELECT 'test connection';")
.then((message) => {
console.log("mysql connected");
// Success / boot rest of app
db = database;
resolve(knex);
})
.catch((err) => {
// Failure / timeout
console.log(err);
reject(err);
});
// const knex = require('knex')(mysqlDBconfig);
// knex.client(mysqlDBconfig)
// db = database;
// resolve(database);
}
});
});
}
function rmqConnect() {
return new Promise(async (resolve, reject) => {
try {
let rmqConn = await rmq.connect(config["rmqUri"], function (err, conn) {
if (err) {
console.log("[AMQP]", err.message);
return setTimeout(rmqConnect, 5000);
}
conn.on("error", function (err) {
if (err.message !== "Connection closing") {
console.error("[AMQP] conn error", err.message);
return setTimeout(rmqConnect, 5000);
}
});
conn.on("close", function () {
console.error("[AMQP] reconnecting");
return setTimeout(rmqConnect, 1000);
});
});
resolve(rmqConn);
} catch (error) {
console.log("failed connect to rmq ");
console.log("try to connect RMQ in 5 sec ..");
setTimeout(function () {
rmqConnect();
}, 5000);
}
});
}
exports.commonSuccess = () => {
const data = {
status: true,
rc: "0000",
message: "Berhasil memuat permintaaan",
};
return data;
};
const requestResponse = {
common_nik_not_found: {
status: false,
rc: "0000",
message: "Nik Tidak Terdaftar",
},
common_idkab_sudah_terdaftar: {
status: false,
rc: "0000",
message: "Id Kabupaten Sudah Terdaftar",
},
common_signin_success: {
status: true,
rc: "0000",
message: "Berhasil memuat permintaaan",
},
common_success: {
status: true,
rc: "0000",
message: "Berhasil memuat permintaaan",
},
common_nodata: {
status: false,
rc: "0000",
message: "Tidak ada data",
},
common_delete: {
status: true,
rc: "0000",
message: "Berhasil menghapus data",
},
common_success_simple: {
status: true,
rc: "0000",
message: "Berhasil memuat permintaaan",
},
account_not_found: {
status: false,
rc: "401",
message: "Cek kembali username / password anda",
},
common_error: {
status: false,
rc: "5000",
message:
"Server tidak merespon, silahkan hubungi call center untuk info lebih lanjut",
},
token_invalid: {
success: false,
rc: "0030",
message: "Akses ditolak! Sesi Anda telah berakhir atau tidak valid",
},
email_already_use: {
status: false,
rc: "0011",
message: "Email sudah digunakan",
},
phone_number_already_use: {
status: false,
rc: "0012",
message: "Nomor telepon telah digunakan",
},
user_already_like: {
status: true,
rc: "0013",
message: "Like",
},
invalid_token: {
status: false,
rc: "0030",
message: "Sesi anda telah berakhir, Silahkan login kembali !",
},
sudah_ada_data: {
status: false,
rc: "0056",
message: "Sudah ada data",
},
gagal_memuat: {
status: false,
rc: "0058",
message: "Gagal Memuat",
},
tidak_ada_data: {
status: false,
rc: "0058",
message: "Tidak ada data",
},
tidak_ada_data_pupuk: {
status: false,
rc: "0058",
message: "Anda tidak memiliki jatah subsidi",
},
nik_sudah_ada: {
status: false,
rc: "0105",
message: "Nik sudah digunakan",
},
akun_blm_aktif: {
status: false,
rc: "0105",
message: "Akun anda blm aktif",
},
lengkapi_data: {
status: false,
rc: "0105",
message: "Lengkapi data profile anda",
},
pembaruan_aplikasi: {
status: true,
rc: "0105",
message: "Untuk kenyamanan penggunaan aplikasi, mohon update aplikasi anda",
},
tidak_ada_rekening: {
status: false,
rc: "0105",
message: "Anda Belum memiliki nomor rekening",
},
tidak_ada_kios: {
status: false,
rc: "0105",
message: "Anda Belum memiliki kios",
},
berhasil_transaksi: {
status: true,
rc: "0105",
message: "Berhasil transaksi",
},
tidak_ada_kios: {
status: false,
rc: "0105",
message: "Tidak ada kios didaerah kamu",
},
};
module.exports = {
requestResponse,
mongodbUri,
dbConnect,
rmqConnect,
};