I should be working.
This commit is contained in:
1 parent
d262f0d2f8
commit
d78b4f1d90
5 files changed
+55
-45
No files matched your search
+12
-8
@@ -88,14 +88,18 @@ pub fn get_account_by_id(tx: &Transaction, id: &AccountId) -> Result<Account> {
|
||||
}
|
||||
|
||||
fn create_account(tx: &Transaction, sec: &SecurityId, user: &UserId, account_type: AccountType) -> Result<Account> {
|
||||
let q = "INSERT INTO accounts(security, owner, amount, timestamp, account_type)
|
||||
VALUES (?1, ?2, 0, CURRENT_TIMESTAMP, ?3)";
|
||||
let q = "INSERT INTO accounts(security, amount, timestamp, account_type)
|
||||
VALUES (?1, 0, CURRENT_TIMESTAMP, ?2)";
|
||||
let account_type = match account_type {
|
||||
AccountType::Checking => "checking",
|
||||
AccountType::SecurityEmitter => "security_emitter",
|
||||
};
|
||||
tx.execute(q, (sec, user, account_type))?;
|
||||
tx.execute(q, (sec, account_type))?;
|
||||
let id = AccountId::from_id(tx.last_insert_rowid() as u32);
|
||||
|
||||
let q = "INSERT INTO account_user_permissions(user_id, account_id)
|
||||
VALUES(?1, ?2)";
|
||||
tx.execute(q, params![user, id])?;
|
||||
return get_account_by_id(tx, &id);
|
||||
}
|
||||
|
||||
@@ -108,7 +112,7 @@ pub fn create_security_emitter_account(tx: &Transaction, sec: &SecurityId, user:
|
||||
}
|
||||
|
||||
pub fn is_owner(tx: &Transaction, account_id: &AccountId, user_id: &UserId) -> Result<bool> {
|
||||
let q = "SELECT id FROM accounts WHERE id = ?1 AND owner = ?2";
|
||||
let q = "SELECT id FROM account_user_permissions WHERE account_id = ?1 AND user_id = ?2";
|
||||
let params = params![account_id, user_id];
|
||||
let ite = |row: &Row| row.get::<usize, u32>(0);
|
||||
let option = tx.query_row(q, params, ite).optional()?;
|
||||
@@ -159,8 +163,8 @@ mod test_accounts {
|
||||
assert_eq!(acc.account_type, AccountType::Checking);
|
||||
assert_eq!(0, acc.raw_amount());
|
||||
|
||||
assert!(is_owner(& tx, & acc.id(), &user.id())?);
|
||||
assert!(!is_owner(& tx, & acc.id(), ¬_owner.id())?);
|
||||
assert!(is_owner(&tx, &acc.id(), &user.id())?);
|
||||
assert!(!is_owner(&tx, &acc.id(), ¬_owner.id())?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -176,8 +180,8 @@ mod test_accounts {
|
||||
assert_eq!(acc.account_type, AccountType::SecurityEmitter);
|
||||
assert_eq!(0, acc.raw_amount());
|
||||
|
||||
assert!(is_owner(& tx, & acc.id(), &user.id())?);
|
||||
assert!(!is_owner(& tx, & acc.id(), ¬_owner.id())?);
|
||||
assert!(is_owner(&tx, &acc.id(), &user.id())?);
|
||||
assert!(!is_owner(&tx, &acc.id(), ¬_owner.id())?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user