From dfdc1ce2e3607fa0a7c96b9f370b7f8c2bc7125f Mon Sep 17 00:00:00 2001 From: Weber Rener Paiva Date: Thu, 26 Dec 2024 17:30:29 -0300 Subject: [PATCH] feat: Add UsuarioDTO and ExameDTO interfaces; update Exame model for DTO integration; remove unused InMemoryRepository and AuthService; adjust repository exports and fix asset path in index.html --- angular.json | 4 +- angular_old.json | 145 ------------------ .../DatabaseRepository.spec.ts | 81 ++++++++++ .../DatabaseRepository/DatabaseRepository.ts | 77 +++++++--- src/app/Repository/EyedropsRepository.ts | 6 +- .../InMemoryRepository/InMemoryProvider.ts | 12 -- .../InMemoryRepository/InMemoryRepository.ts | 34 ---- src/app/Repository/index.ts | 1 - src/app/main/main.page.spec.ts | 46 +++--- src/app/main/main.page.ts | 8 +- src/app/models/Exame.spec.ts | 47 +++++- src/app/models/Exame.ts | 35 ++++- src/app/models/ExameDTO.ts | 14 ++ src/app/models/Material.spec.ts | 90 +++++++++-- src/app/models/Material.ts | 143 ++++++++++++++++- src/app/models/MaterialDTO.ts | 60 ++++++++ src/app/models/Usuario.spec.ts | 22 +++ src/app/models/Usuario.ts | 17 +- src/app/models/UsuarioDTO.ts | 6 + src/app/models/index.ts | 3 + src/app/models/listas.ts | 7 +- src/app/services/auth.service.spec.ts | 16 -- src/app/services/auth.service.ts | 26 ---- src/app/services/exame.service.spec.ts | 14 +- src/app/services/exame.service.ts | 53 +++---- src/index.html | 2 +- 26 files changed, 613 insertions(+), 356 deletions(-) delete mode 100644 angular_old.json delete mode 100644 src/app/Repository/InMemoryRepository/InMemoryProvider.ts delete mode 100644 src/app/Repository/InMemoryRepository/InMemoryRepository.ts create mode 100644 src/app/models/ExameDTO.ts create mode 100644 src/app/models/MaterialDTO.ts create mode 100644 src/app/models/Usuario.spec.ts create mode 100644 src/app/models/UsuarioDTO.ts delete mode 100644 src/app/services/auth.service.spec.ts delete mode 100644 src/app/services/auth.service.ts diff --git a/angular.json b/angular.json index 16c6c5e..d1e6898 100644 --- a/angular.json +++ b/angular.json @@ -27,7 +27,7 @@ { "glob": "**/*", "input": "public", - "src/assets" + "output": "src/assets" } ], "styles": ["src/global.scss", "src/theme/variables.scss"], @@ -82,7 +82,7 @@ { "glob": "**/*", "input": "public", - "src/assets" + "output": "src/assets" } ], "styles": ["src/global.scss", "src/theme/variables.scss"], diff --git a/angular_old.json b/angular_old.json deleted file mode 100644 index 454190c..0000000 --- a/angular_old.json +++ /dev/null @@ -1,145 +0,0 @@ -{ - "$schema": "./node_modules/@angular/cli/lib/config/schema.json", - "version": 1, - "newProjectRoot": "projects", - "projects": { - "app": { - "projectType": "application", - "schematics": { - "@ionic/angular-toolkit:page": { - "styleext": "scss", - "standalone": true - } - }, - "root": "", - "sourceRoot": "src", - "prefix": "app", - "architect": { - "build": { - "builder": "@angular-devkit/build-angular:browser", - "options": { - "outputPath": "www", - "index": "src/index.html", - "main": "src/main.ts", - "polyfills": "src/polyfills.ts", - "tsConfig": "tsconfig.app.json", - "inlineStyleLanguage": "scss", - "assets": [ - { - "glob": "**/*", - "input": "src/assets", - "output": "assets" - } - ], - "styles": ["src/global.scss", "src/theme/variables.scss"], - "scripts": [] - }, - "configurations": { - "production": { - "budgets": [ - { - "type": "initial", - "maximumWarning": "2mb", - "maximumError": "5mb" - }, - { - "type": "anyComponentStyle", - "maximumWarning": "2kb", - "maximumError": "4kb" - } - ], - "fileReplacements": [ - { - "replace": "src/environments/environment.ts", - "with": "src/environments/environment.prod.ts" - } - ], - "outputHashing": "all" - }, - "development": { - "buildOptimizer": false, - "optimization": false, - "vendorChunk": true, - "extractLicenses": false, - "sourceMap": true, - "namedChunks": true - }, - "ci": { - "progress": false - } - }, - "defaultConfiguration": "production" - }, - "serve": { - "builder": "@angular-devkit/build-angular:dev-server", - "configurations": { - "production": { - "buildTarget": "app:build:production" - }, - "development": { - "buildTarget": "app:build:development" - }, - "ci": { - "progress": false - } - }, - "defaultConfiguration": "development" - }, - "extract-i18n": { - "builder": "@angular-devkit/build-angular:extract-i18n", - "options": { - "buildTarget": "app:build" - } - }, - "test": { - "builder": "@angular-devkit/build-angular:karma", - "options": { - "main": "src/test.ts", - "polyfills": "src/polyfills.ts", - "tsConfig": "tsconfig.spec.json", - "karmaConfig": "karma.conf.js", - "inlineStyleLanguage": "scss", - "assets": [ - { - "glob": "**/*", - "input": "src/assets", - "output": "assets" - } - ], - "styles": ["src/global.scss", "src/theme/variables.scss"], - "scripts": [] - }, - "configurations": { - "ci": { - "progress": false, - "watch": false - } - } - }, - "lint": { - "builder": "@angular-eslint/builder:lint", - "options": { - "lintFilePatterns": ["src/**/*.ts", "src/**/*.html"] - } - } - } - } - }, - "cli": { - "schematicCollections": ["@ionic/angular-toolkit"] - }, - "schematics": { - "@ionic/angular-toolkit:component": { - "styleext": "scss" - }, - "@ionic/angular-toolkit:page": { - "styleext": "scss" - }, - "@angular-eslint/schematics:application": { - "setParserOptionsProject": true - }, - "@angular-eslint/schematics:library": { - "setParserOptionsProject": true - } - } -} diff --git a/src/app/Repository/DatabaseRepository/DatabaseRepository.spec.ts b/src/app/Repository/DatabaseRepository/DatabaseRepository.spec.ts index e69de29..4a990a7 100644 --- a/src/app/Repository/DatabaseRepository/DatabaseRepository.spec.ts +++ b/src/app/Repository/DatabaseRepository/DatabaseRepository.spec.ts @@ -0,0 +1,81 @@ +import { TestBed } from "@angular/core/testing" +import "firebase/firestore" +import { AngularFireModule } from "@angular/fire/compat" +import { AngularFirestoreCollection, AngularFirestoreModule } from "@angular/fire/compat/firestore" +import { DatabaseRepository } from "./DatabaseRepository" +import { firstValueFrom, map } from "rxjs" +import { ExameDTO } from "src/app/models/ExameDTO" +import { Exame, Material } from "src/app/models" + +describe("DatabaseRepository", () => { + let component: DatabaseRepository + const firebaseConfig = { + apiKey: "AIzaSyDpMfldg10XJfdkap0lsQkfaFTzbVTv3Lo", + authDomain: "grade-anp-testes.firebaseapp.com", + projectId: "grade-anp-testes", + storageBucket: "grade-anp-testes.firebasestorage.app", + messagingSenderId: "486118580910", + appId: "1:486118580910:web:de3c6d36d5b1672d86c33f", + } + + beforeEach(async () => { + TestBed.configureTestingModule({ + imports: [AngularFireModule.initializeApp(firebaseConfig), AngularFirestoreModule], + providers: [DatabaseRepository, { provide: "EYEDROPS_REPOSITORY", useClass: DatabaseRepository }], + }) + component = TestBed.inject(DatabaseRepository) + await truncate() + }) + + const truncate = async () => { + const eyedropsCollection: AngularFirestoreCollection = component.firestore.collection("eyedrops") + const actions = await firstValueFrom(eyedropsCollection.snapshotChanges()) + for (let i = 0; i < actions.length; i++) { + const docId = actions[i].payload.doc.id + await component.firestore.collection("eyedrops").doc(docId).delete() + } + } + + it("should access firebase and get no documents", async () => { + expect((await component.getAll()).length).toBe(0) + }) + + it("should create a document if not exists", async () => { + const material = Material.create({ numero: "123" }) + await component.save(Exame.create({ material: material.toPersistence() })) + expect((await component.getAll()).length).toBe(1) + }) + + it("should update a document if exists", async () => { + const material = Material.create({ numero: "123" }) + await component.save(Exame.create({ material: material.toPersistence() })) + await component.save(Exame.create({ material: material.toPersistence() })) + expect((await component.getAll()).length).toBe(1) + }) + + it("should get a document by codigo", async () => { + const material = Material.create({ numero: "123/24" }) + await component.save(Exame.create({ material: material.toPersistence() })) + const exameDTO: ExameDTO = await component.getByCodigo("0123/2024 GO") + expect(exameDTO.material.codigo).toBe("0123/2024 GO") + }) + + it("should get a document by UF", async () => { + const material1 = Material.create({ numero: "123", uf: "GO" }) + const material2 = Material.create({ numero: "124", uf: "go" }) + const material3 = Material.create({ numero: "225", uf: "df" }) + await component.save(Exame.create({ material: material1.toPersistence() })) + await component.save(Exame.create({ material: material2.toPersistence() })) + await component.save(Exame.create({ material: material3.toPersistence() })) + expect((await component.getByUF("GO")).length).toBe(2) + expect((await component.getByUF("df")).length).toBe(1) + }) + + // it("should dont update a blocked document by another user", async () => { + // await component.save(Exame.create(Material.create("123/24", "GO"))) + // await component.save(Exame.create(Material.create("124/24", "go"))) + // await component.save(Exame.create(Material.create("225/24", "df"))) + // await component.block("123/24") + // expect((await component.getAll()).length).toBe(2) + // }) +}) diff --git a/src/app/Repository/DatabaseRepository/DatabaseRepository.ts b/src/app/Repository/DatabaseRepository/DatabaseRepository.ts index 65d00ee..6983292 100644 --- a/src/app/Repository/DatabaseRepository/DatabaseRepository.ts +++ b/src/app/Repository/DatabaseRepository/DatabaseRepository.ts @@ -1,35 +1,49 @@ import { Injectable } from "@angular/core" -import { AngularFirestore, CollectionReference } from "@angular/fire/compat/firestore" +import { AngularFirestore, AngularFirestoreCollection, CollectionReference } from "@angular/fire/compat/firestore" import { EyedropsRepository } from "../EyedropsRepository" import { Exame } from "src/app/models" import "firebase/compat/firestore" +import { ExameDTO } from "src/app/models/ExameDTO" +import { firstValueFrom, map } from "rxjs" @Injectable({ providedIn: "root", }) export class DatabaseRepository implements EyedropsRepository { - eyedropsCollection: CollectionReference + eyedropsCollection: AngularFirestoreCollection + eyedropsCollectionRef: CollectionReference - constructor(private firestore: AngularFirestore) { - this.eyedropsCollection = this.firestore.collection("eyedrops").ref - this.getByCodigo("0123/2024 GO") - .then((exame) => { - console.log("exame", exame) - }) - .catch((error) => { - console.error("Error getting document: ", error) - }) + constructor(public firestore: AngularFirestore) { + this.eyedropsCollection = this.firestore.collection("eyedrops") + this.eyedropsCollectionRef = this.firestore.collection("eyedrops").ref + } + + async getAll(): Promise { + return firstValueFrom( + this.eyedropsCollection.snapshotChanges().pipe( + map((actions) => + actions.map((a) => { + const data = a.payload.doc.data() as ExameDTO + const id = a.payload.doc.id + return { id, ...data } + }) + ) + ) + ) } - async getByCodigo(codigo: string): Promise { + + async getByCodigo(codigo: string): Promise { try { - const eyedropsRef = this.eyedropsCollection.where("codigo", "==", codigo) + const materialCollectionRef = this.firestore.collection("eyedrops/exame/material").ref + const eyedropsRef = materialCollectionRef.where("codigo", "==", codigo) const eyedropsQuery = await eyedropsRef.limit(1).get() if (eyedropsQuery.empty) return null - const exame: Exame = await eyedropsQuery.docs.map(async (doc: any) => { + const exame: ExameDTO = await eyedropsQuery.docs.map(async (doc: any) => { const data: any = { - ...doc.data(), id: doc.id, - exame: doc.data(), + codigo: doc.data().codigo, + uf: doc.data().uf, + exame: doc.data().exame, } return data })[0] @@ -39,21 +53,34 @@ export class DatabaseRepository implements EyedropsRepository { throw error } } - getByUF(codigo: string): Promise { - throw new Error("Method not implemented.") + + async getByUF(uf: string): Promise { + try { + const eyedropsRef = this.eyedropsCollectionRef.where("uf", "==", uf.toUpperCase()) + const eyedropsQuery = await eyedropsRef.get() + if (eyedropsQuery.empty) return [] + const exames: ExameDTO[] = eyedropsQuery.docs.map((doc: any) => { + const data: ExameDTO = { + ...doc.data(), + id: doc.id, + } + return data + }) + return exames + } catch (error) { + console.error(`Erro ao buscar documento uf:${uf}`, error) + throw error + } } async save(exame: Exame): Promise { + console.log(exame.toPersistence()) try { - const query = await this.eyedropsCollection.where("codigo", "==", exame.material.codigo).get() + const query = await this.eyedropsCollectionRef.where("codigo", "==", exame.material.codigo).get() if (query.empty) { - console.log("save - create", query.empty) - await this.eyedropsCollection.doc().set({ codigo: exame.material.codigo, exame: JSON.stringify(exame) }) + await this.eyedropsCollection.doc().set(exame.toPersistence()) } else { - console.log("save - update", query.docs[0].id) - await this.eyedropsCollection - .doc(query.docs[0].id) - .set({ codigo: exame.material.codigo, exame: JSON.stringify(exame) }) + await this.eyedropsCollection.doc(query.docs[0].id).set(exame.toPersistence()) } } catch (error) { console.error("Erro ao criar o documento:", error) diff --git a/src/app/Repository/EyedropsRepository.ts b/src/app/Repository/EyedropsRepository.ts index 7e78a06..4204fdc 100644 --- a/src/app/Repository/EyedropsRepository.ts +++ b/src/app/Repository/EyedropsRepository.ts @@ -1,8 +1,10 @@ import { Exame } from "../models" +import { ExameDTO } from "../models/ExameDTO" export interface EyedropsRepository { save(exame: Exame): Promise - getByCodigo(codigo: string): Promise - getByUF(codigo: string): Promise + getAll(): Promise + getByCodigo(codigo: string): Promise + getByUF(codigo: string): Promise truncate(): Promise } diff --git a/src/app/Repository/InMemoryRepository/InMemoryProvider.ts b/src/app/Repository/InMemoryRepository/InMemoryProvider.ts deleted file mode 100644 index 15a7b0b..0000000 --- a/src/app/Repository/InMemoryRepository/InMemoryProvider.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ExameService } from "src/app/services/exame.service" -import { InMemoryRepository } from "./InMemoryRepository" - -export const InMemoryProvider = [ - { - provide: ExameService, - useFactory: (repository: any) => { - return new ExameService(repository) - }, - inject: [InMemoryRepository], - }, -] diff --git a/src/app/Repository/InMemoryRepository/InMemoryRepository.ts b/src/app/Repository/InMemoryRepository/InMemoryRepository.ts deleted file mode 100644 index 6438d57..0000000 --- a/src/app/Repository/InMemoryRepository/InMemoryRepository.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Exame } from "src/app/models" -import { EyedropsRepository } from "../EyedropsRepository" - -export class InMemoryRepository implements EyedropsRepository { - getByCodigo(codigo: string): Promise { - return Promise.resolve( - this.exames.find((exame) => `${exame.material.numero} ${exame.material.uf.toUpperCase()}` === codigo.toUpperCase()) - ) - } - exames: Exame[] = [] - - async getByUF(uf: string): Promise { - return Promise.resolve(this.exames.filter((exame) => exame.material.uf === uf)) - } - - async save(exame: Exame): Promise { - const index = this.exames.findIndex( - (e) => - `${e.material.numero} ${e.material.uf.toUpperCase()}` === - `${exame.material.numero} ${exame.material.uf.toUpperCase()}` - ) - if (index < 0) { - this.exames.push(exame) - } else { - this.exames[index] = exame - } - return - } - - truncate() { - this.exames = [] - return Promise.resolve() - } -} diff --git a/src/app/Repository/index.ts b/src/app/Repository/index.ts index f0b9c65..c9ca0bc 100644 --- a/src/app/Repository/index.ts +++ b/src/app/Repository/index.ts @@ -1,5 +1,4 @@ // @index(['./**/*.ts',/spec/g], f => `export * from '${f.path}'`) export * from "./DatabaseRepository/DatabaseRepository" export * from "./EyedropsRepository" -export * from "./InMemoryRepository/InMemoryRepository" // @endindex diff --git a/src/app/main/main.page.spec.ts b/src/app/main/main.page.spec.ts index a89e07d..125d1ca 100644 --- a/src/app/main/main.page.spec.ts +++ b/src/app/main/main.page.spec.ts @@ -2,35 +2,31 @@ import { ComponentFixture, TestBed } from "@angular/core/testing" import { MainPage } from "./main.page" import { STEP, TAREFAS } from "../models/listas" import { Exame, Material, Usuario } from "../models" -import { AuthService } from "../services/auth.service" -import { WritableSignal } from "@angular/core" import { ExameService, ExameState } from "../services/exame.service" describe("MainPage", () => { let component: MainPage let fixture: ComponentFixture let exame: Exame - - const authServiceMock = { - getUsuarioAtual: () => - new Usuario({ - codigo: "002", - nome: "Usuario 2", - uf: "GO", - perfil: "Perito", - }), - } + let usuarioAtual: Usuario beforeEach(async () => { fixture = await TestBed.configureTestingModule({ imports: [MainPage], - providers: [ExameService, { provide: AuthService, useValue: authServiceMock }], + providers: [ExameService, { provide: "EYEDROPS_REPOSITORY", useClass: class {} }], }).compileComponents() fixture = TestBed.createComponent(MainPage) component = fixture.componentInstance component.ngOnInit() - component.onChangeUsuarioAtual(authServiceMock.getUsuarioAtual()) - exame = new Exame(new Material("1")) + usuarioAtual = Usuario.create({ + codigo: "002", + nome: "Usuario 2", + uf: "GO", + perfil: "Perito", + }) + component.onChangeUsuarioAtual(usuarioAtual) + const material = Material.create({ numero: "1" }) + exame = Exame.create({ material: material.toPersistence() }) }) function populateMaterialFields() { @@ -53,12 +49,12 @@ describe("MainPage", () => { expect(component.state().action).toBe(TAREFAS.RECEBER_MATERIAL) expect(component.state().status).toBe(STEP.RECEBER_MATERIAL) expect(component.state().listaExames).toEqual([]) - expect(component.state().usuarioAtual).toEqual(authServiceMock.getUsuarioAtual()) + expect(component.state().usuarioAtual).toEqual(usuarioAtual) expect(component.state().exameAtual).toBeNull() }) it("should create exame when calling getExame if not exists", () => { - const material = new Material("0123/2024") + const material = Material.create({ numero: "0123/2024" }) expect(component.state().listaExames.length).toBe(0) const exame = component.getExame(material) expect(exame).toBeDefined() @@ -71,8 +67,8 @@ describe("MainPage", () => { }) it("should return the correct exame when calling getExame", () => { - const material1 = new Material("0123/2024") - const material2 = new Material("456/24") + const material1 = Material.create({ numero: "0123/2024" }) + const material2 = Material.create({ numero: "456/24" }) component.getExame(material1) component.getExame(material2) expect(component.state().exameAtual.material).toEqual(material1) @@ -81,7 +77,7 @@ describe("MainPage", () => { expect(exame.material).toEqual(material1) }) - it("should add a new material form control when calling addNrMaterial", () => { + it("should add a Material.create form control when calling addNrMaterial", () => { component.ngOnInit() let nrMateriais = component.getMateriaisControls() expect(nrMateriais.length).toBe(1) @@ -90,8 +86,8 @@ describe("MainPage", () => { }) it("should return the current exame when calling getExameAtual", () => { - const material1 = new Material("0123/2024") - const material2 = new Material("456/24") + const material1 = Material.create({ numero: "0123/2024" }) + const material2 = Material.create({ numero: "456/24" }) component.getExame(material1) component.getExame(material2) component.onChangeMaterialAtual(material1) @@ -106,7 +102,7 @@ describe("MainPage", () => { component.state.update((s) => ({ ...s, listaExames })) expect(component.state().listaExames.length).toBe(1) populateMaterialFields() - const material = new Material("0123/2024") + const material = Material.create({ numero: "0123/2024" }) component.getExame(material) component.onChangeMaterialAtual(material) } @@ -1226,12 +1222,12 @@ describe("MainPage", () => { let usuarioAtual = component.state().usuarioAtual expect(usuarioAtual.nome).toBe("Usuario 2") expect(component.state().exameAtual.getUserOfLastTask()).toBe(usuarioAtual) - component.state().usuarioAtual = { + component.state().usuarioAtual = Usuario.create({ codigo: "003", nome: "Usuario 3", perfil: "Perito", uf: "GO", - } + }) usuarioAtual = component.state().usuarioAtual expect(usuarioAtual.nome).toBe("Usuario 3") component.registrarQtdeSimCards(2) diff --git a/src/app/main/main.page.ts b/src/app/main/main.page.ts index 071e63d..107bcf9 100644 --- a/src/app/main/main.page.ts +++ b/src/app/main/main.page.ts @@ -24,7 +24,6 @@ import { BreakpointObserver, Breakpoints } from "@angular/cdk/layout" import { addIcons } from "ionicons" import { addOutline, camera, cameraOutline, checkmarkOutline, printOutline, syncOutline, trashOutline } from "ionicons/icons" import { BATERIA_STATUS, STEP, TAREFAS, TELA_STATUS } from "../models/listas" -import { AuthService } from "../services/auth.service" import { GaleriaFotosComponent } from "../galeria-fotos/galeria-fotos.component" import { defineCustomElements } from "@ionic/pwa-elements/loader" import { environment } from "src/environments/environment" @@ -178,7 +177,8 @@ export class MainPage implements OnInit { } onChangeUsuarioAtual(usuario: Usuario) { - this.state.update((s) => ({ ...s, usuarioAtual: usuario })) + this.exameService.changeUsuarioAtual(usuario) + // this.state.update((s) => ({ ...s, usuarioAtual: usuario })) } onChangeExameAtual(exame: Exame) { @@ -211,7 +211,7 @@ export class MainPage implements OnInit { const listaExames = this.state().listaExames let exame = listaExames.find((exame) => exame.material.equal(material)) if (!exame) { - exame = new Exame(material) + exame = Exame.create({ material: material.toPersistence() }) listaExames.push(exame) } if (!this.state().exameAtual) this.state.update((s) => ({ ...s, exameAtual: exame })) @@ -274,7 +274,7 @@ export class MainPage implements OnInit { let primeiroMaterial: any const embalagem = uuidv4() this.getMateriaisControls().forEach((m) => { - const material = new Material(m.get("numero")?.value, m.get("uf")?.value) + const material = Material.create({ numero: m.get("numero")?.value, uf: m.get("uf")?.value }) const existeMaterial = this.state().listaExames.some((exame) => exame.material.equal(material)) const exame = this.getExame(material) if (!exame.embalagem) exame.embalagem = embalagem diff --git a/src/app/models/Exame.spec.ts b/src/app/models/Exame.spec.ts index 906e393..0d0b4e8 100644 --- a/src/app/models/Exame.spec.ts +++ b/src/app/models/Exame.spec.ts @@ -1,5 +1,5 @@ import { Exame } from "./Exame" -import { Material, STEP, TAREFAS, Usuario } from "." +import { ExameDTO, Material, STEP, TAREFAS, Usuario } from "." describe("Exame", () => { let exame: Exame @@ -7,14 +7,14 @@ describe("Exame", () => { let usuario: Usuario beforeEach(() => { - material = new Material("123/2024") - usuario = new Usuario({ + material = Material.create({ numero: "123/2024" }) + usuario = Usuario.create({ codigo: "001", nome: "Usuario 1", uf: "GO", perfil: "Perito", }) - exame = new Exame(material) + exame = Exame.create({ material: material.toPersistence() }) }) it("should create an instance of Exame", () => { @@ -22,7 +22,7 @@ describe("Exame", () => { }) it("should have the correct material", () => { - expect(exame.material).toBe(material) + expect(exame.material.toPersistence()).toEqual(material.toPersistence()) }) it("should have the correct currentStep", () => { @@ -94,4 +94,41 @@ describe("Exame", () => { expect(tarefas[0].concluida).toBe(false) expect(tarefas[0].historico).toEqual([]) }) + + it("should convert ExameDTO to Exame", () => { + const exameDTO: ExameDTO = { + id: "exameId", + embalagem: "embalagem", + currentStep: 12, + material: Material.create({ numero: "123" }).toPersistence(), + status: { + codigo: 1, + data: new Date().toISOString(), + usuario: usuario.toPersistence(), + }, + } + + const exame = Exame.create(exameDTO) + expect(exame.id).toBe(exameDTO.id) + expect(exame.embalagem).toBe(exameDTO.embalagem) + expect(exame.currentStep).toBe(exameDTO.currentStep) + expect(exame.material.numero).toBe(exameDTO.material.numero) + expect(exame.status.codigo).toBe(exameDTO.status.codigo) + expect(exame.status.data.toISOString()).toBe(exameDTO.status.data) + expect(exame.status.usuario?.toPersistence()).toEqual(exameDTO.status.usuario) + }) + + it("should convert Exame to ExameDTO", () => { + let exameDTO = exame.toPersistence() + expect(exameDTO.id).toBe("") + expect(exameDTO.embalagem).toBe(exame.embalagem) + expect(exameDTO.currentStep).toBe(exame.currentStep) + expect(exameDTO.material).toEqual(exame.material.toPersistence()) + expect(exameDTO.status.codigo).toBe(exame.status.codigo) + expect(exameDTO.status.data).toBe(exame.status.data.toISOString()) + expect(exameDTO.status.usuario).toBe(null) + exame.status.usuario = usuario + exameDTO = exame.toPersistence() + expect(exameDTO.status.usuario).toEqual(usuario.toPersistence()) + }) }) diff --git a/src/app/models/Exame.ts b/src/app/models/Exame.ts index 3c9cd6b..1a28b60 100644 --- a/src/app/models/Exame.ts +++ b/src/app/models/Exame.ts @@ -1,7 +1,9 @@ import { Material, Usuario } from "." +import { ExameDTO } from "./ExameDTO" import { EXAME_STATUS, STEP, Tarefa, TAREFAS } from "./listas" export class Exame { + private _id: string private _embalagem: string = "" private _tarefas: Tarefa[] = [] private _currentStep: STEP = STEP.RECEBER_MATERIAL @@ -16,11 +18,42 @@ export class Exame { usuario: null, } - constructor(material: Material) { + private constructor(material: Material) { this.material = material this.reset() } + static create(exameDTO: ExameDTO): Exame { + const exame = new Exame(Material.create(exameDTO.material)) + exame._id = exameDTO.id + exame.embalagem = exameDTO.embalagem ?? "" + exame.currentStep = exameDTO.currentStep ?? STEP.RECEBER_MATERIAL + exame.status = { + codigo: exameDTO.status?.codigo ?? EXAME_STATUS.BLOQUEADO, + data: exameDTO.status?.data ? new Date(exameDTO.status?.data) : new Date(), + usuario: exameDTO.status?.usuario ? Usuario.create(exameDTO.status.usuario) : null, + } + return exame + } + + toPersistence(): ExameDTO { + return { + id: this.id ?? "", + embalagem: this.embalagem, + currentStep: this.currentStep, + material: this.material?.toPersistence(), + status: { + codigo: this.status.codigo, + data: this.status.data.toISOString(), + usuario: this.status.usuario?.toPersistence() ?? null, + }, + } + } + + get id(): string { + return this._id + } + get status(): any { return this._status } diff --git a/src/app/models/ExameDTO.ts b/src/app/models/ExameDTO.ts new file mode 100644 index 0000000..e1cf9e4 --- /dev/null +++ b/src/app/models/ExameDTO.ts @@ -0,0 +1,14 @@ +import { MaterialDTO } from "./MaterialDTO" +import { UsuarioDTO } from "./UsuarioDTO" + +export interface ExameDTO { + id?: string + embalagem?: string + currentStep?: number + material: MaterialDTO + status?: { + codigo?: number + data?: string + usuario?: UsuarioDTO + } +} diff --git a/src/app/models/Material.spec.ts b/src/app/models/Material.spec.ts index b50237e..75fce8e 100644 --- a/src/app/models/Material.spec.ts +++ b/src/app/models/Material.spec.ts @@ -1,11 +1,12 @@ import { Material } from "." +import { MaterialDTO } from "./MaterialDTO" describe("Material", () => { const currentYear = new Date().getFullYear() let material: Material beforeEach(() => { - material = new Material("0001/2021") + material = Material.create({ numero: "0001/2021" }) }) it("should create an instance", () => { @@ -13,47 +14,47 @@ describe("Material", () => { }) it("should accept a valid number greater than 0", () => { - const material = new Material(`1`) + const material = Material.create({ numero: "1" }) expect(material.numero).toBe(`0001/${currentYear}`) expect() }) it("should accept a valid number with the current year", () => { - const material = new Material(`0001/${currentYear}`) + const material = Material.create({ numero: `0001/${currentYear}` }) expect(material.numero).toBe(`0001/${currentYear}`) }) it("should accept a valid number with a past year", () => { - let material = new Material("0001/2020") + let material = Material.create({ numero: "0001/2020" }) expect(material.numero).toBe("0001/2020") - material = new Material("1/20") + material = Material.create({ numero: "1/20" }) expect(material.numero).toBe("0001/2020") }) it("should default to the current year if no year is specified", () => { - const material = new Material("0001") + const material = Material.create({ numero: "0001" }) expect(material.numero).toBe(`0001/${currentYear}`) }) it("should adjust a number with an invalid format", () => { - let material = new Material("1") + let material = Material.create({ numero: "1" }) expect(material.numero).toBe(`0001/${currentYear}`) - material = new Material("1/24") + material = Material.create({ numero: "1/24" }) expect(material.numero).toBe(`0001/2024`) }) it("should throw an error for a number equal 0", () => { expect(() => { - new Material(`000`) + Material.create({ numero: "000" }) }).toThrowError("Número de material inválido.") expect(() => { - new Material(`000/${currentYear}`) + Material.create({ numero: `000/${currentYear}` }) }).toThrowError("Número de material inválido.") }) it("should throw an error for a number with a future year", () => { expect(() => { - new Material(`0001/${currentYear + 1}`) + Material.create({ numero: `0001/${currentYear + 1}` }) }).toThrowError("Número de material inválido.") }) @@ -63,7 +64,7 @@ describe("Material", () => { it("should throw an error for an invalid number", () => { expect(() => { - new Material("0000/2022") + Material.create({ numero: "0000/2022" }) }).toThrowError("Número de material inválido.") }) @@ -78,4 +79,69 @@ describe("Material", () => { expect(material.fotos.simCards).toEqual([]) expect(material.fotos.memoryCard).toEqual([]) }) + + it("should convert Material to MaterialDTO", () => { + const materialDTO: MaterialDTO = { + numero: "0001/2023", + uf: "SP", + lacre: "123456", + recebidoLigado: true, + bateria: 1, + telaFuncionando: 1, + recebidoModoAviao: false, + recebidoBloqueado: true, + senhaFornecida: true, + senha: "1234", + fotos: { + embalagem: JSON.stringify(["foto1.jpg"]), + lacre: JSON.stringify(["foto2.jpg"]), + detalhes: JSON.stringify(["foto3.jpg"]), + simCards: JSON.stringify(["foto4.jpg"]), + memoryCard: JSON.stringify(["foto5.jpg"]), + }, + descricao: "Material de teste", + codigoEpol: "EPOL123", + estado_conservacao: "Bom", + aparencia_tela: "Sem arranhões", + funcionamento_tela: "Funcionando", + funcionamento_touch: "Funcionando", + funcionamento_botoes: "Funcionando", + funcionamento_conector_dados: "Funcionando", + outros_defeitos_observados: "Nenhum", + qtde_simcard: 1, + simcard1_operadora: "Operadora1", + simcard1_numero: "123456789", + simcard2_operadora: "", + simcard2_numero: "", + simcard3_operadora: "", + simcard3_numero: "", + qtde_memorycard: 1, + fabricante: "Fabricante1", + modelo: "Modelo1", + imei1: "IMEI123456789", + imei2: "", + serial: "SERIAL123456", + is_modo_aviao: false, + is_simcard1_extracted: false, + is_simcard2_extracted: false, + is_simcard3_extracted: false, + is_memorycard1_extracted: false, + is_memorycard2_extracted: false, + is_memorycard3_extracted: false, + is_inseyets_extracting: false, + inseyets_laped_machine: "", + is_physical_analyzer_opening: false, + physical_analyzer_laped_machine: "", + whatsapp_physical_analyzer: "", + dados_usuario: "", + is_iped_opening: false, + is_iped_ok: false, + is_zipping: false, + is_zip_ok: false, + is_zip_moving: false, + } + const material = Material.create(materialDTO) + const result = material.toPersistence() + expect(result).toEqual(materialDTO) + }) }) diff --git a/src/app/models/Material.ts b/src/app/models/Material.ts index 369dac9..259b14b 100644 --- a/src/app/models/Material.ts +++ b/src/app/models/Material.ts @@ -1,4 +1,5 @@ import { BATERIA_STATUS, TELA_STATUS } from "./listas" +import { MaterialDTO } from "./MaterialDTO" export class Material { private _numero: string = "" @@ -65,7 +66,7 @@ export class Material { private _is_zip_ok: boolean = false private _is_zip_moving: boolean = false - constructor(numero: string = "", uf: string = "GO") { + private constructor(numero: string, uf: string) { this.filterNumero(numero) if (!this.validateNumero()) { throw new Error("Número de material inválido.") @@ -73,6 +74,146 @@ export class Material { this._uf = uf.toUpperCase() } + static create(materialDTO: MaterialDTO): Material { + materialDTO.uf = materialDTO.uf ?? "GO" + let material = new Material(materialDTO.numero, materialDTO.uf) + material._lacre = materialDTO.lacre ?? "" + material._recebidoLigado = materialDTO.recebidoLigado ?? false + material._bateria = materialDTO.bateria ?? 0 + material._telaFuncionando = materialDTO.telaFuncionando ?? 0 + material._recebidoModoAviao = materialDTO.recebidoModoAviao ?? false + material._recebidoBloqueado = materialDTO.recebidoBloqueado ?? false + material._senhaFornecida = materialDTO.senhaFornecida ?? false + material._senha = materialDTO.senha ?? "" + material._fotos = { + embalagem: [], + lacre: [], + detalhes: [], + simCards: [], + memoryCard: [], + } + if (materialDTO.fotos && materialDTO.fotos.embalagem) { + material._fotos.embalagem = JSON.parse(materialDTO.fotos.embalagem) + } + if (materialDTO.fotos && materialDTO.fotos.lacre) { + material._fotos.lacre = JSON.parse(materialDTO.fotos.lacre) + } + if (materialDTO.fotos && materialDTO.fotos.detalhes) { + material._fotos.detalhes = JSON.parse(materialDTO.fotos.detalhes) + } + if (materialDTO.fotos && materialDTO.fotos.simCards) { + material._fotos.simCards = JSON.parse(materialDTO.fotos.simCards) + } + if (materialDTO.fotos && materialDTO.fotos.memoryCard) { + material._fotos.memoryCard = JSON.parse(materialDTO.fotos.memoryCard) + } + material._descricao = materialDTO.descricao ?? "" + material._codigoEpol = materialDTO.codigoEpol ?? "" + material._estado_conservacao = materialDTO.estado_conservacao ?? "" + material._aparencia_tela = materialDTO.aparencia_tela ?? "" + material._funcionamento_tela = materialDTO.funcionamento_tela ?? "" + material._funcionamento_touch = materialDTO.funcionamento_touch ?? "" + material._funcionamento_botoes = materialDTO.funcionamento_botoes ?? "" + material._funcionamento_conector_dados = materialDTO.funcionamento_conector_dados ?? "" + material._outros_defeitos_observados = materialDTO.outros_defeitos_observados ?? "" + material._qtde_simcard = materialDTO.qtde_simcard ?? 0 + material._simcard1_operadora = materialDTO.simcard1_operadora ?? "" + material._simcard1_numero = materialDTO.simcard1_numero ?? "" + material._simcard2_operadora = materialDTO.simcard2_operadora ?? "" + material._simcard2_numero = materialDTO.simcard2_numero ?? "" + material._simcard3_operadora = materialDTO.simcard3_operadora ?? "" + material._simcard3_numero = materialDTO.simcard3_numero ?? "" + material._qtde_memorycard = materialDTO.qtde_memorycard ?? 0 + material._fabricante = materialDTO.fabricante ?? "" + material._modelo = materialDTO.modelo ?? "" + material._imei1 = materialDTO.imei1 ?? "" + material._imei2 = materialDTO.imei2 ?? "" + material._serial = materialDTO.serial ?? "" + material._is_modo_aviao = materialDTO.is_modo_aviao ?? false + material._is_simcard1_extracted = materialDTO.is_simcard1_extracted ?? false + material._is_simcard2_extracted = materialDTO.is_simcard2_extracted ?? false + material._is_simcard3_extracted = materialDTO.is_simcard3_extracted ?? false + material._is_memorycard1_extracted = materialDTO.is_memorycard1_extracted ?? false + material._is_memorycard2_extracted = materialDTO.is_memorycard2_extracted ?? false + material._is_memorycard3_extracted = materialDTO.is_memorycard3_extracted ?? false + material._is_inseyets_extracting = materialDTO.is_inseyets_extracting ?? false + material._inseyets_laped_machine = materialDTO.inseyets_laped_machine ?? "" + material._is_physical_analyzer_opening = materialDTO.is_physical_analyzer_opening ?? false + material._physical_analyzer_laped_machine = materialDTO.physical_analyzer_laped_machine ?? "" + material._whatsapp_physical_analyzer = materialDTO.whatsapp_physical_analyzer ?? "" + material._dados_usuario = materialDTO.dados_usuario ?? "" + material._is_iped_opening = materialDTO.is_iped_opening ?? false + material._is_iped_ok = materialDTO.is_iped_ok ?? false + material._is_zipping = materialDTO.is_zipping ?? false + material._is_zip_ok = materialDTO.is_zip_ok ?? false + material._is_zip_moving = materialDTO.is_zip_moving ?? false + + return material + } + + toPersistence(): MaterialDTO { + return { + numero: this.numero, + uf: this.uf, + codigo: this.codigo, + lacre: this.lacre, + recebidoLigado: this.recebidoLigado, + bateria: this.bateria, + telaFuncionando: this.telaFuncionando, + recebidoModoAviao: this.recebidoModoAviao, + recebidoBloqueado: this.recebidoBloqueado, + senhaFornecida: this.senhaFornecida, + senha: this.senha, + fotos: { + embalagem: this.fotos.embalagem.length > 0 ? JSON.stringify(this.fotos.embalagem) : "", + lacre: this.fotos.lacre.length > 0 ? JSON.stringify(this.fotos.lacre) : "", + detalhes: this.fotos.detalhes.length > 0 ? JSON.stringify(this.fotos.detalhes) : "", + simCards: this.fotos.simCards.length > 0 ? JSON.stringify(this.fotos.simCards) : "", + memoryCard: this.fotos.memoryCard.length > 0 ? JSON.stringify(this.fotos.memoryCard) : "", + }, + descricao: this.descricao, + codigoEpol: this.codigoEpol, + estado_conservacao: this.estado_conservacao, + aparencia_tela: this.aparencia_tela, + funcionamento_tela: this.funcionamento_tela, + funcionamento_touch: this.funcionamento_touch, + funcionamento_botoes: this.funcionamento_botoes, + funcionamento_conector_dados: this.funcionamento_conector_dados, + outros_defeitos_observados: this.outros_defeitos_observados, + qtde_simcard: this.qtde_simcard, + simcard1_operadora: this.simcard1_operadora, + simcard1_numero: this.simcard1_numero, + simcard2_operadora: this.simcard2_operadora, + simcard2_numero: this.simcard2_numero, + simcard3_operadora: this.simcard3_operadora, + simcard3_numero: this.simcard3_numero, + qtde_memorycard: this.qtde_memorycard, + fabricante: this.fabricante, + modelo: this.modelo, + imei1: this.imei1, + imei2: this.imei2, + serial: this.serial, + is_modo_aviao: this.is_modo_aviao, + is_simcard1_extracted: this.is_simcard1_extracted, + is_simcard2_extracted: this.is_simcard2_extracted, + is_simcard3_extracted: this.is_simcard3_extracted, + is_memorycard1_extracted: this.is_memorycard1_extracted, + is_memorycard2_extracted: this.is_memorycard2_extracted, + is_memorycard3_extracted: this.is_memorycard3_extracted, + is_inseyets_extracting: this.is_inseyets_extracting, + inseyets_laped_machine: this.inseyets_laped_machine, + is_physical_analyzer_opening: this.is_physical_analyzer_opening, + physical_analyzer_laped_machine: this.physical_analyzer_laped_machine, + whatsapp_physical_analyzer: this.whatsapp_physical_analyzer, + dados_usuario: this.dados_usuario, + is_iped_opening: this.is_iped_opening, + is_iped_ok: this.is_iped_ok, + is_zipping: this.is_zipping, + is_zip_ok: this.is_zip_ok, + is_zip_moving: this.is_zip_moving, + } + } + get numero(): string { return this._numero } diff --git a/src/app/models/MaterialDTO.ts b/src/app/models/MaterialDTO.ts new file mode 100644 index 0000000..5f6004b --- /dev/null +++ b/src/app/models/MaterialDTO.ts @@ -0,0 +1,60 @@ +export interface MaterialDTO { + numero: string + uf?: string + codigo?: string + lacre?: string + recebidoLigado?: boolean + bateria?: number + telaFuncionando?: number + recebidoModoAviao?: boolean + recebidoBloqueado?: boolean + senhaFornecida?: boolean + senha?: string + fotos?: { + embalagem: string + lacre: string + detalhes: string + simCards: string + memoryCard: string + } + descricao?: string + codigoEpol?: string + estado_conservacao?: string + aparencia_tela?: string + funcionamento_tela?: string + funcionamento_touch?: string + funcionamento_botoes?: string + funcionamento_conector_dados?: string + outros_defeitos_observados?: string + qtde_simcard?: number + simcard1_operadora?: string + simcard1_numero?: string + simcard2_operadora?: string + simcard2_numero?: string + simcard3_operadora?: string + simcard3_numero?: string + qtde_memorycard?: number + fabricante?: string + modelo?: string + imei1?: string + imei2?: string + serial?: string + is_modo_aviao?: boolean + is_simcard1_extracted?: boolean + is_simcard2_extracted?: boolean + is_simcard3_extracted?: boolean + is_memorycard1_extracted?: boolean + is_memorycard2_extracted?: boolean + is_memorycard3_extracted?: boolean + is_inseyets_extracting?: boolean + inseyets_laped_machine?: string + is_physical_analyzer_opening?: boolean + physical_analyzer_laped_machine?: string + whatsapp_physical_analyzer?: string + dados_usuario?: string + is_iped_opening?: boolean + is_iped_ok?: boolean + is_zipping?: boolean + is_zip_ok?: boolean + is_zip_moving?: boolean +} diff --git a/src/app/models/Usuario.spec.ts b/src/app/models/Usuario.spec.ts new file mode 100644 index 0000000..4b81603 --- /dev/null +++ b/src/app/models/Usuario.spec.ts @@ -0,0 +1,22 @@ +import { Usuario } from "./Usuario" +import { UsuarioDTO } from "./UsuarioDTO" + +describe("Usuario", () => { + it("should convert Usuario to UsuarioDTO", () => { + const usuario = Usuario.create({ + codigo: "123", + nome: "John Doe", + perfil: "admin", + uf: "SP", + }) + + const usuarioDTO: UsuarioDTO = usuario.toPersistence() + + expect(usuarioDTO).toEqual({ + codigo: "123", + nome: "John Doe", + perfil: "admin", + uf: "SP", + }) + }) +}) diff --git a/src/app/models/Usuario.ts b/src/app/models/Usuario.ts index 47cd673..e8597e7 100644 --- a/src/app/models/Usuario.ts +++ b/src/app/models/Usuario.ts @@ -1,13 +1,28 @@ +import { UsuarioDTO } from "./UsuarioDTO" + export class Usuario { codigo: string = "" nome: string = "" perfil: string = "" uf: string = "" - constructor(usuario: Usuario) { + private constructor(usuario: UsuarioDTO) { this.codigo = usuario.codigo this.nome = usuario.nome this.perfil = usuario.perfil this.uf = usuario.uf } + + static create(usuario: UsuarioDTO): Usuario { + return new Usuario(usuario) + } + + toPersistence(): UsuarioDTO { + return { + codigo: this.codigo, + nome: this.nome, + perfil: this.perfil, + uf: this.uf, + } + } } diff --git a/src/app/models/UsuarioDTO.ts b/src/app/models/UsuarioDTO.ts new file mode 100644 index 0000000..d5b1669 --- /dev/null +++ b/src/app/models/UsuarioDTO.ts @@ -0,0 +1,6 @@ +export interface UsuarioDTO { + codigo: string + nome: string + perfil: string + uf: string +} diff --git a/src/app/models/index.ts b/src/app/models/index.ts index ce8ea79..8b18821 100644 --- a/src/app/models/index.ts +++ b/src/app/models/index.ts @@ -1,6 +1,9 @@ // @index(['./**/*.ts',/spec/g], f => `export * from '${f.path}'`) export * from "./Exame" +export * from "./ExameDTO" export * from "./listas" export * from "./Material" +export * from "./MaterialDTO" export * from "./Usuario" +export * from "./UsuarioDTO" // @endindex diff --git a/src/app/models/listas.ts b/src/app/models/listas.ts index 3ec1bf5..55ae024 100644 --- a/src/app/models/listas.ts +++ b/src/app/models/listas.ts @@ -1,4 +1,3 @@ -import { AuthService } from "../services/auth.service" import { Usuario } from "./Usuario" export enum STEP { @@ -98,7 +97,7 @@ export type Tarefa = { } export enum EXAME_STATUS { - DISPONIVEL, - BLOQUEADO, - CONCLUIDO, + DISPONIVEL = 0, + BLOQUEADO = 1, + CONCLUIDO = 2, } diff --git a/src/app/services/auth.service.spec.ts b/src/app/services/auth.service.spec.ts deleted file mode 100644 index f1251ca..0000000 --- a/src/app/services/auth.service.spec.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { AuthService } from './auth.service'; - -describe('AuthService', () => { - let service: AuthService; - - beforeEach(() => { - TestBed.configureTestingModule({}); - service = TestBed.inject(AuthService); - }); - - it('should be created', () => { - expect(service).toBeTruthy(); - }); -}); diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts deleted file mode 100644 index 9016788..0000000 --- a/src/app/services/auth.service.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Injectable } from "@angular/core" -import { Usuario } from "../models/Usuario" - -@Injectable({ - providedIn: "root", -}) -export class AuthService { - private usuarioAtual: Usuario - - constructor() { - this.usuarioAtual = new Usuario({ - codigo: "9780", - nome: "Weber Rener Paiva", - uf: "GO", - perfil: "Perito", - }) - } - - getUsuarioAtual(): Usuario { - return this.usuarioAtual - } - - logout() { - this.usuarioAtual = null - } -} diff --git a/src/app/services/exame.service.spec.ts b/src/app/services/exame.service.spec.ts index 90c33f1..c5962c4 100644 --- a/src/app/services/exame.service.spec.ts +++ b/src/app/services/exame.service.spec.ts @@ -1,13 +1,11 @@ import { TestBed } from "@angular/core/testing" import { ExameService } from "./exame.service" import { DatabaseRepository } from "../Repository" -import firebase from "firebase/compat/app" import "firebase/firestore" -import { importProvidersFrom } from "@angular/core" import { AngularFireModule } from "@angular/fire/compat" import { AngularFirestoreModule } from "@angular/fire/compat/firestore" -fdescribe("ExameService", () => { +xdescribe("ExameService", () => { let service: ExameService const firebaseConfig = { apiKey: "AIzaSyDpMfldg10XJfdkap0lsQkfaFTzbVTv3Lo", @@ -18,18 +16,14 @@ fdescribe("ExameService", () => { appId: "1:486118580910:web:de3c6d36d5b1672d86c33f", } - // should config providers like angular main.ts file configuration - beforeEach(() => { + beforeEach(async () => { TestBed.configureTestingModule({ imports: [AngularFireModule.initializeApp(firebaseConfig), AngularFirestoreModule], providers: [DatabaseRepository, { provide: "EYEDROPS_REPOSITORY", useClass: DatabaseRepository }], }) service = TestBed.inject(ExameService) + await service.repository.truncate() }) - it("should access firebase", () => { - service.syncWithFirebase() - - expect(service).toBeTruthy() - }) + it("should block a document", async () => {}) }) diff --git a/src/app/services/exame.service.ts b/src/app/services/exame.service.ts index 4354be7..4a37362 100644 --- a/src/app/services/exame.service.ts +++ b/src/app/services/exame.service.ts @@ -18,19 +18,7 @@ export class ExameService { constructor(@Inject("EYEDROPS_REPOSITORY") public repository: EyedropsRepository) {} - async syncWithFirebase() { - await this.repository - .save(new Exame(new Material("123"))) - .then(() => { - console.log("Document successfully written!") - }) - .catch((error) => { - console.error("Error writing document: ", error) - }) - await this.repository.getByCodigo("0123/2024 GO").then((exame) => { - console.log("getByCodigo => exame", exame) - }) - } + async syncWithFirebase() {} get state$() { return this.state @@ -38,57 +26,64 @@ export class ExameService { getListaPessoas() { const listaPessoas: Usuario[] = [ - { + Usuario.create({ codigo: "0000", nome: "Castro", perfil: "Perito", uf: "GO", - }, - { + }), + Usuario.create({ codigo: "0000", nome: "Clayton", perfil: "Perito", uf: "GO", - }, - { + }), + Usuario.create({ codigo: "0000", nome: "Daniel", perfil: "Perito", uf: "GO", - }, - { + }), + Usuario.create({ codigo: "0000", nome: "Leandro Barcelos", perfil: "Perito", uf: "GO", - }, - { + }), + Usuario.create({ codigo: "0000", nome: "Moreira", perfil: "Perito", uf: "GO", - }, - { + }), + Usuario.create({ codigo: "0000", nome: "Rafael", perfil: "Perito", uf: "GO", - }, - { + }), + Usuario.create({ codigo: "0000", nome: "Eugênio", perfil: "Estagiário", uf: "GO", - }, - { + }), + Usuario.create({ codigo: "0000", nome: "João Pedro", perfil: "Estagiário", uf: "GO", - }, + }), ] return listaPessoas } + + changeUsuarioAtual(usuario: Usuario) { + this.state.update((state) => { + state.usuarioAtual = usuario + return state + }) + } } export type ExameState = { diff --git a/src/index.html b/src/index.html index 54706ab..84f3036 100644 --- a/src/index.html +++ b/src/index.html @@ -14,7 +14,7 @@ - +