list conversations

send sms
begin webhooks
This commit is contained in:
m5r
2021-07-21 00:28:56 +08:00
parent 3762305c4f
commit 6a12d0cd93
25 changed files with 915 additions and 86 deletions

View File

@ -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)