Skip to content

Commit 4bcbd77

Browse files
committed
perf: add bulk import functionality for categories and expenses
1 parent 9bdfb86 commit 4bcbd77

11 files changed

Lines changed: 461 additions & 82 deletions

File tree

documentation/components/SettingsComponent.html

Lines changed: 95 additions & 66 deletions
Large diffs are not rendered by default.

documentation/coverage.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@
769769
<td>CategoryService</td>
770770
<td align="right" data-sort="100">
771771
<span class="coverage-percent">100 %</span>
772-
<span class="coverage-count">(9/9)</span>
772+
<span class="coverage-count">(10/10)</span>
773773
</td>
774774
</tr>
775775
<tr class="very-good">
@@ -805,7 +805,7 @@
805805
<td>ExpenseService</td>
806806
<td align="right" data-sort="100">
807807
<span class="coverage-percent">100 %</span>
808-
<span class="coverage-count">(9/9)</span>
808+
<span class="coverage-count">(10/10)</span>
809809
</td>
810810
</tr>
811811
<tr class="very-good">

documentation/injectables/CategoryService.html

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ <h6><b>Methods</b></h6>
165165
<li>
166166
<a href="#add" >add</a>
167167
</li>
168+
<li>
169+
<a href="#addBulk" >addBulk</a>
170+
</li>
168171
<li>
169172
<a href="#delete" >delete</a>
170173
</li>
@@ -348,6 +351,86 @@ <h3 id="methods">
348351
</tr>
349352
</tbody>
350353
</table>
354+
<table class="table table-sm table-bordered">
355+
<tbody>
356+
<tr>
357+
<td class="col-md-4">
358+
<a name="addBulk"></a>
359+
<span class="name">
360+
<span ><b>addBulk</b></span>
361+
<a href="#addBulk"><span class="icon ion-ios-link"></span></a>
362+
</span>
363+
</td>
364+
</tr>
365+
<tr>
366+
<td class="col-md-4">
367+
<code>addBulk(data: <a href="../interfaces/Category.html" target="_self">Omit&lt;Category, &quot;category_id&quot; | &quot;user_id&quot;&gt;[]</a>)</code>
368+
</td>
369+
</tr>
370+
371+
372+
<tr>
373+
<td class="col-md-4">
374+
<div class="io-line">Defined in <a href="" data-line="167"
375+
class="link-to-prism">src/app/service/localStorage/category.service.ts:167</a></div>
376+
</td>
377+
</tr>
378+
379+
380+
<tr>
381+
<td class="col-md-4">
382+
<div class="io-description"><p>Bulk-adds category records into localStorage.</p>
383+
<p>🔹 Behavior:</p>
384+
<ul>
385+
<li>Generates a new <code>category_id</code> for each category</li>
386+
<li>Assigns the currently logged-in user ID</li>
387+
<li>Appends imported categories to existing stored categories</li>
388+
</ul>
389+
</div>
390+
391+
<div class="io-description">
392+
<b>Parameters :</b>
393+
394+
<table class="params">
395+
<thead>
396+
<tr>
397+
<td>Name</td>
398+
<td>Type</td>
399+
<td>Optional</td>
400+
<td>Description</td>
401+
</tr>
402+
</thead>
403+
<tbody>
404+
<tr>
405+
<td>data</td>
406+
<td>
407+
<code><a href="../interfaces/Category.html" target="_self" >Omit&lt;Category, &quot;category_id&quot; | &quot;user_id&quot;&gt;[]</a></code>
408+
</td>
409+
410+
<td>
411+
No
412+
</td>
413+
414+
415+
<td>
416+
<p>List of category objects without <code>category_id</code> and <code>user_id</code></p>
417+
418+
</td>
419+
</tr>
420+
</tbody>
421+
</table>
422+
</div>
423+
<div class="io-description">
424+
<b>Returns : </b> <code><a href="https://www.typescriptlang.org/docs/handbook/basic-types.html" target="_blank" >void</a></code>
425+
426+
</div>
427+
<div class="io-description">
428+
429+
</div>
430+
</td>
431+
</tr>
432+
</tbody>
433+
</table>
351434
<table class="table table-sm table-bordered">
352435
<tbody>
353436
<tr>
@@ -881,6 +964,34 @@ <h3 id="methods">
881964
if (!this.isBrowser()) return;
882965
this.storageService.updateCategories(categories);
883966
}
967+
968+
/**
969+
* Bulk-adds category records into localStorage.
970+
*
971+
* 🔹 Behavior:
972+
* - Generates a new &#x60;category_id&#x60; for each category
973+
* - Assigns the currently logged-in user ID
974+
* - Appends imported categories to existing stored categories
975+
*
976+
* @param data List of category objects without &#x60;category_id&#x60; and &#x60;user_id&#x60;
977+
*/
978+
addBulk(data: Omit&lt;Category, &#x27;category_id&#x27; | &#x27;user_id&#x27;&gt;[]): void {
979+
if (!this.isBrowser()) return;
980+
981+
const all: Category[] &#x3D; this.getAll() ?? [];
982+
const user_id &#x3D; this.userService.getValue&lt;string&gt;(&#x27;id&#x27;) || &#x27;0&#x27;;
983+
984+
const imported: Category[] &#x3D; data.map(cat &#x3D;&gt; ({
985+
...cat,
986+
category_id: crypto.randomUUID(),
987+
user_id
988+
}));
989+
990+
localStorage.setItem(
991+
this.storageService.getCategoryKey(),
992+
JSON.stringify([...all, ...imported])
993+
);
994+
}
884995
}
885996
</code></pre>
886997
</div>

documentation/injectables/ExpenseService.html

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ <h6><b>Methods</b></h6>
169169
<li>
170170
<a href="#add" >add</a>
171171
</li>
172+
<li>
173+
<a href="#addBulk" >addBulk</a>
174+
</li>
172175
<li>
173176
<a href="#delete" >delete</a>
174177
</li>
@@ -335,6 +338,86 @@ <h3 id="methods">
335338
</tr>
336339
</tbody>
337340
</table>
341+
<table class="table table-sm table-bordered">
342+
<tbody>
343+
<tr>
344+
<td class="col-md-4">
345+
<a name="addBulk"></a>
346+
<span class="name">
347+
<span ><b>addBulk</b></span>
348+
<a href="#addBulk"><span class="icon ion-ios-link"></span></a>
349+
</span>
350+
</td>
351+
</tr>
352+
<tr>
353+
<td class="col-md-4">
354+
<code>addBulk(data: <a href="../interfaces/Expense.html" target="_self">Omit&lt;Expense, expense_id&gt;[]</a>)</code>
355+
</td>
356+
</tr>
357+
358+
359+
<tr>
360+
<td class="col-md-4">
361+
<div class="io-line">Defined in <a href="" data-line="185"
362+
class="link-to-prism">src/app/service/localStorage/expense.service.ts:185</a></div>
363+
</td>
364+
</tr>
365+
366+
367+
<tr>
368+
<td class="col-md-4">
369+
<div class="io-description"><p>Bulk-adds expense records into localStorage.</p>
370+
<p>🔹 Behavior:</p>
371+
<ul>
372+
<li>Generates a new unique <code>expense_id</code> for each expense</li>
373+
<li>Rounds the amount to 2 decimal places</li>
374+
<li>Appends imported expenses to existing stored expenses</li>
375+
</ul>
376+
</div>
377+
378+
<div class="io-description">
379+
<b>Parameters :</b>
380+
381+
<table class="params">
382+
<thead>
383+
<tr>
384+
<td>Name</td>
385+
<td>Type</td>
386+
<td>Optional</td>
387+
<td>Description</td>
388+
</tr>
389+
</thead>
390+
<tbody>
391+
<tr>
392+
<td>data</td>
393+
<td>
394+
<code><a href="../interfaces/Expense.html" target="_self" >Omit&lt;Expense, expense_id&gt;[]</a></code>
395+
</td>
396+
397+
<td>
398+
No
399+
</td>
400+
401+
402+
<td>
403+
<p>List of expense objects without <code>expense_id</code></p>
404+
405+
</td>
406+
</tr>
407+
</tbody>
408+
</table>
409+
</div>
410+
<div class="io-description">
411+
<b>Returns : </b> <code><a href="https://www.typescriptlang.org/docs/handbook/basic-types.html" target="_blank" >void</a></code>
412+
413+
</div>
414+
<div class="io-description">
415+
416+
</div>
417+
</td>
418+
</tr>
419+
</tbody>
420+
</table>
338421
<table class="table table-sm table-bordered">
339422
<tbody>
340423
<tr>
@@ -932,6 +1015,33 @@ <h3 id="methods">
9321015
return itemDate &gt;&#x3D; from &amp;&amp; itemDate &lt;&#x3D; to;
9331016
});
9341017
}
1018+
1019+
/**
1020+
* Bulk-adds expense records into localStorage.
1021+
*
1022+
* 🔹 Behavior:
1023+
* - Generates a new unique &#x60;expense_id&#x60; for each expense
1024+
* - Rounds the amount to 2 decimal places
1025+
* - Appends imported expenses to existing stored expenses
1026+
*
1027+
* @param data List of expense objects without &#x60;expense_id&#x60;
1028+
*/
1029+
addBulk(data: Omit&lt;Expense, &#x27;expense_id&#x27;&gt;[]): void {
1030+
if (!this.isBrowser()) return;
1031+
1032+
const all: Expense[] &#x3D; this.getAll() ?? [];
1033+
1034+
const imported: Expense[] &#x3D; data.map(exp &#x3D;&gt; ({
1035+
...exp,
1036+
expense_id: crypto.randomUUID(),
1037+
amount: Math.round(exp.amount * 100) / 100,
1038+
}));
1039+
1040+
localStorage.setItem(
1041+
this.storageService.getExpenseKey(),
1042+
JSON.stringify([...all, ...imported])
1043+
);
1044+
}
9351045
}
9361046
</code></pre>
9371047
</div>

documentation/interfaces/Category.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,34 @@ <h3 id="inputs">Properties</h3>
652652
if (!this.isBrowser()) return;
653653
this.storageService.updateCategories(categories);
654654
}
655+
656+
/**
657+
* Bulk-adds category records into localStorage.
658+
*
659+
* 🔹 Behavior:
660+
* - Generates a new &#x60;category_id&#x60; for each category
661+
* - Assigns the currently logged-in user ID
662+
* - Appends imported categories to existing stored categories
663+
*
664+
* @param data List of category objects without &#x60;category_id&#x60; and &#x60;user_id&#x60;
665+
*/
666+
addBulk(data: Omit&lt;Category, &#x27;category_id&#x27; | &#x27;user_id&#x27;&gt;[]): void {
667+
if (!this.isBrowser()) return;
668+
669+
const all: Category[] &#x3D; this.getAll() ?? [];
670+
const user_id &#x3D; this.userService.getValue&lt;string&gt;(&#x27;id&#x27;) || &#x27;0&#x27;;
671+
672+
const imported: Category[] &#x3D; data.map(cat &#x3D;&gt; ({
673+
...cat,
674+
category_id: crypto.randomUUID(),
675+
user_id
676+
}));
677+
678+
localStorage.setItem(
679+
this.storageService.getCategoryKey(),
680+
JSON.stringify([...all, ...imported])
681+
);
682+
}
655683
}
656684
</code></pre>
657685
</div>

documentation/interfaces/Expense.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,33 @@ <h3 id="inputs">Properties</h3>
912912
return itemDate &gt;&#x3D; from &amp;&amp; itemDate &lt;&#x3D; to;
913913
});
914914
}
915+
916+
/**
917+
* Bulk-adds expense records into localStorage.
918+
*
919+
* 🔹 Behavior:
920+
* - Generates a new unique &#x60;expense_id&#x60; for each expense
921+
* - Rounds the amount to 2 decimal places
922+
* - Appends imported expenses to existing stored expenses
923+
*
924+
* @param data List of expense objects without &#x60;expense_id&#x60;
925+
*/
926+
addBulk(data: Omit&lt;Expense, &#x27;expense_id&#x27;&gt;[]): void {
927+
if (!this.isBrowser()) return;
928+
929+
const all: Expense[] &#x3D; this.getAll() ?? [];
930+
931+
const imported: Expense[] &#x3D; data.map(exp &#x3D;&gt; ({
932+
...exp,
933+
expense_id: crypto.randomUUID(),
934+
amount: Math.round(exp.amount * 100) / 100,
935+
}));
936+
937+
localStorage.setItem(
938+
this.storageService.getExpenseKey(),
939+
JSON.stringify([...all, ...imported])
940+
);
941+
}
915942
}
916943
</code></pre>
917944
</div>

documentation/js/search/search_index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/dev.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ ng g c component-name
3737

3838
## Create a Service
3939

40-
ng g s service-name
40+
ng g s service-name
41+
42+
### Commit Message Tips
43+
- Use feat: → new feature
44+
- Use fix: → bug fix
45+
- Use perf: → performance improvements
46+
- Use refactor: → code cleanup

0 commit comments

Comments
 (0)