Skip to content

Commit

Permalink
Merge pull request #66 from SystemEngineeringTeam/issue/47-insert-cra…
Browse files Browse the repository at this point in the history
…zy_score

feat: crazy_scoreをDBに保存する関数の実装
  • Loading branch information
SatooRu65536 authored Nov 5, 2024
2 parents d074afe + 15214ba commit 764d578
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/utils/upsertCrazyScore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { supabase } from './supabase/client';
import type { Tables, TablesInsert } from '@/types/supabase';

const upsertCrazyScore = async (
table: Omit<TablesInsert<'crazy_score'>, 'id' | 'created_at' | 'deleted_at'>,
): Promise<Tables<'crazy_score'> | undefined> => {
const { data, error } = await supabase.from('crazy_score').upsert(table).select('*');

if (error !== null) {
throw new Error(error.message);
}
if (data === null) {
throw new Error('Error return data is null');
}
if (data.length === 0) {
throw new Error('Error return data length is 0');
}

return data[0];
};

export default upsertCrazyScore;

0 comments on commit 764d578

Please sign in to comment.