update delete and list transaction requests
This commit is contained in:
parent
e1d5b6c76c
commit
7c4adaf450
11 changed files with 277 additions and 4 deletions
|
@ -39,7 +39,7 @@ constexpr const char* updateTransactionQuery = "UPDATE transactions SET"
|
|||
" `initiator` = ?, `type` = 1, `asset` = ?,"
|
||||
" `parent` = ?, `value` = ?, `performed` = ?"
|
||||
" WHERE `id` = ?";
|
||||
constexpr const char* deleteTransactionQuery = "DELETE FROM transactions where `id` = ? OR `parent` = ?";
|
||||
constexpr const char* deleteTransactionQuery = "DELETE FROM transactions where (`id` = ? OR `parent` = ?) AND `initiator` = ?";
|
||||
constexpr const char* selectAllTransactions = "WITH RECURSIVE AllTransactions AS ("
|
||||
" SELECT t.id, t.initiator, t.asset, t.parent, t.value, t.modified, t.performed t.notes FROM transactions t"
|
||||
" JOIN assets a ON t.asset = a.id"
|
||||
|
@ -475,13 +475,19 @@ void DB::MySQL::updateTransaction(const DB::Transaction& transaction) {
|
|||
upd.execute();
|
||||
}
|
||||
|
||||
void DB::MySQL::deleteTransaction(uint32_t id) {
|
||||
bool DB::MySQL::deleteTransaction(uint32_t id, uint32_t actorId) {
|
||||
MYSQL* con = &connection;
|
||||
|
||||
Statement del(con, deleteTransactionQuery);
|
||||
del.bind(&id, MYSQL_TYPE_LONG, true); //for actual transactions
|
||||
del.bind(&id, MYSQL_TYPE_LONG, true); //for potential children
|
||||
del.bind(&actorId, MYSQL_TYPE_LONG, true); //for preventing unauthorized removal, but it needs to be improved
|
||||
del.execute(); //need to think of a parent with no children transactions...
|
||||
|
||||
if (del.affectedRows() == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<DB::Transaction> DB::MySQL::listTransactions(uint32_t owner) {
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
DB::Transaction addTransaction(const DB::Transaction& transaction) override;
|
||||
std::vector<DB::Transaction> listTransactions(uint32_t owner) override;
|
||||
void updateTransaction(const DB::Transaction& transaction) override;
|
||||
void deleteTransaction(uint32_t id) override;
|
||||
bool deleteTransaction(uint32_t id, uint32_t actorId) override;
|
||||
|
||||
private:
|
||||
void executeFile (const std::filesystem::path& relativePath);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue