feat: edit and resubmit messages (#592)
This commit is contained in:
parent
2e479ccce7
commit
64d1aad2bb
12 changed files with 302 additions and 25 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue