dyomedea/src/db/account.ts

25 lines
726 B
TypeScript
Raw Normal View History

2022-12-25 15:30:47 +00:00
import { getFamily, put } from './lib';
import getUri from '../lib/ids';
export const initialAccount = {
id: 'initial',
name: '???',
localDb: 'dyomedea',
};
2022-12-25 15:30:47 +00:00
export const getAccounts = async () => {
const accountDocs = await getFamily('account', { include_docs: true }, true);
return accountDocs.rows.map((row: any) => row.doc.doc);
2022-12-25 15:30:47 +00:00
};
2022-12-26 16:31:05 +00:00
export const putAccount = async (params: any) => {
const { id, account } = params;
const uri = getUri('account', { account: id });
2022-12-25 15:30:47 +00:00
return await put(uri, 'account', (_: any) => account, {}, true);
};
export const getAccountById = (accounts: any, id: string) => {
const targetAccounts: any[] = accounts.filter((acc: any) => acc.id === id);
return targetAccounts[0];
};