@@ -20,7 +20,7 @@ const createLog = async ({
20
20
description,
21
21
date,
22
22
} ) => {
23
- const currentLogs = getLogsFromStoreByUserId ( userId ) ;
23
+ const currentLogs = await getLogsByUserId ( userId ) ;
24
24
const newLog = {
25
25
id : currentLogs . length + 1 ,
26
26
title,
@@ -30,16 +30,10 @@ const createLog = async ({
30
30
date,
31
31
} ;
32
32
const newLogs = [ ...currentLogs , newLog ] ;
33
- localStorageStore . saveToStore (
34
- prefixLogStoreKey ( userId ) ,
35
- JSON . stringify ( newLogs ) ,
36
- ) ;
33
+ saveLogsToStoreByUserId ( userId , newLogs ) ;
37
34
} ;
38
35
39
36
const getLogsByUserId = async ( userId ) => {
40
- if ( userId === 'admin' ) {
41
- return mockData . LOG_ENTRIES ;
42
- }
43
37
return getLogsFromStoreByUserId ( userId ) ;
44
38
} ;
45
39
@@ -65,8 +59,24 @@ const getLogsFromStoreByUserId = (userId) => {
65
59
return rawLogs ? JSON . parse ( rawLogs ) : [ ] ;
66
60
} ;
67
61
62
+ const saveLogsToStoreByUserId = ( userId , logs ) => {
63
+ localStorageStore . saveToStore (
64
+ prefixLogStoreKey ( userId ) ,
65
+ JSON . stringify ( logs ) ,
66
+ ) ;
67
+ } ;
68
+
68
69
const prefixLogStoreKey = ( userId ) => `${ CREATED_LOG_STORE_KEY } -${ userId } ` ;
69
70
71
+ const loadAdminLogs = async ( ) => {
72
+ const userId = 'admin' ;
73
+ const adminLogs = await getLogsByUserId ( 'admin' ) ;
74
+ if ( adminLogs . length === 0 ) {
75
+ saveLogsToStoreByUserId ( userId , mockData . LOG_ENTRIES ) ;
76
+ }
77
+ } ;
78
+ loadAdminLogs ( ) ;
79
+
70
80
export const logService = {
71
81
getMoodOptions,
72
82
getPriorityOptions,
0 commit comments