add: store coin transfer source
This commit is contained in:
parent
a08552338b
commit
98426d0989
11 changed files with 105 additions and 9 deletions
|
@ -538,6 +538,61 @@ impl DataManager {
|
|||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
// delete transfers
|
||||
let res = execute!(
|
||||
&conn,
|
||||
"DELETE FROM transfers WHERE sender = $1 OR receiver = $2",
|
||||
&[&(id as i64)]
|
||||
);
|
||||
|
||||
if let Err(e) = res {
|
||||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
// delete products
|
||||
let res = execute!(
|
||||
&conn,
|
||||
"DELETE FROM products WHERE owner = $1",
|
||||
&[&(id as i64)]
|
||||
);
|
||||
|
||||
if let Err(e) = res {
|
||||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
// delete domains
|
||||
let res = execute!(
|
||||
&conn,
|
||||
"DELETE FROM domains WHERE owner = $1",
|
||||
&[&(id as i64)]
|
||||
);
|
||||
|
||||
if let Err(e) = res {
|
||||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
// delete services
|
||||
let res = execute!(
|
||||
&conn,
|
||||
"DELETE FROM services WHERE owner = $1",
|
||||
&[&(id as i64)]
|
||||
);
|
||||
|
||||
if let Err(e) = res {
|
||||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
// delete letters
|
||||
let res = execute!(
|
||||
&conn,
|
||||
"DELETE FROM letters WHERE owner = $1",
|
||||
&[&(id as i64)]
|
||||
);
|
||||
|
||||
if let Err(e) = res {
|
||||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
// delete user follows... individually since it requires updating user counts
|
||||
for follow in self.get_userfollows_by_receiver_all(id).await? {
|
||||
self.delete_userfollow(follow.id, &user, true).await?;
|
||||
|
|
|
@ -5,5 +5,6 @@ CREATE TABLE IF NOT EXISTS transfers (
|
|||
receiver BIGINT NOT NULL,
|
||||
amount INT NOT NULL,
|
||||
is_pending INT NOT NULL,
|
||||
method TEXT NOT NULL
|
||||
method TEXT NOT NULL,
|
||||
source TEXT NOT NULL
|
||||
)
|
||||
|
|
|
@ -49,3 +49,7 @@ ADD COLUMN IF NOT EXISTS checkouts TEXT DEFAULT '[]';
|
|||
-- products single_use
|
||||
ALTER TABLE products
|
||||
ADD COLUMN IF NOT EXISTS single_use INT DEFAULT 1;
|
||||
|
||||
-- transfers source
|
||||
ALTER TABLE transfers
|
||||
ADD COLUMN IF NOT EXISTS source TEXT DEFAULT '"General"';
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use crate::model::{
|
||||
auth::User,
|
||||
economy::{CoinTransfer, CoinTransferMethod, Product, ProductFulfillmentMethod},
|
||||
economy::{
|
||||
CoinTransfer, CoinTransferMethod, CoinTransferSource, Product, ProductFulfillmentMethod,
|
||||
},
|
||||
mail::Letter,
|
||||
permissions::FinePermission,
|
||||
Error, Result,
|
||||
|
@ -154,6 +156,7 @@ impl DataManager {
|
|||
product.owner,
|
||||
product.price,
|
||||
CoinTransferMethod::Purchase(product.id),
|
||||
CoinTransferSource::Sale,
|
||||
);
|
||||
|
||||
if !product.stock.is_negative() {
|
||||
|
|
|
@ -18,6 +18,7 @@ impl DataManager {
|
|||
amount: get!(x->4(i32)),
|
||||
is_pending: get!(x->5(i32)) as i8 == 1,
|
||||
method: serde_json::from_str(&get!(x->6(String))).unwrap(),
|
||||
source: serde_json::from_str(&get!(x->7(String))).unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,7 +176,7 @@ impl DataManager {
|
|||
|
||||
let res = execute!(
|
||||
&conn,
|
||||
"INSERT INTO transfers VALUES ($1, $2, $3, $4, $5, $6, $7)",
|
||||
"INSERT INTO transfers VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
params![
|
||||
&(data.id as i64),
|
||||
&(data.created as i64),
|
||||
|
@ -184,6 +185,7 @@ impl DataManager {
|
|||
&data.amount,
|
||||
&{ if data.is_pending { 1 } else { 0 } },
|
||||
&serde_json::to_string(&data.method).unwrap(),
|
||||
&serde_json::to_string(&data.source).unwrap(),
|
||||
]
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue