feat: edit and resubmit messages (#592)

This commit is contained in:
Jeremy 2024-12-05 15:29:33 +03:00 committed by GitHub
parent 2e479ccce7
commit 64d1aad2bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 302 additions and 25 deletions

View file

@ -1,7 +1,7 @@
import 'server-only';
import { genSaltSync, hashSync } from 'bcrypt-ts';
import { and, asc, desc, eq, gt } from 'drizzle-orm';
import { and, asc, desc, eq, gt, gte } from 'drizzle-orm';
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
@ -279,3 +279,33 @@ export async function getSuggestionsByDocumentId({
throw error;
}
}
export async function getMessageById({ id }: { id: string }) {
try {
return await db.select().from(message).where(eq(message.id, id));
} catch (error) {
console.error('Failed to get message by id from database');
throw error;
}
}
export async function deleteMessagesByChatIdAfterTimestamp({
chatId,
timestamp,
}: {
chatId: string;
timestamp: Date;
}) {
try {
return await db
.delete(message)
.where(
and(eq(message.chatId, chatId), gte(message.createdAt, timestamp)),
);
} catch (error) {
console.error(
'Failed to delete messages by id after timestamp from database',
);
throw error;
}
}