summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-04-24 20:33:45 +0300
committereug-vs <eug-vs@keemail.me>2021-04-24 20:34:45 +0300
commit2894f6bf244f66fa64ba8915db18763e78ef03c9 (patch)
treea9535e6265e5ad6a538a95b156eb58067021f608
parentdfcad777da36002f9ec6350d7a7a07ebf4a1ada6 (diff)
downloadcommercel-ui-2894f6bf244f66fa64ba8915db18763e78ef03c9.tar.gz
feat: add accounts service
-rw-r--r--src/hooks/useAPIClient.ts4
-rw-r--r--src/services/accounts/index.ts19
-rw-r--r--src/services/index.ts2
-rw-r--r--src/services/types.ts6
4 files changed, 29 insertions, 2 deletions
diff --git a/src/hooks/useAPIClient.ts b/src/hooks/useAPIClient.ts
index fd3ee19..72997f5 100644
--- a/src/hooks/useAPIClient.ts
+++ b/src/hooks/useAPIClient.ts
@@ -29,8 +29,8 @@ const registerServiceHooks = <Item = any>(service: string): void => {
if (!result.data && result.isValidating) {
// If we are waiting for the first result, check if we can maybe
// get the data from already cached list for the time-being
- const item = _.find(preloadedItems, { _id });
- return { ...result, data: item } as Response<Item>;
+ const item = _.find(preloadedItems, { _id }) as Item;
+ return { ...result, data: item };
}
return result;
};
diff --git a/src/services/accounts/index.ts b/src/services/accounts/index.ts
new file mode 100644
index 0000000..fc3a830
--- /dev/null
+++ b/src/services/accounts/index.ts
@@ -0,0 +1,19 @@
+import { ServiceParams } from '../../lib/ServiceContext';
+import { Account } from '../types';
+
+const service: ServiceParams<Account> = {
+ route: 'accounts',
+ name: 'Счета',
+ nameSingular: 'Счёт',
+ tableFields: [
+ { key: 'name', label: 'Название' },
+ { key: 'balance', label: 'Баланс' },
+ ],
+ searchBy: ['name'],
+ default: {
+ name: '',
+ balance: 0,
+ },
+};
+
+export default service;
diff --git a/src/services/index.ts b/src/services/index.ts
index 2b0b17b..df2305c 100644
--- a/src/services/index.ts
+++ b/src/services/index.ts
@@ -1,3 +1,4 @@
+import accounts from './accounts';
import contractors from './contractors';
import waybills from './waybills';
import transfers from './transfers';
@@ -9,6 +10,7 @@ const services = [
products,
waybills,
transfers,
+ accounts,
];
services.forEach(service => registerServiceHooks(service.route));
diff --git a/src/services/types.ts b/src/services/types.ts
index e6e01db..6fa5f30 100644
--- a/src/services/types.ts
+++ b/src/services/types.ts
@@ -4,6 +4,12 @@ interface BaseModel {
updatedAt: string;
}
+export interface Account extends BaseModel {
+ name: string;
+ code: string;
+ balance: number;
+}
+
export interface Contractor extends BaseModel {
name: string;
vatId: string;