---
# System prepended metadata

title: Saved Searches Technical Refinement

---

# ASR-335 Saved search - change history - Technical Refinement 


#### APPEALS-45662 - Create SavedSearch model

###### SavedSearch model:
- `saved_search: belong_to a user`
- `user: has_many: saved_searches`
- `saved_search :validation: limit saved_searches to 10 per user`

###### SavedSearch Migration:
 Columns:
- `search_name: String`
- `search_description: String`
- `user_id: int` 
- `saved_search: jsonB`
-    e.g 
```
{
    search_name: "Search name"
    search_description: "This search fillters ..."
    user_id: 12
    saved_search: {
      report_type: ["Event/Action", "Status"],
      status_report_type: ["Last Action Taken", "Summary"],
      events: {0: "added_issue", 1: "claim_created", 2: "claim_closed", 3: "claim_status_inprogress", 4: "added_decision_date", 5: "added_issue_no_decision_date", 6: "claim_status_incomplete", 7: "completed_disposition", 8: "removed_issue", 9: "withdrew_issue"},
      timing: {"range"=>"after", "start_date"=>"2024-04-30T05:00:00.000Z"},
      statuses: ["Incomplete", "In Progress", "Completed", "Cancelled"],
      days_waiting: { comparison_operator: "moreThan", value_one:"23"},
      decision_review_type: ["Higher-Level Reviews", "Supplemental Claims"],
      issue_type: { 0: "Beneficiary Travel" },
      issue_disposition: ["Dismissed", "Blank", "Denied", "DTA Error", "Granted", "withdrawn"],
      personnel: {},
      facility: { "101":"VACO" }
}
```


#### APPEALS-45663	Create SavedSearch seed data/factories	
- New file `db/seeds/vha_saved_search.rb`
- create 10 seaved searchs per 10 users

#### APPEALS-45664	Creation of Saved Search controller

- Create SavedSearchController
* SavedSearch object
```
{
    id: integer
    search_name: String
    search_description: String 
    user_id: int 
    saved_search: jsonB 
    created_at: datetime(iso 8601)
    updated_at: datetime(iso 8601)
}
```
----
#### * POST /users/:user_id/saved_searches

  Creates a new Saved Search, that belongs to a user and returns 200 success.
* **URL Params**  
  *Required:* `user_id=[integer]`
* **Headers**  
  Content-Type: application/json  
* **Data Params**  
```
  {
    search_name: String
    search_description: String 
    saved_search: jsonB 
  }
```
* **Success Response:**  
  * **Code:** 204 No Content
  **Content:**  `{ "Success creating message" }` 
* **Error Response:**  
  * **Code:** 404  
  **Content:** `{ error : " User has more than 10 Saved Searchs saved" }`  
----
#### * DELETE /users/:user_id/saved_searches/:id**

  Deletes the specified saved_searches.
* **URL Params**  
  *Required:* `id=[integer]`
  *Required:* `user_id=[integer]`
* **Data Params**  
  None
* **Headers**  
  Content-Type: application/json  
  Authorization: Bearer `<OAuth Token>`
* **Success Response:** 
  * **Code:** 204 No Content
* **Error Response:**  
  * **Code:** 404  
  **Content:** `{ error : "Saved Searches doesn't exist" }`  
  OR  
  * **Code:** 401  
  **Content:** `{ error : error : "You are unauthorized to make this request." }`
----  
####  * GET /saved_searches

  Returns all SavedSearches in the system.
* **URL Params**  
  None
* **Data Params**  
  None
* **Headers**  
  Content-Type: application/json  
* **Success Response:**  
* **Code:** 200  
  **Content:**  
```
{
  SavedSearches: [
           {<saved_search_object>},
           {<saved_search_object>},
           {<saved_search_object>}
         ]
}
```

----  
####  * GET /users/:id/saved_searches**

  Returns all Saved Searches associated with the specified User.
* **URL Params**  
  *Required:* `id=[integer]`
* **Data Params**  
  None
* **Headers**  
  Content-Type: application/json  
  Authorization: Bearer `<OAuth Token>`
* **Success Response:**   
     * **Code:** 200  
 ```{
  count: 3, # Sum of saved serach per user ?
  saved_searches: [ 
           {<...saved_search_object},
           {<...saved_search_object>},
           {<...saved_search_object>}
         ]
    }
```

* **Error Response:**  
  * **Code:** 404  
  **Content:** `{ error : "user doesn't exist" }`  
  OR  
  * **Code:** 401  
  **Content:** `{ error : error : "You are unauthorized to make this request." }`

#### APPEALS-45336	Creation of Saved Searches page and ‘View saved searches’ button on Generate task report page



#### APPEALS-45665	Creation of Saved Searches table on Saved Searches page	Story

#### APPEALS-45666	Populate tabs on Saved Searches page

#### APPEALS-45667	Creation of ‘Delete’ button on Saved Searches page	Story

#### APPEALS-45668	Creation of ‘Apply’ button on Saved Searches page	Story

#### APPEALS-45669	Creation of ‘Save search’ button on Generate task report page


#### APPEALS-45670	Creation of ‘Save your search’ modal		

#### APPEALS-45671	Creation of ‘Limit Reached’ modal		

#### APPEALS-45672	Creation of ‘Delete search’ modal on Saved Searches page – My saved search tab