Skip to content

Commit

Permalink
fix(server): validate when if field
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 committed Apr 9, 2024
1 parent 0c61c8f commit a16495c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/modules/ticket/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async fn process_ticket_flow<'a>(
}

let process_schema = process_flow
.get_schema(&mut conn)
.get_schema(&mut conn, &user)
.await
.map_err(|err| AppError::internal(err.to_string()))?;

Expand Down
37 changes: 27 additions & 10 deletions src/modules/ticket/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ impl TicketSchemaFlow {
pub async fn get_detail(
&self,
conn: &mut crate::DbConn,
optional_user: Option<&User>
) -> Result<TicketSchemaFlowItem, diesel::result::Error> {
let (flow, form, review) = ticket_schema_flows::table
.filter(ticket_schema_flows::id.eq(self.id))
Expand All @@ -500,15 +501,30 @@ impl TicketSchemaFlow {
.load(conn)
.await?;

let mut form_schema = FormSchema {
form,
fields: fields
.iter()
.cloned()
.filter(|field| field.ticket_schema_form_id == form_id)
.collect::<Vec<_>>(),
};
form_schema.fields.sort_by_key(|field| field.order);
if let Some(user) = optional_user {
let form_schema = FormSchema::new_with_user(
conn,
user,
form,
fields
.iter()
.cloned()
.filter(|field| field.ticket_schema_form_id == form_id)
.collect::<Vec<_>>(),
)
.await;

return Ok(TicketSchemaFlowItem {
schema: flow,
module: TicketSchemaFlowValue::Form(form_schema),
});
}

let form_schema = FormSchema::new(form, fields
.iter()
.cloned()
.filter(|field| field.ticket_schema_form_id == form_id)
.collect::<Vec<_>>());

return Ok(TicketSchemaFlowItem {
schema: flow,
Expand Down Expand Up @@ -970,10 +986,11 @@ impl TicketFlow {
pub async fn get_schema(
&self,
conn: &mut crate::DbConn,
user: &User,
) -> Result<TicketSchemaFlowItem, diesel::result::Error> {
let schema_flow = TicketSchemaFlow::find(conn, self.ticket_schema_flow_id).await?;

schema_flow.get_detail(conn).await
schema_flow.get_detail(conn, Some(user)).await
}

pub async fn save(&self, conn: &mut crate::DbConn) -> Result<usize, diesel::result::Error> {
Expand Down

0 comments on commit a16495c

Please sign in to comment.