def get(self):
     cnx = DBConnection.get_connection().connection()
     cursor = cnx.cursor()
     cursor.execute(
         f"SELECT * FROM complain_voucher_fisik where complain_id='{self.complain_id}'"
     )
     complain_result = cursor.fetchone()
     if complain_result:
         self.id = complain_result[0]
         # self.complain_id = complain_id
         self.telegram_id = complain_result[2]
         self.status = complain_result[3]
         self.kabupaten = complain_result[4]
         self.kecamatan = complain_result[5]
         self.nama_outlet = complain_result[6]
         self.id_digipos_outlet = complain_result[7]
         self.nomor_pelanggan = complain_result[8]
         self.serial_number = complain_result[9]
         self.tgl_inject_voucher = complain_result[10]
         self.paket = complain_result[11]
         self.masalah = complain_result[12]
         # self.photo = complain_result[13]
         self.chat_id = complain_result[14]
         self.message_id = complain_result[15]
         self.handler_user_id = complain_result[16]
         self.created = complain_result[17]
         return self
     return self
 def new(self,
         data,
         telegram_id,
         complain_type=None,
         chat_id=None,
         message_id=None):
     photo = None
     if data['photo']:
         photo = data['photo']
         del data['photo']
     if photo:
         pass
     if complain_type == 'digipos':
         cnx = DBConnection.get_connection().connection()
         cursor = cnx.cursor()
         query_save_complain = (
             "INSERT INTO complain_digipos "
             "(complain_id, kabupaten, telegram_id, "
             "kecamatan, id_outlet, nama_outlet, no_mkios, no_pelanggan, "
             "tgl_transaksi, detail, pay_method, versi_apk_dipos, channel_lain, "
             "chat_id, message_id) "
             f'VALUES ("{self.complain_id}", %(kabupaten)s, {telegram_id}, %(kecamatan)s, '
             f'%(id_outlet)s, %(nama_outlet)s, %(no_mkios)s,  %(no_pelanggan)s, '
             f'%(tgl_transaksi)s, %(detail)s, %(pay_method)s, %(versi_apk_dipos)s, '
             f'%(channel_lain)s, "{chat_id}", "{message_id}")')
         cursor.execute(query_save_complain, data)
         cnx.commit()
         data['photo'] = photo
     else:
         raise KeyError
 def set_status(self, status: str, admin_id: str):
     cnx = DBConnection.get_connection().connection()
     cursor = cnx.cursor()
     sql = f"UPDATE complain_registrasi_perdana SET status = '{status}', handler_user_id = '{admin_id}' " \
           f"WHERE complain_id = '{self.complain_id}'"
     cursor.execute(sql)
     cnx.commit()
 def new(self,
         data,
         telegram_id,
         complain_type=None,
         chat_id=None,
         message_id=None):
     photo = None
     if data['photo']:
         photo = data['photo']
         del data['photo']
     if photo:
         pass
     if complain_type == 'voucher_fisik':
         cnx = DBConnection.get_connection().connection()
         cursor = cnx.cursor()
         query_save_complain = (
             "INSERT INTO complain_voucher_fisik "
             "(complain_id, telegram_id, kabupaten, "
             "kecamatan, nama_outlet, id_digipos_outlet, nomor_pelanggan, "
             "serial_number, tgl_inject_voucher, paket, masalah, chat_id, "
             "message_id) "
             f'VALUES ("{self.complain_id}", {telegram_id}, %(kabupaten)s, %(kecamatan)s, '
             f'%(nama_outlet)s, %(id_digipos_outlet)s, %(nomor_pelanggan)s, '
             f'%(serial_number)s, %(tgl_inject_voucher)s, %(paket)s, %(masalah)s, '
             f'"{chat_id}", "{message_id}")')
         cursor.execute(query_save_complain, data)
         cnx.commit()
         data['photo'] = photo
     else:
         raise KeyError
 def get(self):
     cnx = DBConnection.get_connection().connection()
     cursor = cnx.cursor()
     cursor.execute(
         f"SELECT * FROM complain_digipos where complain_id='{self.complain_id}'"
     )
     complain_result = cursor.fetchone()
     if complain_result:
         self.id = complain_result[0]
         # self.complain_id = complain_result[1]
         self.status = complain_result[2]
         self.kabupaten = complain_result[3]
         self.telegram_id = complain_result[4]
         self.kecamatan = complain_result[5]
         self.id_outlet = complain_result[6]
         self.nama_outlet = complain_result[7]
         self.no_mkios = complain_result[8]
         self.no_pelanggan = complain_result[9]
         self.tgl_transaksi = complain_result[10]
         self.detail = complain_result[11]
         self.pay_method = complain_result[12]
         self.versi_apk_dipos = complain_result[13]
         self.channel_lain = complain_result[14]
         self.photo = complain_result[15]
         self.chat_id = complain_result[16]
         self.message_id = complain_result[17]
         self.handler_user_id = complain_result[18]
         self.created = complain_result[19]
         return self
     return self
async def order_barang(order: Order):
    cnx = DBConnection.get_connection().connection()
    cursor = cnx.cursor()
    query = ("INSERT INTO orderan "
             "(telegram_id, kode_barang, qty) "
             "VALUES (%(telegram_id)s, %(kode_barang)s, %(qty)s)")
    cursor.execute(query, order.get())
    cnx.commit()
async def add_user(user: dict):
    cnx = DBConnection.get_connection().connection()
    cursor = cnx.cursor(buffered=True)
    query = ("INSERT INTO user "
             "(telegram_id, telegram_username, kabupaten, kecamatan, nama_outlet, nomor_mkios) "
             "VALUES (%(telegram_id)s, '', %(kabupaten)s, %(kecamatan)s, %(nama_outlet)s, %(nomor_mkios)s)")
    cursor.execute(query, user)
    cnx.commit()
 def new(self, data, telegram_id, chat_id=None, message_id=None):
     cnx = DBConnection.get_connection().connection()
     cursor = cnx.cursor()
     query_save_complain = (
         "INSERT INTO complain_registrasi_perdana "
         "(complain_id, telegram_id, msisdn_or_nomor_kartu, "
         "nama_lengkap, tempat_lahir, tanggal_lahir, nik, "
         "no_kk, chat_id, message_id) "
         f'VALUES ("{self.complain_id}", {telegram_id}, %(msisdn_or_nomor_kartu)s, %(nama_lengkap)s, '
         f'%(tempat_lahir)s, %(tanggal_lahir)s, %(nik)s, '
         f'%(no_kk)s, "{chat_id}", "{message_id}")')
     cursor.execute(query_save_complain, data)
     cnx.commit()
async def is_registered(id_user: int) -> User:
    cnx = DBConnection.get_connection().connection()
    cursor = cnx.cursor()
    cursor.execute(f"SELECT * FROM user where telegram_id={id_user}")
    user = cursor.fetchone()
    user_result = User()
    if user:
        user_result.ok = True
        user_result.telegram_id = user[0]
        user_result.telegram_username = user[1]
        user_result.kabupaten = user[2]
        user_result.kecamatan = user[3]
        user_result.nama_outlet = user[4]
        user_result.nomor_mkios = user[5]
        user_result.tgl_registrasi = user[6]
        return user_result
    return user_result
 def get(self):
     cnx = DBConnection.get_connection().connection()
     cursor = cnx.cursor()
     cursor.execute(
         f"SELECT * FROM complain_registrasi_perdana where complain_id='{self.complain_id}'"
     )
     complain_result = cursor.fetchone()
     if complain_result:
         self.id = complain_result[0]
         self.telegram_id = complain_result[2]
         self.status = complain_result[3]
         self.msisdn_or_nomor_kartu = complain_result[4]
         self.nama_lengkap = complain_result[5]
         self.tempat_lahir = complain_result[6]
         self.tanggal_lahir = complain_result[7]
         self.nik = complain_result[8]
         self.no_kk = complain_result[9]
         self.chat_id = complain_result[10]
         self.message_id = complain_result[11]
         self.handler_user_id = complain_result[12]
         self.created = complain_result[13]
         return self
     return self
Exemple #11
0
def test_mock_database(mocker):
    mocker.patch.object(db, 'get_connection')
    db.get_connection()
    db.get_connection.assert_called_once()