mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-16 08:04:45 -04:00
refactor: use integer primary keys
Closes #1292 Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
499f632d8d
commit
2c1e0517ff
17 changed files with 42 additions and 42 deletions
|
@ -131,9 +131,9 @@ export class NotesController {
|
||||||
await this.mediaService.removeNoteFromMediaUpload(mediaUpload);
|
await this.mediaService.removeNoteFromMediaUpload(mediaUpload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.logger.debug('Deleting note: ' + note.id, 'deleteNote');
|
this.logger.debug(`Deleting note: ${note.id}`, 'deleteNote');
|
||||||
await this.noteService.deleteNote(note);
|
await this.noteService.deleteNote(note);
|
||||||
this.logger.debug('Successfully deleted ' + note.id, 'deleteNote');
|
this.logger.debug(`Successfully deleted ${note.id}`, 'deleteNote');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,12 +172,12 @@ export class NotesController {
|
||||||
@RequestNote() note: Note,
|
@RequestNote() note: Note,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
'Purging history of note: ' + note.id,
|
`Purging history of note: ${note.id}`,
|
||||||
'purgeNoteRevisions',
|
'purgeNoteRevisions',
|
||||||
);
|
);
|
||||||
await this.revisionsService.purgeRevisions(note);
|
await this.revisionsService.purgeRevisions(note);
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
'Successfully purged history of note ' + note.id,
|
`Successfully purged history of note ${note.id}`,
|
||||||
'purgeNoteRevisions',
|
'purgeNoteRevisions',
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -141,9 +141,9 @@ export class NotesController {
|
||||||
await this.mediaService.removeNoteFromMediaUpload(mediaUpload);
|
await this.mediaService.removeNoteFromMediaUpload(mediaUpload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.logger.debug('Deleting note: ' + note.id, 'deleteNote');
|
this.logger.debug(`Deleting note: ${note.id}`, 'deleteNote');
|
||||||
await this.noteService.deleteNote(note);
|
await this.noteService.deleteNote(note);
|
||||||
this.logger.debug('Successfully deleted ' + note.id, 'deleteNote');
|
this.logger.debug(`Successfully deleted ${note.id}`, 'deleteNote');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -268,7 +268,7 @@ describe('MediaService', () => {
|
||||||
id: 'testMediaUpload',
|
id: 'testMediaUpload',
|
||||||
backendData: 'testBackendData',
|
backendData: 'testBackendData',
|
||||||
note: Promise.resolve({
|
note: Promise.resolve({
|
||||||
id: '123',
|
id: 123,
|
||||||
} as Note),
|
} as Note),
|
||||||
} as MediaUpload;
|
} as MediaUpload;
|
||||||
const createQueryBuilder = {
|
const createQueryBuilder = {
|
||||||
|
@ -283,7 +283,7 @@ describe('MediaService', () => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
.mockImplementation(() => createQueryBuilder);
|
.mockImplementation(() => createQueryBuilder);
|
||||||
const mediaList = await service.listUploadsByNote({
|
const mediaList = await service.listUploadsByNote({
|
||||||
id: '123',
|
id: 123,
|
||||||
} as Note);
|
} as Note);
|
||||||
expect(mediaList).toEqual([mockMediaUploadEntry]);
|
expect(mediaList).toEqual([mockMediaUploadEntry]);
|
||||||
});
|
});
|
||||||
|
@ -301,7 +301,7 @@ describe('MediaService', () => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
.mockImplementation(() => createQueryBuilder);
|
.mockImplementation(() => createQueryBuilder);
|
||||||
const mediaList = await service.listUploadsByNote({
|
const mediaList = await service.listUploadsByNote({
|
||||||
id: '123',
|
id: 123,
|
||||||
} as Note);
|
} as Note);
|
||||||
expect(mediaList).toEqual([]);
|
expect(mediaList).toEqual([]);
|
||||||
});
|
});
|
||||||
|
@ -318,7 +318,7 @@ describe('MediaService', () => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
.mockImplementation(() => createQueryBuilder);
|
.mockImplementation(() => createQueryBuilder);
|
||||||
const mediaList = await service.listUploadsByNote({
|
const mediaList = await service.listUploadsByNote({
|
||||||
id: '123',
|
id: 123,
|
||||||
} as Note);
|
} as Note);
|
||||||
expect(mediaList).toEqual([]);
|
expect(mediaList).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,8 +17,8 @@ import { PrimaryValueTransformer } from './primary.value-transformer';
|
||||||
@Entity()
|
@Entity()
|
||||||
@Unique('Only one primary alias per note', ['note', 'primary'])
|
@Unique('Only one primary alias per note', ['note', 'primary'])
|
||||||
export class Alias {
|
export class Alias {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn()
|
||||||
id: string;
|
id: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the actual alias
|
* the actual alias
|
||||||
|
|
|
@ -86,8 +86,8 @@ export class AliasService {
|
||||||
*/
|
*/
|
||||||
async makeAliasPrimary(note: Note, alias: string): Promise<Alias> {
|
async makeAliasPrimary(note: Note, alias: string): Promise<Alias> {
|
||||||
let newPrimaryFound = false;
|
let newPrimaryFound = false;
|
||||||
let oldPrimaryId = '';
|
let oldPrimaryId = 0;
|
||||||
let newPrimaryId = '';
|
let newPrimaryId = 0;
|
||||||
|
|
||||||
this.notesService.checkNoteIdOrAlias(alias);
|
this.notesService.checkNoteIdOrAlias(alias);
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,8 @@ import { generatePublicId } from './utils';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Note {
|
export class Note {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn()
|
||||||
id: string;
|
id: number;
|
||||||
|
|
||||||
@Column({ type: 'text' })
|
@Column({ type: 'text' })
|
||||||
publicId: string;
|
publicId: string;
|
||||||
|
|
|
@ -26,7 +26,7 @@ export class NoteGroupPermission {
|
||||||
group: Group;
|
group: Group;
|
||||||
|
|
||||||
@PrimaryColumn()
|
@PrimaryColumn()
|
||||||
noteId: string;
|
noteId: number;
|
||||||
|
|
||||||
@ManyToOne((_) => Note, (note) => note.groupPermissions, {
|
@ManyToOne((_) => Note, (note) => note.groupPermissions, {
|
||||||
onDelete: 'CASCADE', // This deletes the NoteGroupPermission, when the associated Note is deleted
|
onDelete: 'CASCADE', // This deletes the NoteGroupPermission, when the associated Note is deleted
|
||||||
|
|
|
@ -18,7 +18,7 @@ export class NoteUserPermission {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@PrimaryColumn()
|
@PrimaryColumn()
|
||||||
userId: string;
|
userId: number;
|
||||||
|
|
||||||
@ManyToOne((_) => User, {
|
@ManyToOne((_) => User, {
|
||||||
onDelete: 'CASCADE', // This deletes the NoteUserPermission, when the associated Note is deleted
|
onDelete: 'CASCADE', // This deletes the NoteUserPermission, when the associated Note is deleted
|
||||||
|
@ -27,7 +27,7 @@ export class NoteUserPermission {
|
||||||
user: User;
|
user: User;
|
||||||
|
|
||||||
@PrimaryColumn()
|
@PrimaryColumn()
|
||||||
noteId: string;
|
noteId: number;
|
||||||
|
|
||||||
@ManyToOne((_) => Note, (note) => note.userPermissions, {
|
@ManyToOne((_) => Note, (note) => note.userPermissions, {
|
||||||
onDelete: 'CASCADE', // This deletes the NoteUserPermission, when the associated Note is deleted
|
onDelete: 'CASCADE', // This deletes the NoteUserPermission, when the associated Note is deleted
|
||||||
|
|
|
@ -139,9 +139,9 @@ describe('PermissionsService', () => {
|
||||||
|
|
||||||
// The two users we test with:
|
// The two users we test with:
|
||||||
const user2 = {} as User;
|
const user2 = {} as User;
|
||||||
user2.id = '2';
|
user2.id = 2;
|
||||||
const user1 = {} as User;
|
const user1 = {} as User;
|
||||||
user1.id = '1';
|
user1.id = 1;
|
||||||
|
|
||||||
it('should be defined', () => {
|
it('should be defined', () => {
|
||||||
expect(service).toBeDefined();
|
expect(service).toBeDefined();
|
||||||
|
@ -676,9 +676,9 @@ describe('PermissionsService', () => {
|
||||||
const noteWithPreexistingPermissions: Note = { ...note };
|
const noteWithPreexistingPermissions: Note = { ...note };
|
||||||
noteWithPreexistingPermissions.userPermissions = Promise.resolve([
|
noteWithPreexistingPermissions.userPermissions = Promise.resolve([
|
||||||
{
|
{
|
||||||
noteId: '',
|
noteId: 4711,
|
||||||
note: noteWithPreexistingPermissions,
|
note: noteWithPreexistingPermissions,
|
||||||
userId: '',
|
userId: 4711,
|
||||||
user: user,
|
user: user,
|
||||||
canEdit: !userPermissionUpdate.canEdit,
|
canEdit: !userPermissionUpdate.canEdit,
|
||||||
},
|
},
|
||||||
|
@ -750,9 +750,9 @@ describe('PermissionsService', () => {
|
||||||
const noteWithUserPermission: Note = { ...note };
|
const noteWithUserPermission: Note = { ...note };
|
||||||
noteWithUserPermission.userPermissions = Promise.resolve([
|
noteWithUserPermission.userPermissions = Promise.resolve([
|
||||||
{
|
{
|
||||||
noteId: '',
|
noteId: 4711,
|
||||||
note: noteWithUserPermission,
|
note: noteWithUserPermission,
|
||||||
userId: '',
|
userId: 4711,
|
||||||
user: user,
|
user: user,
|
||||||
canEdit: !userPermissionUpdate.canEdit,
|
canEdit: !userPermissionUpdate.canEdit,
|
||||||
},
|
},
|
||||||
|
@ -788,7 +788,7 @@ describe('PermissionsService', () => {
|
||||||
const noteWithPreexistingPermissions: Note = { ...note };
|
const noteWithPreexistingPermissions: Note = { ...note };
|
||||||
noteWithPreexistingPermissions.groupPermissions = Promise.resolve([
|
noteWithPreexistingPermissions.groupPermissions = Promise.resolve([
|
||||||
{
|
{
|
||||||
noteId: '',
|
noteId: 4711,
|
||||||
note: noteWithPreexistingPermissions,
|
note: noteWithPreexistingPermissions,
|
||||||
groupId: 0,
|
groupId: 0,
|
||||||
group: group,
|
group: group,
|
||||||
|
@ -820,7 +820,7 @@ describe('PermissionsService', () => {
|
||||||
const noteWithPreexistingPermissions: Note = { ...note };
|
const noteWithPreexistingPermissions: Note = { ...note };
|
||||||
noteWithPreexistingPermissions.groupPermissions = Promise.resolve([
|
noteWithPreexistingPermissions.groupPermissions = Promise.resolve([
|
||||||
{
|
{
|
||||||
noteId: '',
|
noteId: 4711,
|
||||||
note: noteWithPreexistingPermissions,
|
note: noteWithPreexistingPermissions,
|
||||||
groupId: 0,
|
groupId: 0,
|
||||||
group: group,
|
group: group,
|
||||||
|
@ -858,7 +858,7 @@ describe('PermissionsService', () => {
|
||||||
const noteWithPreexistingPermissions: Note = { ...note };
|
const noteWithPreexistingPermissions: Note = { ...note };
|
||||||
noteWithPreexistingPermissions.groupPermissions = Promise.resolve([
|
noteWithPreexistingPermissions.groupPermissions = Promise.resolve([
|
||||||
{
|
{
|
||||||
noteId: '',
|
noteId: 4711,
|
||||||
note: noteWithPreexistingPermissions,
|
note: noteWithPreexistingPermissions,
|
||||||
groupId: 0,
|
groupId: 0,
|
||||||
group: group,
|
group: group,
|
||||||
|
@ -867,9 +867,9 @@ describe('PermissionsService', () => {
|
||||||
]);
|
]);
|
||||||
noteWithPreexistingPermissions.userPermissions = Promise.resolve([
|
noteWithPreexistingPermissions.userPermissions = Promise.resolve([
|
||||||
{
|
{
|
||||||
noteId: '',
|
noteId: 4711,
|
||||||
note: noteWithPreexistingPermissions,
|
note: noteWithPreexistingPermissions,
|
||||||
userId: '',
|
userId: 4711,
|
||||||
user: user,
|
user: user,
|
||||||
canEdit: !userPermissionUpdate.canEdit,
|
canEdit: !userPermissionUpdate.canEdit,
|
||||||
},
|
},
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { RealtimeNote } from './realtime-note';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RealtimeNoteStore {
|
export class RealtimeNoteStore {
|
||||||
private noteIdToRealtimeNote = new Map<string, RealtimeNote>();
|
private noteIdToRealtimeNote = new Map<number, RealtimeNote>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link RealtimeNote} for the given {@link Note} and memorizes it.
|
* Creates a new {@link RealtimeNote} for the given {@link Note} and memorizes it.
|
||||||
|
@ -37,7 +37,7 @@ export class RealtimeNoteStore {
|
||||||
* @param noteId The id of the {@link Note}
|
* @param noteId The id of the {@link Note}
|
||||||
* @return A {@link RealtimeNote} or {@code undefined} if no instance is existing.
|
* @return A {@link RealtimeNote} or {@code undefined} if no instance is existing.
|
||||||
*/
|
*/
|
||||||
public find(noteId: string): RealtimeNote | undefined {
|
public find(noteId: number): RealtimeNote | undefined {
|
||||||
return this.noteIdToRealtimeNote.get(noteId);
|
return this.noteIdToRealtimeNote.get(noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ describe('RealtimeNoteStore', () => {
|
||||||
let mockedRealtimeNote: RealtimeNote;
|
let mockedRealtimeNote: RealtimeNote;
|
||||||
let realtimeNoteConstructorSpy: jest.SpyInstance;
|
let realtimeNoteConstructorSpy: jest.SpyInstance;
|
||||||
const mockedContent = 'mockedContent';
|
const mockedContent = 'mockedContent';
|
||||||
const mockedNoteId = 'mockedNoteId';
|
const mockedNoteId = 4711;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
|
@ -22,7 +22,7 @@ import { WebsocketDoc } from './websocket-doc';
|
||||||
|
|
||||||
describe('RealtimeNoteService', () => {
|
describe('RealtimeNoteService', () => {
|
||||||
const mockedContent = 'mockedContent';
|
const mockedContent = 'mockedContent';
|
||||||
const mockedNoteId = 'mockedNoteId';
|
const mockedNoteId = 4711;
|
||||||
let websocketDoc: WebsocketDoc;
|
let websocketDoc: WebsocketDoc;
|
||||||
let mockedNote: Note;
|
let mockedNote: Note;
|
||||||
let mockedRealtimeNote: RealtimeNote;
|
let mockedRealtimeNote: RealtimeNote;
|
||||||
|
|
|
@ -32,7 +32,7 @@ describe('realtime note', () => {
|
||||||
.spyOn(websocketAwarenessModule, 'WebsocketAwareness')
|
.spyOn(websocketAwarenessModule, 'WebsocketAwareness')
|
||||||
.mockImplementation(() => mockedAwareness);
|
.mockImplementation(() => mockedAwareness);
|
||||||
|
|
||||||
mockedNote = Mock.of<Note>({ id: 'mock-note' });
|
mockedNote = Mock.of<Note>({ id: 4711 });
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
|
|
|
@ -186,7 +186,7 @@ describe('Websocket gateway', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockedNote = Mock.of<Note>({ id: 'mocknote' });
|
const mockedNote = Mock.of<Note>({ id: 4711 });
|
||||||
jest
|
jest
|
||||||
.spyOn(notesService, 'getNoteByIdOrAlias')
|
.spyOn(notesService, 'getNoteByIdOrAlias')
|
||||||
.mockImplementation((noteId: string) =>
|
.mockImplementation((noteId: string) =>
|
||||||
|
|
|
@ -21,8 +21,8 @@ import { Revision } from './revision.entity';
|
||||||
*/
|
*/
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Edit {
|
export class Edit {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn()
|
||||||
id: string;
|
id: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Revisions this edit appears in
|
* Revisions this edit appears in
|
||||||
|
|
|
@ -116,7 +116,7 @@ describe('RevisionsService', () => {
|
||||||
describe('purgeRevisions', () => {
|
describe('purgeRevisions', () => {
|
||||||
it('purges the revision history', async () => {
|
it('purges the revision history', async () => {
|
||||||
const note = {} as Note;
|
const note = {} as Note;
|
||||||
note.id = 'test';
|
note.id = 4711;
|
||||||
let revisions: Revision[] = [];
|
let revisions: Revision[] = [];
|
||||||
const revision1 = Revision.create('a', 'a', note) as Revision;
|
const revision1 = Revision.create('a', 'a', note) as Revision;
|
||||||
revision1.id = 1;
|
revision1.id = 1;
|
||||||
|
@ -146,7 +146,7 @@ describe('RevisionsService', () => {
|
||||||
});
|
});
|
||||||
it('has no effect on revision history when a single revision is present', async () => {
|
it('has no effect on revision history when a single revision is present', async () => {
|
||||||
const note = {} as Note;
|
const note = {} as Note;
|
||||||
note.id = 'test';
|
note.id = 4711;
|
||||||
let revisions: Revision[] = [];
|
let revisions: Revision[] = [];
|
||||||
const revision1 = Revision.create('a', 'a', note) as Revision;
|
const revision1 = Revision.create('a', 'a', note) as Revision;
|
||||||
revision1.id = 1;
|
revision1.id = 1;
|
||||||
|
|
|
@ -23,8 +23,8 @@ import { Note } from '../notes/note.entity';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class User {
|
export class User {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn()
|
||||||
id: string;
|
id: number;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
unique: true,
|
unique: true,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue