list conversations
send sms begin webhooks
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import appLogger from "../../lib/logger";
|
||||
import supabase from "../supabase/server";
|
||||
import { computeEncryptionKey } from "./_encryption";
|
||||
import { findPhoneNumber } from "./phone-number";
|
||||
|
||||
const logger = appLogger.child({ module: "customer" });
|
||||
|
||||
@ -8,11 +9,12 @@ export type Customer = {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string;
|
||||
paddleCustomerId: string;
|
||||
paddleSubscriptionId: string;
|
||||
accountSid: string;
|
||||
authToken: string;
|
||||
encryptionKey: string;
|
||||
accountSid?: string;
|
||||
authToken?: string; // TODO: should encrypt it
|
||||
twimlAppSid?: string;
|
||||
paddleCustomerId?: string;
|
||||
paddleSubscriptionId?: string;
|
||||
};
|
||||
|
||||
type CreateCustomerParams = Pick<Customer, "id" | "email" | "name">;
|
||||
@ -47,6 +49,19 @@ export async function findCustomer(id: Customer["id"]): Promise<Customer> {
|
||||
return data!;
|
||||
}
|
||||
|
||||
export async function findCustomerByPhoneNumber(phoneNumber: string): Promise<Customer> {
|
||||
const { customerId } = await findPhoneNumber(phoneNumber);
|
||||
const { error, data } = await supabase
|
||||
.from<Customer>("customer")
|
||||
.select("*")
|
||||
.eq("id", customerId)
|
||||
.single();
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
return data!;
|
||||
}
|
||||
|
||||
export async function updateCustomer(id: string, update: Partial<Customer>) {
|
||||
await supabase.from<Customer>("customer")
|
||||
.update(update)
|
||||
|
Reference in New Issue
Block a user