Repository navigation
Migrate reviews to resource_edits table #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fe9a218
Migrate reviews to resource_edits table
tayloraj10 f195914
Merge branch 'main' into migrate-to-resource-edits-table
tayloraj10 b386366
Fix Biome formatting/import-order issues from merge
tayloraj10 5779b83
Add pre-bundling configuration for @mui/icons-material in Vite
tayloraj10 eae5169
Update .gitignore to include local notes and remove next-up.md file
tayloraj10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,3 +9,6 @@ | |
|
|
||
| # Amplify build output | ||
| /.amplify-hosting/ | ||
|
|
||
| # Local notes | ||
| docs/next-up.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import type { SupabaseClient } from "@supabase/supabase-js"; | ||
| import type { | ||
| EditReviewStatus, | ||
| ResourceEdit, | ||
| ResourceEditQueueRow, | ||
| } from "~/types/ResourceEdit"; | ||
| import type { ResourceEntry } from "~/types/ResourceEntry"; | ||
|
|
||
| const TABLE_NAME = "resource_edits"; | ||
|
|
||
| export const getResourceEditAPI = (client: SupabaseClient) => { | ||
| const table = client.from(TABLE_NAME); | ||
|
|
||
| return { | ||
| /** All pending edits to existing resources, joined to the current resource for compare. */ | ||
| getEditsQueue: async () => { | ||
| const { data, error } = await client | ||
| .from("resource_edits_queue") | ||
| .select("*") | ||
| .order("submitted_at", { ascending: false }); | ||
|
|
||
| if (error) { | ||
| throw error; | ||
| } | ||
|
|
||
| return (data ?? []) as ResourceEditQueueRow[]; | ||
| }, | ||
| /** All pending brand-new site submissions (no mapped_resource). */ | ||
| getNewResourcesQueue: async () => { | ||
| const { data, error } = await client | ||
| .from("new_resources_queue") | ||
| .select("*") | ||
| .order("submitted_at", { ascending: false }); | ||
|
|
||
| if (error) { | ||
| throw error; | ||
| } | ||
|
|
||
| return (data ?? []) as ResourceEdit[]; | ||
| }, | ||
| getList: async (params: { review_status?: EditReviewStatus } = {}) => { | ||
| let query = table.select("*").order("submitted_at", { ascending: false }); | ||
|
|
||
| if (params.review_status) { | ||
| query = query.eq("review_status", params.review_status); | ||
| } | ||
|
|
||
| const { data, error } = await query; | ||
|
|
||
| if (error) { | ||
| throw error; | ||
| } | ||
|
|
||
| return (data ?? []) as ResourceEdit[]; | ||
| }, | ||
| getById: async (id: number) => { | ||
| const { data, error } = await table | ||
| .select("*") | ||
| .eq("id", id) | ||
| .single<ResourceEdit>(); | ||
|
|
||
| if (error) { | ||
| throw error; | ||
| } | ||
|
|
||
| return data; | ||
| }, | ||
| /** Partial update to the proposed values while an edit is PENDING. */ | ||
| updateFields: async (id: number, values: Partial<ResourceEntry>) => { | ||
| const { data, error } = await table | ||
| .update(values) | ||
| .eq("id", id) | ||
| .select() | ||
| .single<ResourceEdit>(); | ||
|
|
||
| if (error) { | ||
| throw error; | ||
| } | ||
|
|
||
| return data; | ||
| }, | ||
| /** Approves the edit via the `approve_edit` RPC — applies it to `resources` | ||
| * (updating the mapped resource, or inserting a new one) so the change | ||
| * goes live on the map. Returns the resulting `resources` row. */ | ||
| approve: async (id: number, reviewer: string) => { | ||
| const { data, error } = await client | ||
| .rpc("approve_edit", { p_edit_id: id, p_reviewer: reviewer }) | ||
| .single<ResourceEntry & { id: number }>(); | ||
|
|
||
| if (error) { | ||
| throw error; | ||
| } | ||
|
|
||
| return data; | ||
| }, | ||
| reject: async (id: number, reviewer: string, notes?: string) => { | ||
| const { data, error } = await client | ||
| .rpc("reject_edit", { | ||
| p_edit_id: id, | ||
| p_reviewer: reviewer, | ||
| p_notes: notes ?? null, | ||
| }) | ||
| .single<ResourceEdit>(); | ||
|
|
||
| if (error) { | ||
| throw error; | ||
| } | ||
|
|
||
| return data; | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| export default getResourceEditAPI; |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, we run aggregation queries on the database level instead of manipulating the data in code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix in a future PR, have an issue to track this