Skip to content

Commit 85d4264

Browse files
committed
simplify
1 parent 36f046d commit 85d4264

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

supabase/functions/fetch-scrobbles/db.hooman.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ export class TableHooman extends DbSupabaseTable {
2525
throw new Error("Error fetching hooman: " + JSON.stringify(error));
2626
}
2727

28-
if (null !== data) {
28+
if (data) {
2929
return data.id;
3030
}
3131

32-
const { error: errorCrate } = await this.getSupabase()
32+
const { data: insertData, error: insertError } = await this.getSupabase()
3333
.from(this.tableName)
34-
.insert({
35-
[columnName.lastfm_user]: lastFmUser,
36-
});
34+
.insert({ [columnName.lastfm_user]: lastFmUser })
35+
.select("id")
36+
.maybeSingle<{ id: string }>();
3737

38-
if (errorCrate) {
39-
throw new Error("Error create new hooman: " + JSON.stringify(errorCrate));
38+
if (insertError || !insertData) {
39+
throw new Error("Error creating hooman: " + JSON.stringify(insertError));
4040
}
4141

42-
return this.findOrCreateByLastFmUser(lastFmUser);
42+
return insertData.id;
4343
}
4444
}

0 commit comments

Comments
 (0)