Fix db query to restore previous doc version (#498)
This commit is contained in:
parent
d948b99719
commit
c5f6ac8deb
2 changed files with 15 additions and 5 deletions
|
|
@ -11,6 +11,7 @@ import {
|
||||||
User,
|
User,
|
||||||
document,
|
document,
|
||||||
Suggestion,
|
Suggestion,
|
||||||
|
suggestion,
|
||||||
Message,
|
Message,
|
||||||
message,
|
message,
|
||||||
vote,
|
vote,
|
||||||
|
|
@ -227,6 +228,15 @@ export async function deleteDocumentsByIdAfterTimestamp({
|
||||||
timestamp: Date;
|
timestamp: Date;
|
||||||
}) {
|
}) {
|
||||||
try {
|
try {
|
||||||
|
await db
|
||||||
|
.delete(suggestion)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(suggestion.documentId, id),
|
||||||
|
gt(suggestion.documentCreatedAt, timestamp)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return await db
|
return await db
|
||||||
.delete(document)
|
.delete(document)
|
||||||
.where(and(eq(document.id, id), gt(document.createdAt, timestamp)));
|
.where(and(eq(document.id, id), gt(document.createdAt, timestamp)));
|
||||||
|
|
@ -244,7 +254,7 @@ export async function saveSuggestions({
|
||||||
suggestions: Array<Suggestion>;
|
suggestions: Array<Suggestion>;
|
||||||
}) {
|
}) {
|
||||||
try {
|
try {
|
||||||
return await db.insert(Suggestion).values(suggestions);
|
return await db.insert(suggestion).values(suggestions);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to save suggestions in database');
|
console.error('Failed to save suggestions in database');
|
||||||
throw error;
|
throw error;
|
||||||
|
|
@ -259,8 +269,8 @@ export async function getSuggestionsByDocumentId({
|
||||||
try {
|
try {
|
||||||
return await db
|
return await db
|
||||||
.select()
|
.select()
|
||||||
.from(Suggestion)
|
.from(suggestion)
|
||||||
.where(and(eq(Suggestion.documentId, documentId)));
|
.where(and(eq(suggestion.documentId, documentId)));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
console.error(
|
||||||
'Failed to get suggestions by document version from database'
|
'Failed to get suggestions by document version from database'
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ export const document = pgTable(
|
||||||
|
|
||||||
export type Document = InferSelectModel<typeof document>;
|
export type Document = InferSelectModel<typeof document>;
|
||||||
|
|
||||||
export const Suggestion = pgTable(
|
export const suggestion = pgTable(
|
||||||
'Suggestion',
|
'Suggestion',
|
||||||
{
|
{
|
||||||
id: uuid('id').notNull().defaultRandom(),
|
id: uuid('id').notNull().defaultRandom(),
|
||||||
|
|
@ -106,4 +106,4 @@ export const Suggestion = pgTable(
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
export type Suggestion = InferSelectModel<typeof Suggestion>;
|
export type Suggestion = InferSelectModel<typeof suggestion>;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue