mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 14:44:43 -04:00
feat(note): save createdAt in a separate column
To keep the createdAt date stable, even when the revisions are dropped, this adds a separate column to store this data separately from revisions. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
342efcd7b7
commit
09ec447069
4 changed files with 10 additions and 6 deletions
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
Column,
|
Column,
|
||||||
|
CreateDateColumn,
|
||||||
Entity,
|
Entity,
|
||||||
JoinTable,
|
JoinTable,
|
||||||
ManyToMany,
|
ManyToMany,
|
||||||
|
@ -94,6 +95,9 @@ export class Note {
|
||||||
})
|
})
|
||||||
version: number;
|
version: number;
|
||||||
|
|
||||||
|
@CreateDateColumn()
|
||||||
|
createdAt: Date;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
private constructor() {}
|
private constructor() {}
|
||||||
|
|
||||||
|
@ -102,7 +106,10 @@ export class Note {
|
||||||
* @param owner The owner of the note
|
* @param owner The owner of the note
|
||||||
* @param alias Optional primary alias
|
* @param alias Optional primary alias
|
||||||
*/
|
*/
|
||||||
public static create(owner: User | null, alias?: string): Omit<Note, 'id'> {
|
public static create(
|
||||||
|
owner: User | null,
|
||||||
|
alias?: string,
|
||||||
|
): Omit<Note, 'id' | 'createdAt'> {
|
||||||
const newNote = new Note();
|
const newNote = new Note();
|
||||||
newNote.publicId = generatePublicId();
|
newNote.publicId = generatePublicId();
|
||||||
newNote.aliases = alias
|
newNote.aliases = alias
|
||||||
|
|
|
@ -775,7 +775,6 @@ describe('NotesService', () => {
|
||||||
expect(metadataDto.aliases).toHaveLength(1);
|
expect(metadataDto.aliases).toHaveLength(1);
|
||||||
expect(metadataDto.aliases[0].name).toEqual((await note.aliases)[0].name);
|
expect(metadataDto.aliases[0].name).toEqual((await note.aliases)[0].name);
|
||||||
expect(metadataDto.title).toEqual(note.title);
|
expect(metadataDto.title).toEqual(note.title);
|
||||||
expect(metadataDto.createdAt).toEqual(revisions[0].createdAt);
|
|
||||||
expect(metadataDto.description).toEqual(note.description);
|
expect(metadataDto.description).toEqual(note.description);
|
||||||
expect(metadataDto.editedBy).toHaveLength(1);
|
expect(metadataDto.editedBy).toHaveLength(1);
|
||||||
expect(metadataDto.editedBy[0]).toEqual(user.username);
|
expect(metadataDto.editedBy[0]).toEqual(user.username);
|
||||||
|
@ -879,7 +878,6 @@ describe('NotesService', () => {
|
||||||
(await note.aliases)[0].name,
|
(await note.aliases)[0].name,
|
||||||
);
|
);
|
||||||
expect(noteDto.metadata.title).toEqual(note.title);
|
expect(noteDto.metadata.title).toEqual(note.title);
|
||||||
expect(noteDto.metadata.createdAt).toEqual(revisions[0].createdAt);
|
|
||||||
expect(noteDto.metadata.description).toEqual(note.description);
|
expect(noteDto.metadata.description).toEqual(note.description);
|
||||||
expect(noteDto.metadata.editedBy).toHaveLength(1);
|
expect(noteDto.metadata.editedBy).toHaveLength(1);
|
||||||
expect(noteDto.metadata.editedBy[0]).toEqual(user.username);
|
expect(noteDto.metadata.editedBy[0]).toEqual(user.username);
|
||||||
|
@ -900,7 +898,6 @@ describe('NotesService', () => {
|
||||||
);
|
);
|
||||||
expect(noteDto.metadata.tags).toHaveLength(1);
|
expect(noteDto.metadata.tags).toHaveLength(1);
|
||||||
expect(noteDto.metadata.tags[0]).toEqual((await note.tags)[0].name);
|
expect(noteDto.metadata.tags[0]).toEqual((await note.tags)[0].name);
|
||||||
expect(noteDto.metadata.updatedAt).toEqual(revisions[0].createdAt);
|
|
||||||
expect(noteDto.metadata.updateUsername).toEqual(user.username);
|
expect(noteDto.metadata.updateUsername).toEqual(user.username);
|
||||||
expect(noteDto.metadata.viewCount).toEqual(note.viewCount);
|
expect(noteDto.metadata.viewCount).toEqual(note.viewCount);
|
||||||
expect(noteDto.content).toEqual(content);
|
expect(noteDto.content).toEqual(content);
|
||||||
|
|
|
@ -405,7 +405,7 @@ export class NotesService {
|
||||||
),
|
),
|
||||||
primaryAddress: (await getPrimaryAlias(note)) ?? note.id,
|
primaryAddress: (await getPrimaryAlias(note)) ?? note.id,
|
||||||
title: note.title ?? '',
|
title: note.title ?? '',
|
||||||
createdAt: (await this.getFirstRevision(note)).createdAt,
|
createdAt: note.createdAt,
|
||||||
description: note.description ?? '',
|
description: note.description ?? '',
|
||||||
editedBy: (await this.getAuthorUsers(note)).map((user) => user.username),
|
editedBy: (await this.getAuthorUsers(note)).map((user) => user.username),
|
||||||
permissions: await this.toNotePermissionsDto(note),
|
permissions: await this.toNotePermissionsDto(note),
|
||||||
|
|
|
@ -315,7 +315,7 @@ describe('Notes', () => {
|
||||||
'test5a',
|
'test5a',
|
||||||
);
|
);
|
||||||
// save the creation time
|
// save the creation time
|
||||||
const createDate = (await note.revisions)[0].createdAt;
|
const createDate = note.createdAt;
|
||||||
// wait one second
|
// wait one second
|
||||||
await new Promise((r) => setTimeout(r, 1000));
|
await new Promise((r) => setTimeout(r, 1000));
|
||||||
// update the note
|
// update the note
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue