From 2894f6bf244f66fa64ba8915db18763e78ef03c9 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 24 Apr 2021 20:33:45 +0300 Subject: feat: add accounts service --- src/hooks/useAPIClient.ts | 4 ++-- src/services/accounts/index.ts | 19 +++++++++++++++++++ src/services/index.ts | 2 ++ src/services/types.ts | 6 ++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/services/accounts/index.ts 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 = (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; + 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 = { + 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; -- cgit v1.2.3