metamigo-db: build, fmt, lint
This commit is contained in:
parent
2ffb15b1f9
commit
2a1ced5383
17 changed files with 160 additions and 125 deletions
|
|
@ -1,48 +0,0 @@
|
|||
import { RepositoryBase, recordInfo, UUID, Flavor } from "@digiresilience/metamigo-common";
|
||||
|
||||
export type WhatsappBotId = Flavor<UUID, "Whatsapp Bot Id">;
|
||||
|
||||
export interface UnsavedWhatsappBot {
|
||||
phoneNumber: string;
|
||||
userId: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface SavedWhatsappBot extends UnsavedWhatsappBot {
|
||||
id: WhatsappBotId;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
token: string;
|
||||
authInfo: string;
|
||||
qrCode: string;
|
||||
isVerified: boolean;
|
||||
}
|
||||
|
||||
export const WhatsappBotRecord = recordInfo<
|
||||
UnsavedWhatsappBot,
|
||||
SavedWhatsappBot
|
||||
>("app_public", "whatsapp_bots");
|
||||
|
||||
export class WhatsappBotRecordRepository extends RepositoryBase(
|
||||
WhatsappBotRecord
|
||||
) {
|
||||
async updateQR(
|
||||
bot: SavedWhatsappBot,
|
||||
qrCode: string | undefined
|
||||
): Promise<SavedWhatsappBot> {
|
||||
return this.db.one(
|
||||
"UPDATE $1 SET (qr_code) = ROW($2) WHERE id = $3 RETURNING *",
|
||||
[this.schemaTable, qrCode, bot.id]
|
||||
);
|
||||
}
|
||||
|
||||
async updateAuthInfo(
|
||||
bot: SavedWhatsappBot,
|
||||
authInfo: string | undefined
|
||||
): Promise<SavedWhatsappBot> {
|
||||
return this.db.one(
|
||||
"UPDATE $1 SET (auth_info, is_verified) = ROW($2, true) WHERE id = $3 RETURNING *",
|
||||
[this.schemaTable, authInfo, bot.id]
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue