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()));
|
||||
}
|
||||
|
||||
let person = Person {
|
||||
person_id: 0,
|
||||
person_dni: format!("{}", dni),
|
||||
person_names: p.nombres,
|
||||
person_paternal_surname: p.apellidoPaterno,
|
||||
person_maternal_surname: p.apellidoMaterno,
|
||||
};
|
||||
match Person::get_by_dni(dni).await {
|
||||
Ok(p) => return (Status::Ok, Json(p)),
|
||||
Err(error) => {
|
||||
eprintln!("Error fetching person from DB: {:?}", error);
|
||||
|
||||
return (Status::Ok, Json(person));
|
||||
return (Status::InternalServerError, Json(Person::default()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return error
|
||||
|
@ -31,8 +31,8 @@ impl CustomLabel {
|
||||
"SELECT custom_label_id FROM custom_label WHERE custom_label_value = ?",
|
||||
value
|
||||
)
|
||||
.fetch_all(db)
|
||||
.await?;
|
||||
.fetch_all(db)
|
||||
.await?;
|
||||
|
||||
if result.is_empty() {
|
||||
Ok(-1)
|
||||
@ -50,8 +50,8 @@ impl CustomLabel {
|
||||
"INSERT INTO custom_label (custom_label_value) VALUES (?)",
|
||||
value
|
||||
)
|
||||
.execute(db)
|
||||
.await?;
|
||||
.execute(db)
|
||||
.await?;
|
||||
let result = Self::get_id_by_value(value).await?;
|
||||
|
||||
Ok(result)
|
||||
|
@ -34,6 +34,16 @@ impl Person {
|
||||
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)]
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { FilledCard } from "../../components/FilledCard";
|
||||
import { For } from "solid-js";
|
||||
import { For, createSignal } from "solid-js";
|
||||
import { XIcon } from "../../icons/XIcon";
|
||||
import { allCourses } from "../../utils/allCourses";
|
||||
import { RegisterBatchCreate } from "../../types/Register";
|
||||
@ -12,8 +12,18 @@ function isoDateToLocalDate(date: string): string {
|
||||
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}) {
|
||||
const [loading, setLoading] = createSignal(false);
|
||||
|
||||
const submit = async() => {
|
||||
setLoading(true);
|
||||
|
||||
await wait(2000);
|
||||
|
||||
const registers: RegisterBatchCreate = props.selections.map(({courseId, date, customLabel}) => ({
|
||||
person_id: props.personId!,
|
||||
course_id: courseId,
|
||||
@ -32,6 +42,7 @@ export function RegisterPreview(props: {selections: Array<RegistrationPreview>,
|
||||
}
|
||||
|
||||
props.onRegister();
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
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
|
||||
disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
type="button"
|
||||
disabled={props.selections.length === 0}
|
||||
disabled={props.selections.length === 0 || loading()}
|
||||
onclick={submit}
|
||||
>
|
||||
Registrar los {props.selections.length} cursos
|
||||
|
Loading…
Reference in New Issue
Block a user