Rename Authorship entity to Edit

As we now have a separate Author entity, which holds information
about an author (the color), the Authorship name became confusing.
Edit seems to be a better name, as the entity saves information
about a change in a note.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-05-31 21:46:41 +02:00
parent 2b0fa17d03
commit 62e0530d2b
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
19 changed files with 67 additions and 73 deletions

View file

@ -26,7 +26,7 @@ export class NoteDto {
metadata: NoteMetadataDto;
/**
* Authorship information of this note
* Edit information of this note
*/
@IsArray()
@ValidateNested({ each: true })

View file

@ -8,7 +8,7 @@ import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { Author } from '../authors/author.entity';
import { LoggerModule } from '../logger/logger.module';
import { Authorship } from '../revisions/authorship.entity';
import { Edit } from '../revisions/edit.entity';
import { Revision } from '../revisions/revision.entity';
import { RevisionsModule } from '../revisions/revisions.module';
import { AuthToken } from '../auth/auth-token.entity';
@ -89,7 +89,7 @@ describe('NotesService', () => {
.useValue({})
.overrideProvider(getRepositoryToken(Identity))
.useValue({})
.overrideProvider(getRepositoryToken(Authorship))
.overrideProvider(getRepositoryToken(Edit))
.useValue({})
.overrideProvider(getRepositoryToken(Revision))
.useClass(Repository)
@ -680,21 +680,21 @@ describe('NotesService', () => {
.mockImplementation(async (note: Note): Promise<Note> => note);
const note = await service.createNote(content);
const revisions = await note.revisions;
revisions[0].authorships = [
revisions[0].edits = [
{
revisions: revisions,
startPos: 0,
endPos: 1,
updatedAt: new Date(1549312452000),
author: author,
} as Authorship,
} as Edit,
{
revisions: revisions,
startPos: 0,
endPos: 1,
updatedAt: new Date(1549312452001),
author: author,
} as Authorship,
} as Edit,
];
revisions[0].createdAt = new Date(1549312452000);
jest.spyOn(revisionRepo, 'findOne').mockResolvedValue(revisions[0]);
@ -776,21 +776,21 @@ describe('NotesService', () => {
.mockImplementation(async (note: Note): Promise<Note> => note);
const note = await service.createNote(content);
const revisions = await note.revisions;
revisions[0].authorships = [
revisions[0].edits = [
{
revisions: revisions,
startPos: 0,
endPos: 1,
updatedAt: new Date(1549312452000),
author: author,
} as Authorship,
} as Edit,
{
revisions: revisions,
startPos: 0,
endPos: 1,
updatedAt: new Date(1549312452001),
author: author,
} as Authorship,
} as Edit,
];
revisions[0].createdAt = new Date(1549312452000);
jest

View file

@ -198,8 +198,8 @@ export class NotesService {
return await this.userRepository
.createQueryBuilder('user')
.innerJoin('user.authors', 'author')
.innerJoin('author.authorships', 'authorship')
.innerJoin('authorship.revisions', 'revision')
.innerJoin('author.edits', 'edit')
.innerJoin('edit.revisions', 'revision')
.innerJoin('revision.note', 'note')
.where('note.id = :id', { id: note.id })
.getMany();
@ -322,14 +322,14 @@ export class NotesService {
*/
async calculateUpdateUser(note: Note): Promise<User | null> {
const lastRevision = await this.getLatestRevision(note);
if (lastRevision && lastRevision.authorships) {
// Sort the last Revisions Authorships by their updatedAt Date to get the latest one
// the user of that Authorship is the updateUser
return lastRevision.authorships.sort(
if (lastRevision && lastRevision.edits) {
// Sort the last Revisions Edits by their updatedAt Date to get the latest one
// the user of that Edit is the updateUser
return lastRevision.edits.sort(
(a, b) => b.updatedAt.getTime() - a.updatedAt.getTime(),
)[0].author.user;
}
// If there are no Authorships, the owner is the updateUser
// If there are no Edits, the owner is the updateUser
return note.owner;
}