Skip to content

Commit

Permalink
Reduce ESLint error
Browse files Browse the repository at this point in the history
  • Loading branch information
azuki774 committed Sep 10, 2024
1 parent 46304cf commit 0d15f25
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 79 deletions.
9 changes: 4 additions & 5 deletions components/PostRecord.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<script setup lang='ts'>
import type { Category } from '@/interfaces'
const config = useRuntimeConfig() // nuxt.config.ts に書いてあるコンフィグを読み出す
const selector = ref<any>()
const categoryList = ref<Category[]>()
const asyncData = await useFetch(
'/api/getCategories',
{
key: `/api/getCategories`,
}
},
)
const data = asyncData.data.value as Category[]
// category 加工
if (data != undefined) { // 取得済の場合のみ
for (let d of data) {
for (const d of data) {
// 100, category_name -> 100:category_name という表示に
// ただし加工済の場合は skip
if (d.category_name[3] != ':') {
Expand All @@ -29,7 +28,7 @@ categoryList.value = data
const priceBox = ref<number>()
const postButton = async (): Promise<void> => {
const asyncDataBtn = await useAsyncData(
await useAsyncData(
`record`,
(): Promise<any> => {
const send_category_id = selector.value.slice(0, 3) // 210-食費→210
Expand All @@ -38,7 +37,7 @@ const postButton = async (): Promise<void> => {
const localurl = '/api/postRecord' + paramStr
const response = $fetch(localurl)
return response
}
},
)
location.reload()
}
Expand Down
15 changes: 5 additions & 10 deletions components/History.vue → components/ShowHistory.vue
Original file line number Diff line number Diff line change
@@ -1,44 +1,39 @@
<script setup lang='ts'>
import type { Record } from '@/interfaces'
const config = useRuntimeConfig() // nuxt.config.ts に書いてあるコンフィグを読み出す
const recordList = ref<Record[]>()
const asyncData = await useFetch(
'/api/history',
{
key: `/api/history`,
}
},
)
const data = asyncData.data.value as Record[]
// fetchデータを整形
if (data != undefined) { // 取得済の場合のみ
for (let d of data) {
for (const d of data) {
d.datetime = d.datetime.slice(0, 19) // 2023-09-23T00:00:00+09:00 -> 2023-09-23T00:00:00
}
}
recordList.value = data
async function showDeleteDialog(id: number): Promise<void> {
const userResponse: boolean = confirm('このデータを削除しますか')
if (userResponse == true) {
console.log('delete: id=' + id)
const asyncDataBtn = await useAsyncData(
await useAsyncData(
`record`,
(): Promise<any> => {
const param = { 'id': id }
const param = { id: id }
const paramStr = '?id=' + param['id']
const localurl = '/api/deleteRecord' + paramStr
const response = $fetch(localurl)
return response
}
},
)
location.reload()
}
}
</script>
Expand Down
11 changes: 5 additions & 6 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: '2024-04-03',
css: ["bootstrap/dist/css/bootstrap.min.css"],
css: ['bootstrap/dist/css/bootstrap.min.css'],
devtools: { enabled: true },
routeRules: {
"/": { ssr: false },
'/': { ssr: false },
},
runtimeConfig: {
public: { // 外部から取得するにはpublic が必要
mawinterApi: "http://mawinter-api", // .env の NUXT_PUBLIC_API_BASE_ENDPOINT から取得
}
mawinterApi: 'http://mawinter-api', // .env の NUXT_PUBLIC_API_BASE_ENDPOINT から取得
},
},
modules: [
'@nuxt/eslint'
'@nuxt/eslint',
],

})
9 changes: 3 additions & 6 deletions pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<script setup lang='ts'>
import type Year from './summary/[year].vue'
const today = new Date()
let thisYear = today.getFullYear()
const thisYear = today.getFullYear()
</script>


<template>
<h1>mawinter-front</h1>
<section>
<h1>mawinter-front</h1>
<p text-alignment='center'>
<h2>登録</h2>
<PostRecord />
Expand All @@ -22,7 +19,7 @@ let thisYear = today.getFullYear()

<p text-alignment='center'>
<h2>直近履歴</h2>
<History />
<ShowHistory />
</p>
</section>
</template>
Expand Down
47 changes: 22 additions & 25 deletions pages/summary/[year].vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang='ts'>
import type { SummaryOne } from '@/interfaces'
const config = useRuntimeConfig() // nuxt.config.ts に書いてあるコンフィグを読み出す
const incomeList = ref<SummaryOne[]>()
const incomeSumList = ref<SummaryOne>()
const outgoingList = ref<SummaryOne[]>()
Expand All @@ -16,10 +15,10 @@ const asyncData = await useFetch(
{
key: `/api/summary`,
transform: (data: SummaryOne[]): SummaryOne[][] => {
let incomeArray: SummaryOne[] = []
let outgoingArray: SummaryOne[] = []
let investArray: SummaryOne[] = []
for (let d of data) {
const incomeArray: SummaryOne[] = []
const outgoingArray: SummaryOne[] = []
const investArray: SummaryOne[] = []
for (const d of data) {
if ([100, 101, 110].includes(d.category_id)) {
incomeArray.push(d)
}
Expand All @@ -32,12 +31,10 @@ const asyncData = await useFetch(
}
const retArray: SummaryOne[][] = [incomeArray, outgoingArray, investArray]
return retArray
}
}
},
},
)
if (asyncData.data.value != undefined) {
const incomeData = asyncData.data.value[0] as SummaryOne[]
const outgoingData = asyncData.data.value[1] as SummaryOne[]
Expand All @@ -47,17 +44,17 @@ if (asyncData.data.value != undefined) {
investList.value = investData
// sum の計算(income)
let incomeSumData: SummaryOne = {
const incomeSumData: SummaryOne = {
category_id: 999,
category_name: '収入合計',
price: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
total: 0
total: 0,
}
for (let i: number = 0; i < 12; i++) {
let sum: number = 0
let totalsum: number = 0
for (let d of incomeData) {
for (const d of incomeData) {
sum += d.price[i]
totalsum += d.price[i]
}
Expand All @@ -67,16 +64,16 @@ if (asyncData.data.value != undefined) {
incomeSumList.value = incomeSumData
// sum の計算(outgoing)
let outgoingSumData: SummaryOne = {
const outgoingSumData: SummaryOne = {
category_id: 999,
category_name: '支出合計',
price: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
total: 0
total: 0,
}
for (let i: number = 0; i < 12; i++) {
let sum: number = 0
let totalsum: number = 0
for (let d of outgoingData) {
for (const d of outgoingData) {
sum += d.price[i]
totalsum += d.price[i]
}
Expand All @@ -86,17 +83,17 @@ if (asyncData.data.value != undefined) {
outgoingSumList.value = outgoingSumData
// sum の計算(invest)
let investSumData: SummaryOne = {
const investSumData: SummaryOne = {
category_id: 999,
category_name: '投資合計',
price: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
total: 0
total: 0,
}
for (let i: number = 0; i < 12; i++) {
let sum: number = 0
let totalsum: number = 0
for (let d of investData) {
for (const d of investData) {
sum += d.price[i]
totalsum += d.price[i]
}
Expand All @@ -106,11 +103,11 @@ if (asyncData.data.value != undefined) {
investSumList.value = investSumData
// 合計テーブル用の計算
let AllSumData: SummaryOne = {
const AllSumData: SummaryOne = {
category_id: 999,
category_name: '合計',
price: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
total: 0
total: 0,
}
for (let i: number = 0; i < 12; i++) {
Expand All @@ -119,11 +116,11 @@ if (asyncData.data.value != undefined) {
AllSumData.total = incomeSumData.total - outgoingSumData.total - investSumData.total
AllSumList.value = AllSumData
let AllSumWithoutInvestData: SummaryOne = {
const AllSumWithoutInvestData: SummaryOne = {
category_id: 999,
category_name: '合計(投資除く)',
price: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
total: 0
total: 0,
}
for (let i: number = 0; i < 12; i++) {
Expand All @@ -138,8 +135,8 @@ if (asyncData.data.value != undefined) {
</script>

<template>
<h1>サマリー表示</h1>
<div class='container'>
<h1>サマリー表示</h1>
<a href='../'>トップに戻る</a>

<h2>合計</h2>
Expand Down Expand Up @@ -494,11 +491,11 @@ if (asyncData.data.value != undefined) {
<th scope='col' style='width: 5%'>1月</th>
<th scope='col' style='width: 5%'>2月</th>
<th scope='col' style='width: 5%'>3月</th>
<th scope='col' style='width: 7%''>合計</th>
<th scope='col' style='width: 7%'>合計</th>
</tr>
</thead>
<tbody>
<tr v-for=' invest in investList'>
<tr v-for='invest in investList'>
<td>{{ invest.category_id }}</td>
<td>{{ invest.category_name }}</td>
<td>
Expand Down
8 changes: 4 additions & 4 deletions server/api/deleteRecord.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export default defineEventHandler ( async (event) => {
export default defineEventHandler (async (event) => {
const config = useRuntimeConfig()
const query = getQuery(event)
const url = config.public.mawinterApi + "/v2/record/" + query.id
const url = config.public.mawinterApi + '/v2/record/' + query.id
const result = await $fetch(url,
{
method: "DELETE",
}
method: 'DELETE',
},
)
return result
})
8 changes: 4 additions & 4 deletions server/api/getCategories.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default defineEventHandler ( async (event) => {
export default defineEventHandler (async () => {
const config = useRuntimeConfig()
const url = config.public.mawinterApi + "/categories"
const url = config.public.mawinterApi + '/categories'
const result = await $fetch(url,
{
method: "GET",
}
method: 'GET',
},
)
return result
})
18 changes: 9 additions & 9 deletions server/api/history.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default defineEventHandler ( async (event) => {
const config = useRuntimeConfig()
const url = config.public.mawinterApi + "/v2/record"
const result = await $fetch(url,
{
method: "GET",
}
)
return result
export default defineEventHandler (async () => {
const config = useRuntimeConfig()
const url = config.public.mawinterApi + '/v2/record'
const result = await $fetch(url,
{
method: 'GET',
},
)
return result
})
11 changes: 5 additions & 6 deletions server/api/postRecord.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default defineEventHandler ( async (event) => {
export default defineEventHandler (async (event) => {
const config = useRuntimeConfig()
const query = getQuery(event)
// create body
Expand All @@ -10,13 +10,12 @@ export default defineEventHandler ( async (event) => {
"memo":"手動"
}
`
console.log(reqbody)
const url = config.public.mawinterApi + "/v2/record"
const url = config.public.mawinterApi + '/v2/record'
const result = await $fetch(url,
{
method: "POST",
body: reqbody
}
method: 'POST',
body: reqbody,
},
)
return result
})
8 changes: 4 additions & 4 deletions server/api/summary.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default defineEventHandler ( async (event) => {
export default defineEventHandler (async () => {
const config = useRuntimeConfig()
const url = config.public.mawinterApi + "/v2/record/summary/2024"
const url = config.public.mawinterApi + '/v2/record/summary/2024'
const result = await $fetch(url,
{
method: "GET",
}
method: 'GET',
},
)
return result
})

0 comments on commit 0d15f25

Please sign in to comment.