import { Injectable } from "@angular/core" ; import { STORAGE_KEYS } from "../config/storage_keys.config" ; import { LocalUser } from "../models/local_user" ; import { Cart } from "../models/cart" ; @ Injectable ( ) export class StorageService { getLocalUser ( ) { let usr = localStorage . getItem ( STORAGE_KEYS . localUser ) ; if ( usr == null ) { return null ; } else { return JSON . parse ( usr ) ; } } setLocalUser ( obj ) { if ( obj == null ) { localStorage . removeItem ( STORAGE_KEYS . localUser ) ; } else { localStorage . setItem ( STORAGE_KEYS . localUser , JSON . stringify ( obj ) ) ; } } getCart ( ) { let str = localStorage . getItem ( STORAGE_KEYS . cart ) ; if ( str != null ) { return JSON . parse ( str ) ; } else { return null ; } } setCart ( obj ) { if ( obj != null ) { localStorage . setItem ( STORAGE_KEYS . cart , JSON . stringify ( obj ) ) ; } else { localStorage . removeItem ( STORAGE_KEYS . cart ) ; } } }