-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to refresh debate bill match view via endpoint
- Loading branch information
1 parent
b65e7f7
commit 5dab9b6
Showing
6 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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,11 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
source ../.env | ||
source ../lib/functions/deploy.sh | ||
source ../lib/functions/run.sh | ||
|
||
FUNCTION_NAME="refresh-debate-bill-match-view" | ||
|
||
deploy "$SUPABASE_PROJECT_ID" "$FUNCTION_NAME" | ||
run "$SUPABASE_PROJECT_ID" "$SUPABASE_SERVICE_ROLE_KEY" "$FUNCTION_NAME" '{}' |
This file contains 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
This file contains 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
23 changes: 23 additions & 0 deletions
23
supabase/functions/lib/shared-functions/refresh-debate-bill-match-view.ts
This file contains 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,23 @@ | ||
import { createSupabase } from "../utils/create-supabase.ts"; | ||
import { isAdmin } from "../utils/check-admin.ts"; | ||
import buildResponseProxy from "../utils/build-response-proxy.ts"; | ||
|
||
async function refresh() { | ||
const supabase = createSupabase(); | ||
const { error } = await supabase.rpc("refresh_materialized_view", { | ||
view_name: "public.debate_bill_match_view", | ||
}); | ||
if (error) throw error; | ||
} | ||
|
||
export default async function refreshDebateBillMatchView(req: Request) { | ||
if (!isAdmin(req)) { | ||
return buildResponseProxy({ message: "Unauthorised." }, 401); | ||
} | ||
|
||
await refresh(); | ||
|
||
return buildResponseProxy({ | ||
message: "Refreshed debate_bill_match_view.", | ||
}); | ||
} |
This file contains 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,5 @@ | ||
import "https://esm.sh/@supabase/functions-js/src/edge-runtime.d.ts"; | ||
import proxyToResponseWrapper from "../lib/utils/proxy-to-response-wrapper.ts"; | ||
import refreshDebateBillMatchView from "../lib/shared-functions/refresh-debate-bill-match-view.ts"; | ||
|
||
Deno.serve(proxyToResponseWrapper(refreshDebateBillMatchView)); |
This file contains 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