Fixes #1
This commit is contained in:
parent
c9a57406b4
commit
ab7b3f27b6
@ -81,15 +81,14 @@ pub async fn get_by_dni(dni: i32) -> (Status, Json<Person>) {
|
|||||||
return (Status::InternalServerError, Json(Person::default()));
|
return (Status::InternalServerError, Json(Person::default()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let person = Person {
|
match Person::get_by_dni(dni).await {
|
||||||
person_id: 0,
|
Ok(p) => return (Status::Ok, Json(p)),
|
||||||
person_dni: format!("{}", dni),
|
Err(error) => {
|
||||||
person_names: p.nombres,
|
eprintln!("Error fetching person from DB: {:?}", error);
|
||||||
person_paternal_surname: p.apellidoPaterno,
|
|
||||||
person_maternal_surname: p.apellidoMaterno,
|
|
||||||
};
|
|
||||||
|
|
||||||
return (Status::Ok, Json(person));
|
return (Status::InternalServerError, Json(Person::default()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return error
|
// Return error
|
||||||
|
@ -34,6 +34,16 @@ impl Person {
|
|||||||
person_maternal_surname: "".to_string(),
|
person_maternal_surname: "".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_by_dni(dni: i32) -> Result<Person, sqlx::Error> {
|
||||||
|
let db = db();
|
||||||
|
|
||||||
|
let result = sqlx::query_as!(Person, "SELECT * FROM person WHERE person_dni = ?", dni)
|
||||||
|
.fetch_one(db)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FilledCard } from "../../components/FilledCard";
|
import { FilledCard } from "../../components/FilledCard";
|
||||||
import { For } from "solid-js";
|
import { For, createSignal } from "solid-js";
|
||||||
import { XIcon } from "../../icons/XIcon";
|
import { XIcon } from "../../icons/XIcon";
|
||||||
import { allCourses } from "../../utils/allCourses";
|
import { allCourses } from "../../utils/allCourses";
|
||||||
import { RegisterBatchCreate } from "../../types/Register";
|
import { RegisterBatchCreate } from "../../types/Register";
|
||||||
@ -12,8 +12,18 @@ function isoDateToLocalDate(date: string): string {
|
|||||||
return `${day}/${month}`;
|
return `${day}/${month}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wait(ms: number) {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
export function RegisterPreview(props: {selections: Array<RegistrationPreview>, personId: number | null, onDelete: (v: number) => void, onRegister: () => void}) {
|
export function RegisterPreview(props: {selections: Array<RegistrationPreview>, personId: number | null, onDelete: (v: number) => void, onRegister: () => void}) {
|
||||||
|
const [loading, setLoading] = createSignal(false);
|
||||||
|
|
||||||
const submit = async() => {
|
const submit = async() => {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
await wait(2000);
|
||||||
|
|
||||||
const registers: RegisterBatchCreate = props.selections.map(({courseId, date, customLabel}) => ({
|
const registers: RegisterBatchCreate = props.selections.map(({courseId, date, customLabel}) => ({
|
||||||
person_id: props.personId!,
|
person_id: props.personId!,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
@ -32,6 +42,7 @@ export function RegisterPreview(props: {selections: Array<RegistrationPreview>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
props.onRegister();
|
props.onRegister();
|
||||||
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -53,7 +64,7 @@ export function RegisterPreview(props: {selections: Array<RegistrationPreview>,
|
|||||||
class="bg-c-primary text-c-on-primary px-4 py-2 rounded-full cursor-pointer mt-4
|
class="bg-c-primary text-c-on-primary px-4 py-2 rounded-full cursor-pointer mt-4
|
||||||
disabled:opacity-50 disabled:cursor-not-allowed"
|
disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
type="button"
|
type="button"
|
||||||
disabled={props.selections.length === 0}
|
disabled={props.selections.length === 0 || loading()}
|
||||||
onclick={submit}
|
onclick={submit}
|
||||||
>
|
>
|
||||||
Registrar los {props.selections.length} cursos
|
Registrar los {props.selections.length} cursos
|
||||||
|
Loading…
Reference in New Issue
Block a user