Skip to content

Commit

Permalink
Fix document ordering
Browse files Browse the repository at this point in the history
Document creation is saved only as a date without time,
to order properly we employ full identifier, which is based
on time.
  • Loading branch information
skodapetr committed Oct 13, 2023
1 parent a51ad5e commit 32e40a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion server/database/directory-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ function getDataFilePath() {
async function listDocuments() {
const result = databaseContent.documents
.map(document => ({...document, "items": undefined}));
result.sort((left, right) => right.created.localeCompare(left.created));
result.sort((left, right) => {
const created = right.created.localeCompare(left.created);
if (created === 0) {
return right.identifier.localeCompare(left.identifier);
} else {
return created;
}
});
return result;
}

Expand Down
9 changes: 8 additions & 1 deletion server/database/file-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ function getDataFilePath() {
async function listDocuments() {
const result = databaseContent.documents
.map(document => ({...document, "items": undefined}));
result.sort((left, right) => right.created.localeCompare(left.created));
result.sort((left, right) => {
const created = right.created.localeCompare(left.created);
if (created === 0) {
return right.identifier.localeCompare(left.identifier);
} else {
return created;
}
});
return result;
}

Expand Down

0 comments on commit 32e40a7

Please sign in to comment.