refactor: use integer primary keys

Closes #1292

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2022-09-18 20:26:42 +02:00 committed by Yannick Bungers
parent 499f632d8d
commit 2c1e0517ff
17 changed files with 42 additions and 42 deletions

View file

@ -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<void> {
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;

View file

@ -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;
}

View file

@ -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([]);
});

View file

@ -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

View file

@ -86,8 +86,8 @@ export class AliasService {
*/
async makeAliasPrimary(note: Note, alias: string): Promise<Alias> {
let newPrimaryFound = false;
let oldPrimaryId = '';
let newPrimaryId = '';
let oldPrimaryId = 0;
let newPrimaryId = 0;
this.notesService.checkNoteIdOrAlias(alias);

View file

@ -26,8 +26,8 @@ import { generatePublicId } from './utils';
@Entity()
export class Note {
@PrimaryGeneratedColumn('uuid')
id: string;
@PrimaryGeneratedColumn()
id: number;
@Column({ type: 'text' })
publicId: string;

View file

@ -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

View file

@ -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

View file

@ -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,
},

View file

@ -10,7 +10,7 @@ import { RealtimeNote } from './realtime-note';
@Injectable()
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.
@ -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);
}

View file

@ -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();

View file

@ -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;

View file

@ -32,7 +32,7 @@ describe('realtime note', () => {
.spyOn(websocketAwarenessModule, 'WebsocketAwareness')
.mockImplementation(() => mockedAwareness);
mockedNote = Mock.of<Note>({ id: 'mock-note' });
mockedNote = Mock.of<Note>({ id: 4711 });
});
afterAll(() => {

View file

@ -186,7 +186,7 @@ describe('Websocket gateway', () => {
}
});
const mockedNote = Mock.of<Note>({ id: 'mocknote' });
const mockedNote = Mock.of<Note>({ id: 4711 });
jest
.spyOn(notesService, 'getNoteByIdOrAlias')
.mockImplementation((noteId: string) =>

View file

@ -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

View file

@ -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;

View file

@ -23,8 +23,8 @@ import { Note } from '../notes/note.entity';
@Entity()
export class User {
@PrimaryGeneratedColumn('uuid')
id: string;
@PrimaryGeneratedColumn()
id: number;
@Column({
unique: true,