From d17c5dadc18ee75a36b70fb31caaf7b8cef89b3d Mon Sep 17 00:00:00 2001 From: anko9801 Date: Sat, 7 Sep 2024 11:07:57 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Repository=20=E3=81=AB?= =?UTF-8?q?=E3=81=82=E3=81=A3=E3=81=9F=E3=83=90=E3=83=AA=E3=83=87=E3=83=BC?= =?UTF-8?q?=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=92=20usecase=20=E3=81=A7?= =?UTF-8?q?=E8=A1=8C=E3=81=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/request/repository.ts | 8 -------- src/features/request/usecase.ts | 13 ++++++++++--- src/features/transaction/repository.ts | 8 -------- src/features/transaction/usecase.ts | 8 ++++++++ 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/features/request/repository.ts b/src/features/request/repository.ts index 4953acd0..c97b2e7f 100644 --- a/src/features/request/repository.ts +++ b/src/features/request/repository.ts @@ -25,14 +25,6 @@ export const useRequestRepository = () => { const createRequestRepository = () => ({ fetchRequests: async (querySeed: RequestQuerySeed): Promise => { - const rule = /^2[0-9]{3}-[0-9]{1,2}-[0-9]{1,2}$/ - if ( - (querySeed.since && !rule.test(querySeed.since)) || - (querySeed.until && !rule.test(querySeed.until)) - ) { - throw new Error('日付はyyyy-MM-ddの形式で入力してください') - } - const { data } = await apis.getRequests( querySeed.sort, querySeed.currentStatus !== '' ? querySeed.currentStatus : undefined, diff --git a/src/features/request/usecase.ts b/src/features/request/usecase.ts index 05f8ea24..5d7e1506 100644 --- a/src/features/request/usecase.ts +++ b/src/features/request/usecase.ts @@ -11,9 +11,16 @@ import { createTagIfNotExistUsecase } from '/@/features/tag/usecase' export const useFetchRequestsUsecase = async () => { const repository = useRequestRepository() - const { requests, isRequestFetched, filterParams } = storeToRefs( - useRequestStore() - ) + const { requests, isRequestFetched, filterParams } = + storeToRefs(useRequestStore()) + + const rule = /^2[0-9]{3}-[0-9]{1,2}-[0-9]{1,2}$/ + if ( + (filterParams.value.since && !rule.test(filterParams.value.since)) || + (filterParams.value.until && !rule.test(filterParams.value.until)) + ) { + throw new Error('日付はyyyy-MM-ddの形式で入力してください') + } try { requests.value = await repository.fetchRequests(filterParams.value) diff --git a/src/features/transaction/repository.ts b/src/features/transaction/repository.ts index 59a26ce8..7d5dc130 100644 --- a/src/features/transaction/repository.ts +++ b/src/features/transaction/repository.ts @@ -16,14 +16,6 @@ const createTransactionRepository = () => ({ fetchTransactions: async ( querySeed: TransactionQuerySeed ): Promise => { - const rule = /^2[0-9]{3}-[0-9]{1,2}-[0-9]{1,2}$/ - if ( - (querySeed.since && !rule.test(querySeed.since)) || - (querySeed.until && !rule.test(querySeed.until)) - ) { - throw new Error('日付はyyyy-MM-ddの形式で入力してください') - } - const { data } = await apis.getTransactions( querySeed.sort, querySeed.target, diff --git a/src/features/transaction/usecase.ts b/src/features/transaction/usecase.ts index 3195ac07..888eadf8 100644 --- a/src/features/transaction/usecase.ts +++ b/src/features/transaction/usecase.ts @@ -15,6 +15,14 @@ export const useFetchTransactionsUsecase = async () => { useTransactionStore() ) + const rule = /^2[0-9]{3}-[0-9]{1,2}-[0-9]{1,2}$/ + if ( + (filterParams.value.since && !rule.test(filterParams.value.since)) || + (filterParams.value.until && !rule.test(filterParams.value.until)) + ) { + throw new Error('日付はyyyy-MM-ddの形式で入力してください') + } + try { transactions.value = await repository.fetchTransactions(filterParams.value) isTransactionFetched.value = true