opencode ergebnis V0.1
This commit is contained in:
1 parent
61d86a3d83
commit
7e498ebc3f
71 files changed
+28982
-46
No files matched your search
@@ -0,0 +1,66 @@
|
||||
"""
|
||||
Account Model - Abstraktionsschicht für Datenbankzugriffe
|
||||
"""
|
||||
from cmbnet.db import get_db
|
||||
|
||||
|
||||
class AccountModel:
|
||||
@staticmethod
|
||||
def get_all_by_tenant(tenant_id):
|
||||
db = get_db()
|
||||
return db.execute(
|
||||
'SELECT * FROM accounts WHERE tenant_id = ? ORDER BY id',
|
||||
(tenant_id,)
|
||||
).fetchall()
|
||||
|
||||
@staticmethod
|
||||
def get_by_id(account_id, tenant_id=None):
|
||||
db = get_db()
|
||||
if tenant_id:
|
||||
return db.execute(
|
||||
'SELECT * FROM accounts WHERE id = ? AND tenant_id = ?',
|
||||
(account_id, tenant_id)
|
||||
).fetchone()
|
||||
return db.execute('SELECT * FROM accounts WHERE id = ?', (account_id,)).fetchone()
|
||||
|
||||
@staticmethod
|
||||
def get_by_name_and_tenant(name, tenant_id):
|
||||
db = get_db()
|
||||
return db.execute(
|
||||
'SELECT * FROM accounts WHERE name = ? AND tenant_id = ?',
|
||||
(name, tenant_id)
|
||||
).fetchone()
|
||||
|
||||
@staticmethod
|
||||
def create(tenant_id, name, password_hash, role):
|
||||
db = get_db()
|
||||
cursor = db.execute(
|
||||
'INSERT INTO accounts (tenant_id, name, password_hash, role) VALUES (?, ?, ?, ?)',
|
||||
(tenant_id, name, password_hash, role)
|
||||
)
|
||||
db.commit()
|
||||
return cursor.lastrowid
|
||||
|
||||
@staticmethod
|
||||
def update_role(account_id, tenant_id, role):
|
||||
db = get_db()
|
||||
db.execute(
|
||||
'UPDATE accounts SET role = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? AND tenant_id = ?',
|
||||
(role, account_id, tenant_id)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
@staticmethod
|
||||
def set_password(account_id, tenant_id, password_hash):
|
||||
db = get_db()
|
||||
db.execute(
|
||||
'UPDATE accounts SET password_hash = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? AND tenant_id = ?',
|
||||
(password_hash, account_id, tenant_id)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
@staticmethod
|
||||
def delete(account_id, tenant_id):
|
||||
db = get_db()
|
||||
db.execute('DELETE FROM accounts WHERE id = ? AND tenant_id = ?', (account_id, tenant_id))
|
||||
db.commit()
|
||||
Reference in new issue
Block a user