-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
311 lines (273 loc) · 10.8 KB
/
controller.js
File metadata and controls
311 lines (273 loc) · 10.8 KB
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
'use strict';
var response = require('./res');
var connection = require('./koneksi');
exports.index = function (req, res) {
response.ok("Back-End REST API Running Now!", res)
};
//menampilkan semua data tabel barang
exports.tampilbarang = function (req, res) {
connection.query('SELECT * FROM t_barang', function (error, rows, fileds) {
if (error) {
console.log(error);
} else {
response.ok(rows, res)
}
});
};
//menampilkan semua data tabel transaksi
exports.tampilsemuatransaksi = function (req, res) {
connection.query('SELECT * FROM t_transaksi', function (error, rows, fileds) {
if (error) {
console.log(error);
} else {
response.ok(rows, res)
}
});
};
//menampilkan semua data tabel user
exports.tampiluser = function (req, res) {
connection.query('SELECT * FROM t_user', function (error, rows, fileds) {
if (error) {
console.log(error);
} else {
response.ok(rows, res)
}
});
};
//menampilkan semua data kontak
exports.tampilkontak = function (req, res) {
connection.query('SELECT * FROM t_contact', function (error, rows, fileds) {
if (error) {
console.log(error);
} else {
response.ok(rows, res)
}
});
};
//=============================BATAS TAMPIL=======================================================///
//menampilkan semua data tabel barang berdasarkan id_barang
exports.tampilbarangid = function (req, res) {
let id_barang = req.params.id_barang;
connection.query('SELECT * FROM t_barang WHERE id_barang = ?', [id_barang],
function (error, rows, fields) {
if (error) {
console.log(error);
} else {
response.ok(rows, res);
}
});
};
//menampilkan semua data tabel TRANSAKSI berdasarkan kode TRANSAKSI
exports.tampiltransaksiid = function (req, res) {
let kode_transaksi = req.params.kode_transaksi;
connection.query('SELECT * FROM t_barang WHERE kode_transaksi = ?', [kode_transaksi],
function (error, rows, fields) {
if (error) {
console.log(error);
} else {
response.ok(rows, res);
}
});
};
//menampilkan semua data tabel barang berdasarkan id_user
exports.tampiluserid = function (req, res) {
let id_user = req.params.id_user;
connection.query('SELECT * FROM user WHERE id_user = ?', [id_user],
function (error, rows, fields) {
if (error) {
console.log(error);
} else {
response.ok(rows, res);
}
});
};
//=============================BATAS TAMPIL BY ID=======================================================///
//menambahkan data transaksi
exports.tambahtransaksi = function (req, res) {
var kode_transaksi = req.body.kode_transaksi;
var kode_barang = req.body.kode_barang;
var nama_barang = req.body.nama_barang;
var id_user = req.body.id_user;
var id_admin = req.body.id_admin;
var id_pembayaran = req.body.id_pembayaran;
var tgl_transaksi = req.body.tgl_transaksi;
connection.query('INSERT INTO t_transaksi (kode_transaksi,kode_barang,nama_barang,id_user,id_admin,id_pembayaran,tgl_transaksi) VALUES(?,?,?,?,?,?,?)',
[kode_transaksi,kode_barang,nama_barang,id_user,id_admin,id_pembayaran,tgl_transaksi],
function (error, rows, fields) {
if (error) {
console.log(error);
} else {
response.ok("Berhasil Menambahkan Data!", res)
}
});
};
//menambahkan data barang
exports.tambahbarang = function (req, res) {
var kode_barang = req.body.kode_barang;
var nama_barang = req.body.nama_barang;
var harga = req.body.harga;
var jumlah_barang = req.body.jumlah_barang;
var satuan = req.body.satuan;
connection.query('INSERT INTO t_barang (kode_barang,nama_barang,harga,jumlah_barang,satuan) VALUES(?,?,?,?,?)',
[kode_barang,nama_barang,harga,jumlah_barang,satuan],
function (error, rows, fields) {
if (error) {
console.log(error);
} else {
response.ok("Berhasil Menambahkan Data!", res)
}
});
};
//menambahkan data USER
exports.tambahuser = function (req, res) {
var id_user = req.body.id_user;
var nama_user = req.body.nama_user;
var username = req.body.username;
var email = req.body.email;
var password = req.body.password;
var tanggal_daftar = req.body.tanggal_daftar;
var nohp = req.body.nohp;
var alamat = req.body.alamat;
connection.query('INSERT INTO t_user (id_user,nama_user,username,email,password,tanggal_daftar,nohp,alamat) VALUES(?,?,?,?,?,?,?,?)',
[id_user,nama_user,username,email,password,tanggal_daftar,nohp,alamat],
function (error, rows, fields) {
if (error) {
console.log(error);
} else {
response.ok("User Berhasil Ditambahkan !", res)
}
});
};
//menambahkan data kontak
exports.tambahkontak = function (req, res) {
var id_contact = req.body.id_contact;
var nama_contact = req.body.nama_contact;
var email_contact = req.body.email_contact;
var pesan = req.body.pesan;
connection.query('INSERT INTO t_contact (id_contact,nama_contact, email_contact,pesan) VALUES(?,?,?,?)',
[id_contact,nama_contact, email_contact,pesan],
function (error, rows, fields) {
if (error) {
console.log(error);
} else {
response.ok("Pesan anda terkirim!", res)
}
});
};
//===============================================================BATAS TAMBAH DATA=======================================
//mengubah data berdasarkan kode_transaksi
exports.ubahtransaksi= function (req, res) {
var kode_transaksi = req.body.kode_transaksi;
var kode_barang = req.body.kode_barang;
var nama_barang = req.body.nama_barang;
var id_user = req.body.id_user;
var id_admin = req.body.id_admin;
var id_pembayaran = req.body.id_pembayaran;
var tgl_transaksi = req.body.tgl_transaksi;
connection.query('UPDATE t_transaksi SET kode_barang=?, nama_barang=?, id_user=?,id_admin=?,satuan=?,id_pembayaran=?,tgl_transaksi=?, WHERE kode_transaksi=?', [kode_barang, nama_barang, id_user,id_admin,harga,id_pembayaran,tgl_transaksi, kode_transaksi],
function (error, rows, fields) {
if (error) {
console.log(error);
} else {
response.ok("Berhasil Ubah Data", res)
}
});
}
//mengubah data berdasarkan id_barang
exports.ubahbarang= function (req, res) {
var id_barang = req.body.id_barang;
var kode_barang = req.body.kode_barang;
var nama_barang = req.body.nama_barang;
var jumlah_barang = req.body.jumlah_barang;
var harga = req.body.harga;
var satuan = req.body.satuan;
connection.query('UPDATE t_barang SET kode_barang=?, nama_barang=?,harga=?, jumlah_barang=?,satuan=? WHERE id_barang=?', [kode_barang, nama_barang, jumlah_barang,harga,satuan, id_barang],
function (error, rows, fields) {
if (error) {
console.log(error);
} else {
response.ok("Berhasil Ubah Data", res)
}
});
}
//mengubah data berdasarkan id_user
exports.ubahuser= function (req, res) {
var id_user = req.body.id_user;
var nama_user = req.body.nama_user;
var username = req.body.username;
var email = req.body.email;
var password = req.body.password;
//tidak gunakan tanggal daftar untuk ubah user
var nohp = req.body.nohp;
var alamat = req.body.alamat;
connection.query('UPDATE t_user SET nama_user=?, username=?,email=?,password=?,nohp=?,alamat=?, WHERE id_user=?', [nama_user,username,email,password,nohp,alamat, id_user],
function (error, rows, fields) {
if (error) {
console.log(error);
} else {
response.ok("Berhasil Ubah Data User", res)
}
});
}
//====================================================BATAS UBAH DATA==================================================
//Menghapus data berdasarkan kode_transaksi
exports.hapustransaksi = function (req, res) {
var kode_transaksi = req.body.kode_transaksi;
connection.query('DELETE FROM t_transaksi WHERE kode_transaksi=?',[kode_transaksi],
function (error, rows, fields) {
if (error) {
console.log(error);
} else {
response.ok("Berhasil Hapus Data", res)
}
});
}
//Menghapus data berdasarkan id_barang
exports.hapusbarang = function (req, res) {
var id_barang = req.body.id_barang;
connection.query('DELETE FROM t_barang WHERE id_barang=?',[id_barang],
function (error, rows, fields) {
if (error) {
console.log(error);
} else {
response.ok("Berhasil Hapus Data", res)
}
});
}
//Menghapus data berdasarkan id_user
exports.hapususer = function (req, res) {
var id_user = req.body.id_user;
connection.query('DELETE FROM t_user WHERE id_user=?',[id_user],
function (error, rows, fields) {
if (error) {
console.log(error);
} else {
response.ok("Berhasil Hapus User", res)
}
});
}
// ==========================================BATAS SINTAK Delete===================================================================\\
//menampilkan transaksi group (masih blum di fix)
exports.tampilgroupbarang = function(req, res){
connection.query('SELECT t_barang.id_barang,t_barang.kode_barang, t_barang.nama_barang, t_barang.harga,t_barang.jumlah_barang,t_barang.satuan, t_transaksi.kode_barang, t_transaksi.kode_transaksi from krs JOIN t_transaksi JOIN t_barang WHERE t_transaksi = t_transaksi.kode_transaksi t_transaksi.kode_barang = t_barang.id_barang ORDER BY t_barang.id_barang',
function (error, rows, fields){
if(error){
console.log(error);
}else {
response.oknested(rows, res);
}
}
)
}
//menampilkan TRANSAKSI group (masih blum di fix)
exports.tampilgrouptransaksi= function(req, res){
connection.query('SELECT t_barang.id_barang,t_barang, t_barang.kode_barang, t_barang.nama_barang, t_barang.harga,t_barang.jumlah_barang,t_barang.satuan, t_transaksi.kode_barang from krs JOIN t_transaksi JOIN t_barang WHERE t_transaksi = t_transaksi.kode_transaksi t_transaksi = t_barang.id_barang ORDER BY t_barang.id_barang',
function (error, rows, fields){
if(error){
console.log(error);
}else {
response.oknested(rows, res);
}
}
)
}