Clarify datatype sent by GET /register/:dni

This commit is contained in:
Araozu 2023-05-07 19:09:32 -05:00
parent 92291b1ec3
commit b331c03952
3 changed files with 36 additions and 8 deletions

View File

@ -1,6 +1,7 @@
import { Injectable } from "@nestjs/common"; import { Injectable } from "@nestjs/common";
import { DataSource, Repository } from "typeorm"; import { DataSource, Repository } from "typeorm";
import { RegistroGIE } from "../../model/RegistroGIE/registroGIE.entity"; import { RegistroGIE } from "../../model/RegistroGIE/registroGIE.entity";
import { RegisterReturn } from "../../types/RegisterReturn";
@Injectable() @Injectable()
@ -11,10 +12,23 @@ export class CertificateService {
this.registroGIERepository = dataSource.getRepository(RegistroGIE); this.registroGIERepository = dataSource.getRepository(RegistroGIE);
} }
async getByDni(dni: string) { async getByDni(dni: string): Promise<Array<RegisterReturn>> {
return await this.registroGIERepository.findBy({ const data = await this.registroGIERepository.findBy({
dni, dni,
}); });
return data.map((raw): RegisterReturn => ({
id: raw.id,
dni: raw.dni,
nombre: raw.nombre,
curso: raw.curso,
codigo: raw.codigo,
fecha_actual: raw.fecha_actual.toString(),
fecha_inscripcion: raw.fecha_inscripcion.toString(),
curso_nombre: raw.curso_nombre,
personaId: raw.persona?.id,
cursoGIEId: raw.cursoGIE?.id,
}));
} }
async deleteById(id: number) { async deleteById(id: number) {

View File

@ -0,0 +1,16 @@
export interface RegisterReturn {
id: number,
dni: string,
nombre: string,
curso: number,
codigo: number,
/** YYYY-MM-DD */
fecha_actual: string,
/** YYYY-MM-DD */
fecha_inscripcion: string,
curso_nombre: string,
// New fields
personaId?: number,
cursoGIEId?: number,
}

View File

@ -1,12 +1,10 @@
import { Show, createEffect, createSignal, For } from "solid-js"; import { Show, createEffect, createSignal, For } from "solid-js";
import { Person } from "../../types/Person"; import { Person } from "../../types/Person";
import type { RegistroGIE } from "../../model/RegistroGIE/registroGIE.entity"; import { RegisterReturn } from "../../types/RegisterReturn";
export function Registers(props: { person: Person | null }) { export function Registers(props: { person: Person | null }) {
const [loading, setLoading] = createSignal(false); const [loading, setLoading] = createSignal(false);
const [registers, setRegisters] = createSignal<Array<RegistroGIE>>([]); const [registers, setRegisters] = createSignal<Array<RegisterReturn>>([]);
const x: Array<RegistroGIE> = JSON.parse("[{\"id\":12086,\"dni\":\"47269725\",\"nombre\":\"PEÑAFIEL ROJAS NATHALY\",\"curso\":10,\"codigo\":5619,\"fecha_actual\":\"2023-05-06\",\"fecha_inscripcion\":\"2023-05-04\",\"curso_nombre\":\"Matpel I\"},{\"id\":12087,\"dni\":\"47269725\",\"nombre\":\"PEÑAFIEL ROJAS NATHALY\",\"curso\":11,\"codigo\":5620,\"fecha_actual\":\"2023-05-06\",\"fecha_inscripcion\":\"2023-05-05\",\"curso_nombre\":\"Matpel II\"},{\"id\":12088,\"dni\":\"47269725\",\"nombre\":\"PEÑAFIEL ROJAS NATHALY\",\"curso\":1,\"codigo\":1620,\"fecha_actual\":\"2023-05-06\",\"fecha_inscripcion\":\"2023-05-06\",\"curso_nombre\":\"Manejo Defensivo\"}]");
createEffect(() => { createEffect(() => {
const person = props.person; const person = props.person;
@ -23,7 +21,7 @@ export function Registers(props: { person: Person | null }) {
const response = await fetch(`/certificate/${props.person.dni}`); const response = await fetch(`/certificate/${props.person.dni}`);
if (response.ok) { if (response.ok) {
const data: Array<RegistroGIE> = await response.json(); const data: Array<RegisterReturn> = await response.json();
setRegisters(data); setRegisters(data);
} else { } else {
setRegisters([]); setRegisters([]);
@ -82,7 +80,7 @@ export function Registers(props: { person: Person | null }) {
); );
} }
function Register(props: {cert: RegistroGIE, onUpdate: () => void}) { function Register(props: {cert: RegisterReturn, onUpdate: () => void}) {
const [deleteConfirmation, setDeleteConfirmation] = createSignal(false); const [deleteConfirmation, setDeleteConfirmation] = createSignal(false);
const [deleteText, setDeleteText] = createSignal("Eliminar"); const [deleteText, setDeleteText] = createSignal("Eliminar");