Skip to content

Commit

Permalink
fix: denoはaxiosに対応していなかったので、fetchAPIで対応
Browse files Browse the repository at this point in the history
  • Loading branch information
Yamamoto1012 committed Oct 27, 2024
1 parent 81c0c5c commit d01c0da
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions pointRanking/supabase/functions/monthRankingRender/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { serve } from "https://deno.land/std/http/server.ts";
import { createClient } from "https://esm.sh/@supabase/supabase-js@2";
import axios from 'https://cdn.skypack.dev/axios';

const supabaseUrl = Deno.env.get("SUPABASE_URL") || "";
const supabaseServiceRoleKey = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY") || "";
Expand Down Expand Up @@ -30,14 +29,20 @@ serve(async (req) => {
const { data: rankingData, error } = await supabase
.from("MonthLog")
.select("user_id, month_total_point")
.eq("result_month", currentMonth)
.eq("result_month", `${currentMonth}-01`) // 正しい日付形式に修正
.order("month_total_point", { ascending: false })
.limit(10);

if (error) {
console.error("MonthLogテーブルの取得エラー:", error);
await axios.post(slackWebhookUrl, {
text: "データの取得に失敗しました",
await fetch(slackWebhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
text: "データの取得に失敗しました",
}),
});
return new Response("データの取得に失敗しました", { status: 500 });
}
Expand All @@ -51,8 +56,14 @@ serve(async (req) => {

if (usersError) {
console.error("Userテーブルの取得エラー:", usersError);
await axios.post(slackWebhookUrl, {
text: "データの取得に失敗しました",
await fetch(slackWebhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
text: "データの取得に失敗しました",
}),
});
return new Response("データの取得に失敗しました", { status: 500 });
}
Expand All @@ -78,8 +89,14 @@ serve(async (req) => {
.join("\n");

// ランキングをSlackに投稿
await axios.post(slackWebhookUrl, {
text: `今月のポイントランキング\n${rankingText}`,
await fetch(slackWebhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
text: `今月のポイントランキング\n${rankingText}`,
}),
});

return new Response("OK", { status: 200 });
Expand Down

0 comments on commit d01c0da

Please sign in to comment.