@samitouri / QOSami-HFS / commits / 0fd5d3e4

better code: sync way to know it failed or not

Massimo Melina committed Feb 8, 2025 at 00:11 UTC 0fd5d3e448ca2a430a67d84550be7625884f953e
2 files changed +3 -4
dev-plugins.md
+1 -1
@@ -294,7 +294,7 @@ The `api` object you get as parameter of the `init` contains the following:
294
295 - `getAccounts(): string[]` retrieve list of all usernames
296
297 -- `addAccount(username: string, properties: Partial<Account>, updateExisting=false): Account | undefined`
297 +- `addAccount(username: string, properties: Partial<Account>, updateExisting=false): Promise<Account> | undefined`
298 If username already exists, it will ignore the request and return undefined, unless you set `updateExisting` to true.
299
300 - `delAccount(username: string): boolean` returns true if it succeeds.
src/perm.ts
+2 -3
@@ -157,7 +157,7 @@ export function renameAccount(from: string, to: string) {
157 }
158 }
159
160 -export async function addAccount(username: string, props: Partial<Account>, updateExisting=false) {
160 +export function addAccount(username: string, props: Partial<Account>, updateExisting=false) {
161 username = normalizeUsername(username)
162 if (!username) return
163 let account = getAccount(username, false)
@@ -166,8 +166,7 @@ export async function addAccount(username: string, props: Partial<Account>, upda
166 Object.assign(account, _.pickBy(props, Boolean))
167 accountsConfig.set(accounts =>
168 Object.assign(accounts, { [username]: account }))
169 - await updateAccount(account, account)
170 - return account
169 + return updateAccount(account, account).then(() => account!)
170 }
171
172 export function delAccount(username: string) {