generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 11
/
user.ts
34 lines (30 loc) · 1.38 KB
/
user.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { SupabaseClient } from "@supabase/supabase-js";
import { Super } from "./supabase";
import { Context } from "../../../types/context";
import { addCommentToIssue } from "../../../utils/issue";
type Wallet = {
address: string;
};
export class User extends Super {
constructor(supabase: SupabaseClient, context: Context) {
super(supabase, context);
}
async getWalletByUserId(userId: number, issueNumber: number) {
const { data, error } = (await this.supabase.from("users").select("wallets(*)").eq("id", userId).single()) as { data: { wallets: Wallet }; error: unknown };
if (this.context.config.emptyWalletText) {
return null;
}
if ((error && !data) || !data.wallets?.address) {
this.context.logger.error("No wallet address found", { userId, issueNumber });
if (this.context.config.startRequiresWallet) {
await addCommentToIssue(this.context, "```diff\n! Please set your wallet address with the /wallet command first and try again.\n```");
throw new Error("No wallet address found");
} else {
await addCommentToIssue(this.context, "```diff\n# Please set your wallet address with the /wallet command in order to be eligible for rewards.\n```");
}
} else {
this.context.logger.info("Successfully fetched wallet", { userId, address: data.wallets?.address });
}
return data?.wallets?.address || null;
}
}