diff --git a/moneymgr_backend/src/extractors/auth_extractor.rs b/moneymgr_backend/src/extractors/auth_extractor.rs index d714bc6..f1940cf 100644 --- a/moneymgr_backend/src/extractors/auth_extractor.rs +++ b/moneymgr_backend/src/extractors/auth_extractor.rs @@ -141,10 +141,10 @@ impl FromRequest for AuthExtractor { // Check for authorization let uri = req.uri().to_string(); - let authorized = (uri.starts_with("/api/accounts/") && token.right_account) - || (uri.starts_with("/api/movements/") && token.right_movement) - || (uri.starts_with("/api/inbox/") && token.right_inbox) - || (uri.starts_with("/api/attachments/") && token.right_attachment) + let authorized = (uri.starts_with("/api/account") && token.right_account) + || (uri.starts_with("/api/movement") && token.right_movement) + || (uri.starts_with("/api/inbox") && token.right_inbox) + || (uri.starts_with("/api/attachment") && token.right_attachment) || (uri.starts_with("/api/auth/") && token.right_auth); if !authorized { diff --git a/moneymgr_web/src/api/AccountApi.ts b/moneymgr_web/src/api/AccountApi.ts index dc4c201..5c0758b 100644 --- a/moneymgr_web/src/api/AccountApi.ts +++ b/moneymgr_web/src/api/AccountApi.ts @@ -50,6 +50,19 @@ export class AccountApi { }); } + /** + * Create a new account + */ + static async Create(name: string): Promise { + await APIClient.exec({ + uri: `/account`, + method: "POST", + jsonData: { + name, + }, + }); + } + /** * Update account */ diff --git a/moneymgr_web/src/routes/AccountsRoute.tsx b/moneymgr_web/src/routes/AccountsRoute.tsx index 4977949..41595e2 100644 --- a/moneymgr_web/src/routes/AccountsRoute.tsx +++ b/moneymgr_web/src/routes/AccountsRoute.tsx @@ -20,6 +20,19 @@ export function AccountsRoute(): React.ReactElement { const list = accounts.list.list; + const createAccount = async () => { + try { + await AccountApi.Create(`New account #${list.length + 1}`); + + snackbar("New account successfully created!"); + + await accounts.reload(); + } catch (e) { + console.error("Failed to create new account!", e); + alert(`Failed to create new account! ${e}`); + } + }; + const setDefaultAccount = async (account: Account) => { try { await AccountApi.SetDefaultAccount(account); @@ -125,12 +138,12 @@ export function AccountsRoute(): React.ReactElement { actions={ - + - + accounts.reload()}>