Add /me/notes route to MeController

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2020-07-26 17:29:20 +02:00
parent b05022945c
commit 02de7c7d54
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
3 changed files with 15 additions and 2 deletions

View file

@ -1,6 +1,8 @@
import { Test, TestingModule } from '@nestjs/testing'; import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm'; import { getRepositoryToken } from '@nestjs/typeorm';
import { HistoryModule } from '../../../history/history.module'; import { HistoryModule } from '../../../history/history.module';
import { Note } from '../../../notes/note.entity';
import { NotesModule } from '../../../notes/notes.module';
import { User } from '../../../users/user.entity'; import { User } from '../../../users/user.entity';
import { UsersModule } from '../../../users/users.module'; import { UsersModule } from '../../../users/users.module';
import { MeController } from './me.controller'; import { MeController } from './me.controller';
@ -11,10 +13,12 @@ describe('Me Controller', () => {
beforeEach(async () => { beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({ const module: TestingModule = await Test.createTestingModule({
controllers: [MeController], controllers: [MeController],
imports: [UsersModule, HistoryModule], imports: [UsersModule, HistoryModule, NotesModule],
}) })
.overrideProvider(getRepositoryToken(User)) .overrideProvider(getRepositoryToken(User))
.useValue({}) .useValue({})
.overrideProvider(getRepositoryToken(Note))
.useValue({})
.compile(); .compile();
controller = module.get<MeController>(MeController); controller = module.get<MeController>(MeController);

View file

@ -12,6 +12,8 @@ import {
import { HistoryEntryUpdateDto } from '../../../history/history-entry-update.dto'; import { HistoryEntryUpdateDto } from '../../../history/history-entry-update.dto';
import { HistoryEntryDto } from '../../../history/history-entry.dto'; import { HistoryEntryDto } from '../../../history/history-entry.dto';
import { HistoryService } from '../../../history/history.service'; import { HistoryService } from '../../../history/history.service';
import { NoteMetadataDto } from '../../../notes/note-metadata.dto';
import { NotesService } from '../../../notes/notes.service';
import { UserInfoDto } from '../../../users/user-info.dto'; import { UserInfoDto } from '../../../users/user-info.dto';
import { UsersService } from '../../../users/users.service'; import { UsersService } from '../../../users/users.service';
@ -22,6 +24,7 @@ export class MeController {
constructor( constructor(
private usersService: UsersService, private usersService: UsersService,
private historyService: HistoryService, private historyService: HistoryService,
private notesService: NotesService,
) {} ) {}
@Get() @Get()
@ -51,4 +54,9 @@ export class MeController {
throw new NotFoundException(e.message); throw new NotFoundException(e.message);
} }
} }
@Get('notes')
getMyNotes(): NoteMetadataDto[] {
return this.notesService.getUserNotes('someone');
}
} }

View file

@ -1,5 +1,6 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { HistoryModule } from '../../history/history.module'; import { HistoryModule } from '../../history/history.module';
import { NotesModule } from '../../notes/notes.module';
import { UsersModule } from '../../users/users.module'; import { UsersModule } from '../../users/users.module';
import { MeController } from './me/me.controller'; import { MeController } from './me/me.controller';
import { NotesController } from './notes/notes.controller'; import { NotesController } from './notes/notes.controller';
@ -7,7 +8,7 @@ import { MediaController } from './media/media.controller';
import { MonitoringController } from './monitoring/monitoring.controller'; import { MonitoringController } from './monitoring/monitoring.controller';
@Module({ @Module({
imports: [UsersModule, HistoryModule], imports: [UsersModule, HistoryModule, NotesModule],
controllers: [ controllers: [
MeController, MeController,
NotesController, NotesController,