@@ -4,7 +4,6 @@ import { addPendingStaff, getPendingStaffs, removePendingByEmail } from '@/servi
44import type { Staff } from '@/features/staff/types'
55import type { StaffSchema } from '@/features/staff/validation'
66
7- // 1. Definição da Interface do Storage
87export interface StaffStorage {
98 list ( ) : Promise < Staff [ ] > ;
109 create ( data : StaffSchema ) : Promise < { synced : boolean ; error ?: string } > ;
@@ -13,15 +12,13 @@ export interface StaffStorage {
1312 delete ( id : string ) : Promise < void > ;
1413}
1514
16- // Utilitário de Timeout
1715function withTimeout < T > ( promise : Promise < T > , ms = 30000 ) : Promise < T > {
1816 const timeout = new Promise < never > ( ( _ , reject ) =>
19- setTimeout ( ( ) => reject ( new Error ( 'Timeout: Banco de dados não respondeu .' ) ) , ms )
17+ setTimeout ( ( ) => reject ( new Error ( 'Timeout de conexão com o banco .' ) ) , ms )
2018 )
2119 return Promise . race ( [ promise , timeout ] )
2220}
2321
24- // Utilitário de Log Remoto
2522async function logRemoteError ( context : string , error : unknown ) {
2623 if ( ! isFirebaseConfigured ) return
2724 try {
@@ -38,7 +35,6 @@ async function logRemoteError(context: string, error: unknown) {
3835 }
3936}
4037
41- // 2. Implementação Firebase (Online)
4238export const FirebaseStorage : StaffStorage = {
4339 async list ( ) : Promise < Staff [ ] > {
4440 const pending = getPendingStaffs ( )
@@ -66,7 +62,7 @@ export const FirebaseStorage: StaffStorage = {
6662 async create ( data : StaffSchema ) : Promise < { synced : boolean ; error ?: string } > {
6763 if ( ! isFirebaseConfigured ) {
6864 addPendingStaff ( data )
69- return { synced : false , error : 'Firebase não configurado ' }
65+ return { synced : false , error : 'Firebase offline ' }
7066 }
7167
7268 try {
@@ -120,22 +116,21 @@ export const FirebaseStorage: StaffStorage = {
120116 }
121117}
122118
123- // 3. Implementação Local (Offline Fallback Permanente)
124119export const LocalOnlyStorage : StaffStorage = {
125120 async list ( ) : Promise < Staff [ ] > {
126121 return getPendingStaffs ( )
127122 } ,
128123 async create ( data : StaffSchema ) : Promise < { synced : boolean ; error ?: string } > {
129124 addPendingStaff ( data )
130- return { synced : false , error : 'Modo Offline' }
125+ return { synced : false , error : 'Offline' }
131126 } ,
132127 async sync ( ) : Promise < boolean > {
133128 return false
134129 } ,
135130 async update ( ) : Promise < void > {
136- console . warn ( 'Update not supported in LocalOnly mode ' )
131+ console . warn ( 'Update local not supported' )
137132 } ,
138133 async delete ( ) : Promise < void > {
139- console . warn ( 'Delete not supported in LocalOnly mode ' )
134+ console . warn ( 'Delete local not supported' )
140135 }
141136}
0 commit comments