[BE] Fix bug in register fetch
This commit is contained in:
parent
a0e15e5bfd
commit
3734c49084
5
backend/Cargo.lock
generated
5
backend/Cargo.lock
generated
@ -1970,6 +1970,7 @@ dependencies = [
|
|||||||
"atoi",
|
"atoi",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
"chrono",
|
||||||
"crc",
|
"crc",
|
||||||
"crossbeam-queue",
|
"crossbeam-queue",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
@ -2034,6 +2035,7 @@ dependencies = [
|
|||||||
"sha2",
|
"sha2",
|
||||||
"sqlx-core",
|
"sqlx-core",
|
||||||
"sqlx-mysql",
|
"sqlx-mysql",
|
||||||
|
"sqlx-postgres",
|
||||||
"sqlx-sqlite",
|
"sqlx-sqlite",
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
@ -2052,6 +2054,7 @@ dependencies = [
|
|||||||
"bitflags 2.4.0",
|
"bitflags 2.4.0",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
"chrono",
|
||||||
"crc",
|
"crc",
|
||||||
"digest",
|
"digest",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
@ -2093,6 +2096,7 @@ dependencies = [
|
|||||||
"base64",
|
"base64",
|
||||||
"bitflags 2.4.0",
|
"bitflags 2.4.0",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
|
"chrono",
|
||||||
"crc",
|
"crc",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"etcetera",
|
"etcetera",
|
||||||
@ -2129,6 +2133,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "be4c21bf34c7cae5b283efb3ac1bcc7670df7561124dc2f8bdc0b59be40f79a2"
|
checksum = "be4c21bf34c7cae5b283efb3ac1bcc7670df7561124dc2f8bdc0b59be40f79a2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atoi",
|
"atoi",
|
||||||
|
"chrono",
|
||||||
"flume",
|
"flume",
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
@ -8,7 +8,7 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
reqwest = { version = "0.11", features = ["json"] }
|
reqwest = { version = "0.11", features = ["json"] }
|
||||||
rocket = { version = "=0.5.0-rc.3" , features = ["json", "msgpack", "uuid"] }
|
rocket = { version = "=0.5.0-rc.3" , features = ["json", "msgpack", "uuid"] }
|
||||||
sqlx = { version = "0.7.1", features = [ "runtime-tokio", "tls-rustls", "mysql", "macros" ] }
|
sqlx = { version = "0.7.1", features = [ "runtime-tokio", "tls-rustls", "mysql", "macros", "chrono" ] }
|
||||||
once_cell = "1.18.0"
|
once_cell = "1.18.0"
|
||||||
dotenvy = "0.15.7"
|
dotenvy = "0.15.7"
|
||||||
serde = "1.0.188"
|
serde = "1.0.188"
|
||||||
|
@ -22,28 +22,15 @@ pub async fn insert_all(data: Json<Vec<RegisterCreate>>) -> Status {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/register/<dni>")]
|
#[get("/register/<dni>")]
|
||||||
pub async fn get_by_dni(dni: i32) -> Json<Vec<Register>> {
|
pub async fn get_by_dni(dni: i32) -> (Status, Json<Vec<Register>>) {
|
||||||
let r1 = Register {
|
let registers = Register::get_by_dni(dni).await;
|
||||||
register_id: 1,
|
|
||||||
register_code: 322,
|
|
||||||
register_creation_date: "2021-01-01".to_string(),
|
|
||||||
register_display_date: "2021-01-01".to_string(),
|
|
||||||
register_custom_label: "".to_string(),
|
|
||||||
register_person_id: 1,
|
|
||||||
register_course_id: 1,
|
|
||||||
register_is_preview: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
let r2 = Register {
|
match registers {
|
||||||
register_id: 2,
|
Ok(data) => (Status::Ok, Json(data)),
|
||||||
register_code: 323,
|
Err(err) => {
|
||||||
register_creation_date: "2021-01-01".to_string(),
|
eprintln!("{:?}", err);
|
||||||
register_display_date: "2021-01-03".to_string(),
|
|
||||||
register_custom_label: "".to_string(),
|
|
||||||
register_person_id: 1,
|
|
||||||
register_course_id: 2,
|
|
||||||
register_is_preview: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
Json(vec![r1, r2])
|
(Status::InternalServerError, Json(vec![]))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,3 +109,28 @@ impl RegisterCreate {
|
|||||||
Ok(new_max)
|
Ok(new_max)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Register {
|
||||||
|
pub async fn get_by_dni(dni: i32) -> Result<Vec<Register>, sqlx::Error> {
|
||||||
|
let db = db();
|
||||||
|
|
||||||
|
let res = sqlx::query!("SELECT * FROM register
|
||||||
|
WHERE register_person_id = (SELECT person_id FROM person WHERE person_dni = ?)", dni)
|
||||||
|
.fetch_all(db)
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.map(|r| Register {
|
||||||
|
register_id: r.register_id,
|
||||||
|
register_code: r.register_code,
|
||||||
|
register_creation_date: r.register_creation_date.format("%Y-%m-%d").to_string(),
|
||||||
|
register_display_date: r.register_display_date.format("%Y-%m-%d").to_string(),
|
||||||
|
register_custom_label: r.register_custom_label,
|
||||||
|
register_is_preview: r.register_is_preview == 1,
|
||||||
|
register_person_id: r.register_person_id,
|
||||||
|
register_course_id: r.register_course_id,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Ok(res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -12,8 +12,6 @@ function isoDateToLocalDate(date: string): string {
|
|||||||
|
|
||||||
export function RegisterPreview(props: {selections: Array<[number, string]>, personId: number | null, onDelete: (v: number) => void, onRegister: () => void}) {
|
export function RegisterPreview(props: {selections: Array<[number, string]>, personId: number | null, onDelete: (v: number) => void, onRegister: () => void}) {
|
||||||
const submit = async() => {
|
const submit = async() => {
|
||||||
console.log("Submit...");
|
|
||||||
|
|
||||||
const registers: RegisterBatchCreate = props.selections.map(([courseId, date]) => ({
|
const registers: RegisterBatchCreate = props.selections.map(([courseId, date]) => ({
|
||||||
person_id: props.personId!,
|
person_id: props.personId!,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
|
@ -10,7 +10,7 @@ export function Certs() {
|
|||||||
return (
|
return (
|
||||||
<div class="grid grid-cols-[16rem_25rem_1fr]">
|
<div class="grid grid-cols-[16rem_25rem_1fr]">
|
||||||
<Search setPerson={setPerson} />
|
<Search setPerson={setPerson} />
|
||||||
<NewRegister personId={0} onSuccess={() => {}} />
|
<NewRegister personId={person()?.person_id ?? -1} onSuccess={() => {}} />
|
||||||
<Registers person={person()} />
|
<Registers person={person()} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user