mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-30 11:00:01 -05:00
AuthorshipEntity: Adjust to DB schema
This commit replaces the user property with a author property,
in accordance with the DB schema updated in 0d6c3002
.
It also adjusts the NoteService accordingly.
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
27c2bfb36f
commit
20006df82f
3 changed files with 25 additions and 11 deletions
|
@ -655,7 +655,8 @@ describe('NotesService', () => {
|
||||||
describe('toNoteMetadataDto', () => {
|
describe('toNoteMetadataDto', () => {
|
||||||
it('works', async () => {
|
it('works', async () => {
|
||||||
const user = User.create('hardcoded', 'Testy') as User;
|
const user = User.create('hardcoded', 'Testy') as User;
|
||||||
const otherUser = User.create('other hardcoded', 'Testy2') as User;
|
const author = Author.create(1);
|
||||||
|
author.user = user;
|
||||||
const group = Group.create('testGroup', 'testGroup');
|
const group = Group.create('testGroup', 'testGroup');
|
||||||
const content = 'testContent';
|
const content = 'testContent';
|
||||||
jest
|
jest
|
||||||
|
@ -665,18 +666,18 @@ describe('NotesService', () => {
|
||||||
const revisions = await note.revisions;
|
const revisions = await note.revisions;
|
||||||
revisions[0].authorships = [
|
revisions[0].authorships = [
|
||||||
{
|
{
|
||||||
user: otherUser,
|
|
||||||
revisions: revisions,
|
revisions: revisions,
|
||||||
startPos: 0,
|
startPos: 0,
|
||||||
endPos: 1,
|
endPos: 1,
|
||||||
updatedAt: new Date(1549312452000),
|
updatedAt: new Date(1549312452000),
|
||||||
|
author: author,
|
||||||
} as Authorship,
|
} as Authorship,
|
||||||
{
|
{
|
||||||
user: user,
|
|
||||||
revisions: revisions,
|
revisions: revisions,
|
||||||
startPos: 0,
|
startPos: 0,
|
||||||
endPos: 1,
|
endPos: 1,
|
||||||
updatedAt: new Date(1549312452001),
|
updatedAt: new Date(1549312452001),
|
||||||
|
author: author,
|
||||||
} as Authorship,
|
} as Authorship,
|
||||||
];
|
];
|
||||||
revisions[0].createdAt = new Date(1549312452000);
|
revisions[0].createdAt = new Date(1549312452000);
|
||||||
|
@ -738,6 +739,8 @@ describe('NotesService', () => {
|
||||||
describe('toNoteDto', () => {
|
describe('toNoteDto', () => {
|
||||||
it('works', async () => {
|
it('works', async () => {
|
||||||
const user = User.create('hardcoded', 'Testy') as User;
|
const user = User.create('hardcoded', 'Testy') as User;
|
||||||
|
const author = Author.create(1);
|
||||||
|
author.user = user;
|
||||||
const otherUser = User.create('other hardcoded', 'Testy2') as User;
|
const otherUser = User.create('other hardcoded', 'Testy2') as User;
|
||||||
otherUser.userName = 'other hardcoded user';
|
otherUser.userName = 'other hardcoded user';
|
||||||
const group = Group.create('testGroup', 'testGroup');
|
const group = Group.create('testGroup', 'testGroup');
|
||||||
|
@ -749,18 +752,18 @@ describe('NotesService', () => {
|
||||||
const revisions = await note.revisions;
|
const revisions = await note.revisions;
|
||||||
revisions[0].authorships = [
|
revisions[0].authorships = [
|
||||||
{
|
{
|
||||||
user: otherUser,
|
|
||||||
revisions: revisions,
|
revisions: revisions,
|
||||||
startPos: 0,
|
startPos: 0,
|
||||||
endPos: 1,
|
endPos: 1,
|
||||||
updatedAt: new Date(1549312452000),
|
updatedAt: new Date(1549312452000),
|
||||||
|
author: author,
|
||||||
} as Authorship,
|
} as Authorship,
|
||||||
{
|
{
|
||||||
user: user,
|
|
||||||
revisions: revisions,
|
revisions: revisions,
|
||||||
startPos: 0,
|
startPos: 0,
|
||||||
endPos: 1,
|
endPos: 1,
|
||||||
updatedAt: new Date(1549312452001),
|
updatedAt: new Date(1549312452001),
|
||||||
|
author: author,
|
||||||
} as Authorship,
|
} as Authorship,
|
||||||
];
|
];
|
||||||
revisions[0].createdAt = new Date(1549312452000);
|
revisions[0].createdAt = new Date(1549312452000);
|
||||||
|
|
|
@ -310,7 +310,7 @@ export class NotesService {
|
||||||
// the user of that Authorship is the updateUser
|
// the user of that Authorship is the updateUser
|
||||||
return lastRevision.authorships.sort(
|
return lastRevision.authorships.sort(
|
||||||
(a, b) => b.updatedAt.getTime() - a.updatedAt.getTime(),
|
(a, b) => b.updatedAt.getTime() - a.updatedAt.getTime(),
|
||||||
)[0].user;
|
)[0].author.user;
|
||||||
}
|
}
|
||||||
// If there are no Authorships, the owner is the updateUser
|
// If there are no Authorships, the owner is the updateUser
|
||||||
return note.owner;
|
return note.owner;
|
||||||
|
|
|
@ -13,11 +13,11 @@ import {
|
||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn,
|
||||||
UpdateDateColumn,
|
UpdateDateColumn,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
import { User } from '../users/user.entity';
|
import { Author } from '../authors/author.entity';
|
||||||
import { Revision } from './revision.entity';
|
import { Revision } from './revision.entity';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class stores which parts of a revision were edited by a particular user.
|
* The Authorship represents a change in the content of a note by a particular {@link Author}
|
||||||
*/
|
*/
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Authorship {
|
export class Authorship {
|
||||||
|
@ -31,10 +31,10 @@ export class Authorship {
|
||||||
revisions: Revision[];
|
revisions: Revision[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User this authorship represents
|
* Author that created the change
|
||||||
*/
|
*/
|
||||||
@ManyToOne((_) => User)
|
@ManyToOne(() => Author, (author) => author.authorships)
|
||||||
user: User;
|
author: Author;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
startPos: number;
|
startPos: number;
|
||||||
|
@ -47,4 +47,15 @@ export class Authorship {
|
||||||
|
|
||||||
@UpdateDateColumn()
|
@UpdateDateColumn()
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
|
private constructor() {}
|
||||||
|
|
||||||
|
public static create(author: Author, startPos: number, endPos: number) {
|
||||||
|
const newAuthorship = new Authorship();
|
||||||
|
newAuthorship.author = author;
|
||||||
|
newAuthorship.startPos = startPos;
|
||||||
|
newAuthorship.endPos = endPos;
|
||||||
|
return newAuthorship;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue