Skip to content

Commit 972dcce

Browse files
committed
refactor: update article deletion logic to use lte for date comparison
- Modified the article cleanup service to use lte (less than or equal) instead of lt (less than) for the delete_scheduled_at comparison, ensuring articles are deleted correctly when the scheduled time is reached. - Added a comma for consistency in error messages in the search service. These changes improve the accuracy of article deletion and enhance code consistency.
1 parent 1795485 commit 972dcce

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/backend/services/article-cleanup-service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use server";
2-
import { and, lt, neq } from "sqlkit";
2+
import { and, lt, lte, neq } from "sqlkit";
33
import { persistenceRepository } from "../persistence/persistence-repositories";
44
import { handleActionException } from "./RepositoryException";
55
import { deleteArticleById } from "./search.service";
@@ -14,7 +14,7 @@ export async function deleteExpiredArticles() {
1414
const articlesToDelete = await persistenceRepository.article.find({
1515
where: and(
1616
neq("delete_scheduled_at", null),
17-
lt("delete_scheduled_at", currentTime)
17+
lte("delete_scheduled_at", currentTime),
1818
),
1919
});
2020

@@ -25,12 +25,12 @@ export async function deleteExpiredArticles() {
2525
const deleteResult = await persistenceRepository.article.delete({
2626
where: and(
2727
neq("delete_scheduled_at", null),
28-
lt("delete_scheduled_at", currentTime)
28+
lte("delete_scheduled_at", currentTime),
2929
),
3030
});
3131

3232
console.log(
33-
`Successfully deleted ${deleteResult?.rowCount} expired articles`
33+
`Successfully deleted ${deleteResult?.rowCount} expired articles`,
3434
);
3535

3636
return {

src/backend/services/search.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const syncArticleById = async (articleId: string) => {
7171

7272
if (!article) {
7373
throw new Error(
74-
`Article with ID ${articleId} not found or not published.`
74+
`Article with ID ${articleId} not found or not published.`,
7575
);
7676
}
7777

@@ -91,6 +91,7 @@ export const syncArticleById = async (articleId: string) => {
9191
console.error(`Error syncing article ${articleId}:`, error);
9292
}
9393
};
94+
9495
export const deleteArticleById = async (articleId: string) => {
9596
try {
9697
const response = await index.deleteDocument(articleId);

0 commit comments

Comments
 (0)