-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ExameStore and integrate with MainPage; update dependencies…
… and add ExameService
- Loading branch information
Showing
9 changed files
with
137 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { ExameService } from './exame.service'; | ||
|
||
describe('ExameService', () => { | ||
let service: ExameService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(ExameService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class ExameService { | ||
|
||
constructor() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { inject } from "@angular/core" | ||
import { patchState, signalStore, withMethods, withState } from "@ngrx/signals" | ||
import { Exame, STEP, TAREFAS, Usuario } from "../models" | ||
import { ExameService } from "../services/exame.service" | ||
import { AuthService } from "../services/auth.service" | ||
|
||
export type ExameState = { | ||
user: Usuario | ||
error: Error | ||
message: string | ||
action: TAREFAS | ||
status: STEP | ||
listaExames: Exame[] | ||
materialAtual: string | ||
} | ||
|
||
const initialState: ExameState = { | ||
user: null, | ||
error: null, | ||
message: "Receber material na secretaria do SETEC", | ||
action: TAREFAS.RECEBER_MATERIAL, | ||
status: STEP.RECEBER_MATERIAL, | ||
listaExames: [], | ||
materialAtual: "", | ||
} | ||
|
||
export type ExameStore = InstanceType<typeof ExameStore> | ||
export const ExameStore = signalStore( | ||
{ providedIn: "root" }, | ||
withState(initialState), | ||
withMethods( | ||
(store, exameService: ExameService = inject(ExameService), authService: AuthService = inject(AuthService)) => ({ | ||
handleError(error: any) { | ||
let errorMesage = "Algo inesperado aconteceu. Tente novamente mais tarde" | ||
if (error.code === "Auth/invalid-credential") errorMesage = "Credenciais inválidas" | ||
patchState(store, { user: null, status: STEP.RECEBER_MATERIAL, error: { ...error, message: errorMesage } }) | ||
}, | ||
changeAction(action: TAREFAS) { | ||
patchState(store, { action }) | ||
}, | ||
async login(credentials: { email: string; password: string }) { | ||
try { | ||
const user = authService.getUsuarioAtual() | ||
patchState(store, { user }) | ||
} catch (error) { | ||
this.handleError(error) | ||
} | ||
}, | ||
// async register(credentials: { email: string; password: string }) { | ||
// try { | ||
// this.patchLoadingState("registering") | ||
// await ExameService.createAccount(credentials) | ||
// authService.createUser(credentials.email, credentials.password).subscribe((user) => { | ||
// patchState(store, { user, isLoading: false, status: "success", action: "login" }) | ||
// }) | ||
// } catch (error) { | ||
// this.handleError(error) | ||
// } | ||
// }, | ||
async logout() { | ||
authService.logout() | ||
patchState(store, { | ||
user: null, | ||
}) | ||
}, | ||
}) | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters