@@ -13,7 +13,7 @@ import {
1313 createAggregationExpenseRowWithDelimiter ,
1414 createTrackingExpenseRowWithConfig ,
1515 extractExpenseRowFromCsvRow ,
16- stringifyShortcutList
16+ stringifyShortcutList ,
1717} from './expensesHelper'
1818import type { Config , ExpenseTrackingRow } from './expensesModels'
1919import { amountOk , categoryOk , validateConfig } from './expensesChecks'
@@ -29,9 +29,7 @@ const CONFIG_KEYS = {
2929 fixedExpenses : 'fixedExpenses' ,
3030}
3131
32- const TRACKING_MODE = [
33- 'Individual' , 'Shortcuts' , 'Fixed'
34- ]
32+ const TRACKING_MODE = [ 'Individual' , 'Shortcuts' , 'Fixed' ]
3533
3634// if there is no config in the '_configuration' file, then provide an example config
3735const EXAMPLE_CONFIG = `
@@ -154,16 +152,14 @@ const expensesAggregate = async (): Promise<boolean> => {
154152 const year = Number ( await CommandBar . showInput ( 'Please type in the year to aggregate' , 'Start aggregate' ) )
155153
156154 const noteTitleTracking = `${ year } Expenses Tracking`
157- if ( ! await provideAndCheckNote ( noteTitleTracking , config . folderPath , false , year ) ) {
155+ if ( ! ( await provideAndCheckNote ( noteTitleTracking , config . folderPath , false , year ) ) ) {
158156 return false
159157 }
160158
161159 const trackingNote = DataStore . projectNoteByTitle ( noteTitleTracking ) ?. [ 0 ]
162160
163161 if ( trackingNote ) {
164- const trackedData = trackingNote . paragraphs
165- . filter ( para => ! para . rawContent . startsWith ( '#' ) )
166- . map ( para => extractExpenseRowFromCsvRow ( para . rawContent , config ) )
162+ const trackedData = trackingNote . paragraphs . filter ( ( para ) => ! para . rawContent . startsWith ( '#' ) ) . map ( ( para ) => extractExpenseRowFromCsvRow ( para . rawContent , config ) )
167163
168164 if ( ! checkDataQualityBeforeAggregate ( trackedData , year , config ) ) {
169165 return false
@@ -172,7 +168,7 @@ const expensesAggregate = async (): Promise<boolean> => {
172168 const aggregatedData = aggregateByCategoriesAndMonth ( trackedData , config . delimiter )
173169
174170 const noteTitleAggregate = `${ year } Expenses Aggregate`
175- if ( ! await provideAndCheckNote ( noteTitleAggregate , config . folderPath , true ) ) {
171+ if ( ! ( await provideAndCheckNote ( noteTitleAggregate , config . folderPath , true ) ) ) {
176172 return false
177173 }
178174
@@ -182,9 +178,9 @@ const expensesAggregate = async (): Promise<boolean> => {
182178 await Editor . openNoteByTitle ( noteTitleAggregate )
183179 const note = Editor . note
184180 if ( note ) {
185- note . removeParagraphs ( note . paragraphs . filter ( para => ! para . rawContent . startsWith ( '#' ) ) )
181+ note . removeParagraphs ( note . paragraphs . filter ( ( para ) => ! para . rawContent . startsWith ( '#' ) ) )
186182 // add results
187- aggregatedData . forEach ( aggregated => {
183+ aggregatedData . forEach ( ( aggregated ) => {
188184 if ( aggregated . year ) {
189185 lines . push ( createAggregationExpenseRowWithDelimiter ( aggregated , config ) )
190186 }
@@ -214,12 +210,12 @@ const individualTracking = async (): Promise<boolean> => {
214210
215211 const title = `${ getYear ( currentDate ) } Expenses Tracking`
216212
217- if ( ! await provideAndCheckNote ( title , config . folderPath , true ) ) {
213+ if ( ! ( await provideAndCheckNote ( title , config . folderPath , true ) ) ) {
218214 return false
219215 }
220216
221217 const category = await CommandBar . showOptions ( config . categories , 'Please choose category' )
222- const text = await getInputTrimmed ( 'Please type in some text (no semicolon)' , 'Add text to expenses line' )
218+ const text = await getInputTrimmed ( 'Please type in some text (no semicolon)' , 'Add text to expenses line' , 'What was it?' )
223219 let amount = await inputNumber ( 'Please type in amount' )
224220
225221 let amountCheck = amountOk ( amount )
@@ -244,7 +240,7 @@ const individualTracking = async (): Promise<boolean> => {
244240 }
245241 if ( note ) {
246242 note . appendParagraph ( createTrackingExpenseRowWithConfig ( expenseRow , config ) , 'text' )
247- await CommandBar . showOptions ( [ 'OK' ] , 'Individual Expenses saved' )
243+ await CommandBar . showOptions ( [ 'OK' ] , 'Individual Expenses saved' )
248244 }
249245
250246 return true
@@ -266,7 +262,7 @@ const shortcutsTracking = async (): Promise<boolean> => {
266262
267263 const title = `${ getYear ( currentDate ) } Expenses Tracking`
268264
269- if ( ! await provideAndCheckNote ( title , config . folderPath , true ) ) {
265+ if ( ! ( await provideAndCheckNote ( title , config . folderPath , true ) ) ) {
270266 return false
271267 }
272268
@@ -305,7 +301,7 @@ const shortcutsTracking = async (): Promise<boolean> => {
305301 }
306302 if ( note ) {
307303 note . appendParagraph ( createTrackingExpenseRowWithConfig ( expenseRow , config ) , 'text' )
308- await CommandBar . showOptions ( [ 'OK' ] , 'Shortcut Expenses saved' )
304+ await CommandBar . showOptions ( [ 'OK' ] , 'Shortcut Expenses saved' )
309305 }
310306
311307 return true
@@ -327,7 +323,7 @@ const fixedTracking = async (): Promise<boolean> => {
327323
328324 const title = `${ getYear ( currentDate ) } Expenses Tracking`
329325
330- if ( ! await provideAndCheckNote ( title , config . folderPath , true ) ) {
326+ if ( ! ( await provideAndCheckNote ( title , config . folderPath , true ) ) ) {
331327 return false
332328 }
333329
@@ -337,14 +333,14 @@ const fixedTracking = async (): Promise<boolean> => {
337333
338334 const note = DataStore . projectNoteByTitle ( title ) ?. [ 0 ]
339335 config . fixedExpenses
340- . filter ( exp => exp . active && ( exp . month === 0 || exp . month === month ) )
341- . map ( exp => {
336+ . filter ( ( exp ) => exp . active && ( exp . month === 0 || exp . month === month ) )
337+ . map ( ( exp ) => {
342338 if ( ! categoryOk ( exp . category , config . categories ) ) {
343339 exp . category = `>>WRONG CATEGORY (${ exp . category } )<<`
344340 }
345341 return exp
346342 } )
347- . forEach ( exp => {
343+ . forEach ( ( exp ) => {
348344 const expenseRow = {
349345 date : currentDate ,
350346 category : exp . category ,
@@ -356,7 +352,7 @@ const fixedTracking = async (): Promise<boolean> => {
356352
357353 if ( note ) {
358354 note . appendParagraph ( lines . join ( '\n' ) , 'text' )
359- await CommandBar . showOptions ( [ 'OK' ] , 'Fixed Expenses saved' )
355+ await CommandBar . showOptions ( [ 'OK' ] , 'Fixed Expenses saved' )
360356 }
361357
362358 return true
@@ -378,23 +374,18 @@ const provideConfig = async (): Promise<any> => {
378374 throw new Error ( `Cannot find settings for Expenses plugin` )
379375 }
380376 return fromSettings
381- }
382- catch ( err ) {
377+ } catch ( err ) {
383378 logError ( pluginJson , `${ err . name } : ${ err . message } ` )
384379 return null // for completeness
385380 }
386-
387381}
388382
389383/**
390384 * check if one note exists by name, if mulitple exists - throw error, of none extist -> create it
391385 *
392386 * @private
393387 */
394- const provideAndCheckNote = async ( title : string ,
395- folderPath : string ,
396- createNote : boolean ,
397- year ?: number ) : Promise < boolean > => {
388+ const provideAndCheckNote = async ( title : string , folderPath : string , createNote : boolean , year ?: number ) : Promise < boolean > => {
398389 const notes = DataStore . projectNoteByTitle ( title )
399390
400391 // create note if it de
@@ -444,7 +435,6 @@ const checkDataQualityBeforeAggregate = (rows: ExpenseTrackingRow[], year: numbe
444435 logError ( pluginJson , `amount at: ${ createTrackingExpenseRowWithConfig ( row , config ) } ` )
445436 return false
446437 }
447-
448438 }
449439
450440 return true
0 commit comments