From 2c1e0517ff2fc798266ac55dbbb354cdfc983d11 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 18 Sep 2022 20:26:42 +0200 Subject: [PATCH] refactor: use integer primary keys Closes #1292 Signed-off-by: David Mehren --- src/api/private/notes/notes.controller.ts | 8 +++---- src/api/public/notes/notes.controller.ts | 4 ++-- src/media/media.service.spec.ts | 8 +++---- src/notes/alias.entity.ts | 4 ++-- src/notes/alias.service.ts | 4 ++-- src/notes/note.entity.ts | 4 ++-- .../note-group-permission.entity.ts | 2 +- .../note-user-permission.entity.ts | 4 ++-- src/permissions/permissions.service.spec.ts | 22 +++++++++---------- .../realtime-note-store.service.ts | 4 ++-- .../realtime-note/realtime-note-store.spec.ts | 2 +- .../realtime-note.service.spec.ts | 2 +- .../realtime-note/realtime-note.spec.ts | 2 +- .../websocket/websocket.gateway.spec.ts | 2 +- src/revisions/edit.entity.ts | 4 ++-- src/revisions/revisions.service.spec.ts | 4 ++-- src/users/user.entity.ts | 4 ++-- 17 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/api/private/notes/notes.controller.ts b/src/api/private/notes/notes.controller.ts index 9fc023c65..5ec9e45b6 100644 --- a/src/api/private/notes/notes.controller.ts +++ b/src/api/private/notes/notes.controller.ts @@ -131,9 +131,9 @@ export class NotesController { 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); - this.logger.debug('Successfully deleted ' + note.id, 'deleteNote'); + this.logger.debug(`Successfully deleted ${note.id}`, 'deleteNote'); return; } @@ -172,12 +172,12 @@ export class NotesController { @RequestNote() note: Note, ): Promise { this.logger.debug( - 'Purging history of note: ' + note.id, + `Purging history of note: ${note.id}`, 'purgeNoteRevisions', ); await this.revisionsService.purgeRevisions(note); this.logger.debug( - 'Successfully purged history of note ' + note.id, + `Successfully purged history of note ${note.id}`, 'purgeNoteRevisions', ); return; diff --git a/src/api/public/notes/notes.controller.ts b/src/api/public/notes/notes.controller.ts index 47c08cef1..7f388dd38 100644 --- a/src/api/public/notes/notes.controller.ts +++ b/src/api/public/notes/notes.controller.ts @@ -141,9 +141,9 @@ export class NotesController { 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); - this.logger.debug('Successfully deleted ' + note.id, 'deleteNote'); + this.logger.debug(`Successfully deleted ${note.id}`, 'deleteNote'); return; } diff --git a/src/media/media.service.spec.ts b/src/media/media.service.spec.ts index c7e01a4cc..37c4fe0d6 100644 --- a/src/media/media.service.spec.ts +++ b/src/media/media.service.spec.ts @@ -268,7 +268,7 @@ describe('MediaService', () => { id: 'testMediaUpload', backendData: 'testBackendData', note: Promise.resolve({ - id: '123', + id: 123, } as Note), } as MediaUpload; const createQueryBuilder = { @@ -283,7 +283,7 @@ describe('MediaService', () => { // @ts-ignore .mockImplementation(() => createQueryBuilder); const mediaList = await service.listUploadsByNote({ - id: '123', + id: 123, } as Note); expect(mediaList).toEqual([mockMediaUploadEntry]); }); @@ -301,7 +301,7 @@ describe('MediaService', () => { // @ts-ignore .mockImplementation(() => createQueryBuilder); const mediaList = await service.listUploadsByNote({ - id: '123', + id: 123, } as Note); expect(mediaList).toEqual([]); }); @@ -318,7 +318,7 @@ describe('MediaService', () => { // @ts-ignore .mockImplementation(() => createQueryBuilder); const mediaList = await service.listUploadsByNote({ - id: '123', + id: 123, } as Note); expect(mediaList).toEqual([]); }); diff --git a/src/notes/alias.entity.ts b/src/notes/alias.entity.ts index 16d52e5c6..0bbacafd5 100644 --- a/src/notes/alias.entity.ts +++ b/src/notes/alias.entity.ts @@ -17,8 +17,8 @@ import { PrimaryValueTransformer } from './primary.value-transformer'; @Entity() @Unique('Only one primary alias per note', ['note', 'primary']) export class Alias { - @PrimaryGeneratedColumn('uuid') - id: string; + @PrimaryGeneratedColumn() + id: number; /** * the actual alias diff --git a/src/notes/alias.service.ts b/src/notes/alias.service.ts index ccb43a2d0..f3fa588d7 100644 --- a/src/notes/alias.service.ts +++ b/src/notes/alias.service.ts @@ -86,8 +86,8 @@ export class AliasService { */ async makeAliasPrimary(note: Note, alias: string): Promise { let newPrimaryFound = false; - let oldPrimaryId = ''; - let newPrimaryId = ''; + let oldPrimaryId = 0; + let newPrimaryId = 0; this.notesService.checkNoteIdOrAlias(alias); diff --git a/src/notes/note.entity.ts b/src/notes/note.entity.ts index bc12fc265..6f8c79f94 100644 --- a/src/notes/note.entity.ts +++ b/src/notes/note.entity.ts @@ -26,8 +26,8 @@ import { generatePublicId } from './utils'; @Entity() export class Note { - @PrimaryGeneratedColumn('uuid') - id: string; + @PrimaryGeneratedColumn() + id: number; @Column({ type: 'text' }) publicId: string; diff --git a/src/permissions/note-group-permission.entity.ts b/src/permissions/note-group-permission.entity.ts index 275259456..2fec661b6 100644 --- a/src/permissions/note-group-permission.entity.ts +++ b/src/permissions/note-group-permission.entity.ts @@ -26,7 +26,7 @@ export class NoteGroupPermission { group: Group; @PrimaryColumn() - noteId: string; + noteId: number; @ManyToOne((_) => Note, (note) => note.groupPermissions, { onDelete: 'CASCADE', // This deletes the NoteGroupPermission, when the associated Note is deleted diff --git a/src/permissions/note-user-permission.entity.ts b/src/permissions/note-user-permission.entity.ts index accc714ff..deb83ef49 100644 --- a/src/permissions/note-user-permission.entity.ts +++ b/src/permissions/note-user-permission.entity.ts @@ -18,7 +18,7 @@ export class NoteUserPermission { */ @PrimaryColumn() - userId: string; + userId: number; @ManyToOne((_) => User, { onDelete: 'CASCADE', // This deletes the NoteUserPermission, when the associated Note is deleted @@ -27,7 +27,7 @@ export class NoteUserPermission { user: User; @PrimaryColumn() - noteId: string; + noteId: number; @ManyToOne((_) => Note, (note) => note.userPermissions, { onDelete: 'CASCADE', // This deletes the NoteUserPermission, when the associated Note is deleted diff --git a/src/permissions/permissions.service.spec.ts b/src/permissions/permissions.service.spec.ts index 91d60f55b..d510fb60b 100644 --- a/src/permissions/permissions.service.spec.ts +++ b/src/permissions/permissions.service.spec.ts @@ -139,9 +139,9 @@ describe('PermissionsService', () => { // The two users we test with: const user2 = {} as User; - user2.id = '2'; + user2.id = 2; const user1 = {} as User; - user1.id = '1'; + user1.id = 1; it('should be defined', () => { expect(service).toBeDefined(); @@ -676,9 +676,9 @@ describe('PermissionsService', () => { const noteWithPreexistingPermissions: Note = { ...note }; noteWithPreexistingPermissions.userPermissions = Promise.resolve([ { - noteId: '', + noteId: 4711, note: noteWithPreexistingPermissions, - userId: '', + userId: 4711, user: user, canEdit: !userPermissionUpdate.canEdit, }, @@ -750,9 +750,9 @@ describe('PermissionsService', () => { const noteWithUserPermission: Note = { ...note }; noteWithUserPermission.userPermissions = Promise.resolve([ { - noteId: '', + noteId: 4711, note: noteWithUserPermission, - userId: '', + userId: 4711, user: user, canEdit: !userPermissionUpdate.canEdit, }, @@ -788,7 +788,7 @@ describe('PermissionsService', () => { const noteWithPreexistingPermissions: Note = { ...note }; noteWithPreexistingPermissions.groupPermissions = Promise.resolve([ { - noteId: '', + noteId: 4711, note: noteWithPreexistingPermissions, groupId: 0, group: group, @@ -820,7 +820,7 @@ describe('PermissionsService', () => { const noteWithPreexistingPermissions: Note = { ...note }; noteWithPreexistingPermissions.groupPermissions = Promise.resolve([ { - noteId: '', + noteId: 4711, note: noteWithPreexistingPermissions, groupId: 0, group: group, @@ -858,7 +858,7 @@ describe('PermissionsService', () => { const noteWithPreexistingPermissions: Note = { ...note }; noteWithPreexistingPermissions.groupPermissions = Promise.resolve([ { - noteId: '', + noteId: 4711, note: noteWithPreexistingPermissions, groupId: 0, group: group, @@ -867,9 +867,9 @@ describe('PermissionsService', () => { ]); noteWithPreexistingPermissions.userPermissions = Promise.resolve([ { - noteId: '', + noteId: 4711, note: noteWithPreexistingPermissions, - userId: '', + userId: 4711, user: user, canEdit: !userPermissionUpdate.canEdit, }, diff --git a/src/realtime/realtime-note/realtime-note-store.service.ts b/src/realtime/realtime-note/realtime-note-store.service.ts index 2b69b326a..1758c65e2 100644 --- a/src/realtime/realtime-note/realtime-note-store.service.ts +++ b/src/realtime/realtime-note/realtime-note-store.service.ts @@ -10,7 +10,7 @@ import { RealtimeNote } from './realtime-note'; @Injectable() export class RealtimeNoteStore { - private noteIdToRealtimeNote = new Map(); + private noteIdToRealtimeNote = new Map(); /** * 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} * @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); } diff --git a/src/realtime/realtime-note/realtime-note-store.spec.ts b/src/realtime/realtime-note/realtime-note-store.spec.ts index 782817b91..14c969d77 100644 --- a/src/realtime/realtime-note/realtime-note-store.spec.ts +++ b/src/realtime/realtime-note/realtime-note-store.spec.ts @@ -19,7 +19,7 @@ describe('RealtimeNoteStore', () => { let mockedRealtimeNote: RealtimeNote; let realtimeNoteConstructorSpy: jest.SpyInstance; const mockedContent = 'mockedContent'; - const mockedNoteId = 'mockedNoteId'; + const mockedNoteId = 4711; beforeEach(async () => { jest.resetAllMocks(); diff --git a/src/realtime/realtime-note/realtime-note.service.spec.ts b/src/realtime/realtime-note/realtime-note.service.spec.ts index d041e5bdd..231b72d7d 100644 --- a/src/realtime/realtime-note/realtime-note.service.spec.ts +++ b/src/realtime/realtime-note/realtime-note.service.spec.ts @@ -22,7 +22,7 @@ import { WebsocketDoc } from './websocket-doc'; describe('RealtimeNoteService', () => { const mockedContent = 'mockedContent'; - const mockedNoteId = 'mockedNoteId'; + const mockedNoteId = 4711; let websocketDoc: WebsocketDoc; let mockedNote: Note; let mockedRealtimeNote: RealtimeNote; diff --git a/src/realtime/realtime-note/realtime-note.spec.ts b/src/realtime/realtime-note/realtime-note.spec.ts index 4906b12c7..2006eacce 100644 --- a/src/realtime/realtime-note/realtime-note.spec.ts +++ b/src/realtime/realtime-note/realtime-note.spec.ts @@ -32,7 +32,7 @@ describe('realtime note', () => { .spyOn(websocketAwarenessModule, 'WebsocketAwareness') .mockImplementation(() => mockedAwareness); - mockedNote = Mock.of({ id: 'mock-note' }); + mockedNote = Mock.of({ id: 4711 }); }); afterAll(() => { diff --git a/src/realtime/websocket/websocket.gateway.spec.ts b/src/realtime/websocket/websocket.gateway.spec.ts index 180b12ad0..394112c6b 100644 --- a/src/realtime/websocket/websocket.gateway.spec.ts +++ b/src/realtime/websocket/websocket.gateway.spec.ts @@ -186,7 +186,7 @@ describe('Websocket gateway', () => { } }); - const mockedNote = Mock.of({ id: 'mocknote' }); + const mockedNote = Mock.of({ id: 4711 }); jest .spyOn(notesService, 'getNoteByIdOrAlias') .mockImplementation((noteId: string) => diff --git a/src/revisions/edit.entity.ts b/src/revisions/edit.entity.ts index 349e6d54f..bcb64d014 100644 --- a/src/revisions/edit.entity.ts +++ b/src/revisions/edit.entity.ts @@ -21,8 +21,8 @@ import { Revision } from './revision.entity'; */ @Entity() export class Edit { - @PrimaryGeneratedColumn('uuid') - id: string; + @PrimaryGeneratedColumn() + id: number; /** * Revisions this edit appears in diff --git a/src/revisions/revisions.service.spec.ts b/src/revisions/revisions.service.spec.ts index 0a1f24b45..a9e72312b 100644 --- a/src/revisions/revisions.service.spec.ts +++ b/src/revisions/revisions.service.spec.ts @@ -116,7 +116,7 @@ describe('RevisionsService', () => { describe('purgeRevisions', () => { it('purges the revision history', async () => { const note = {} as Note; - note.id = 'test'; + note.id = 4711; let revisions: Revision[] = []; const revision1 = Revision.create('a', 'a', note) as Revision; revision1.id = 1; @@ -146,7 +146,7 @@ describe('RevisionsService', () => { }); it('has no effect on revision history when a single revision is present', async () => { const note = {} as Note; - note.id = 'test'; + note.id = 4711; let revisions: Revision[] = []; const revision1 = Revision.create('a', 'a', note) as Revision; revision1.id = 1; diff --git a/src/users/user.entity.ts b/src/users/user.entity.ts index 4500ce2c8..601dac0c7 100644 --- a/src/users/user.entity.ts +++ b/src/users/user.entity.ts @@ -23,8 +23,8 @@ import { Note } from '../notes/note.entity'; @Entity() export class User { - @PrimaryGeneratedColumn('uuid') - id: string; + @PrimaryGeneratedColumn() + id: number; @Column({ unique: true,