mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-29 08:14:31 -05:00
Switch to using the new custom logger
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
b256fc8b36
commit
e37722a56a
24 changed files with 83 additions and 34 deletions
|
@ -1,6 +1,7 @@
|
||||||
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 { LoggerModule } from '../../../logger/logger.module';
|
||||||
import { AuthorColor } from '../../../notes/author-color.entity';
|
import { AuthorColor } from '../../../notes/author-color.entity';
|
||||||
import { Note } from '../../../notes/note.entity';
|
import { Note } from '../../../notes/note.entity';
|
||||||
import { NotesModule } from '../../../notes/notes.module';
|
import { NotesModule } from '../../../notes/notes.module';
|
||||||
|
@ -18,7 +19,7 @@ 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, NotesModule],
|
imports: [UsersModule, HistoryModule, NotesModule, LoggerModule],
|
||||||
})
|
})
|
||||||
.overrideProvider(getRepositoryToken(User))
|
.overrideProvider(getRepositoryToken(User))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
|
|
@ -4,7 +4,6 @@ import {
|
||||||
Delete,
|
Delete,
|
||||||
Get,
|
Get,
|
||||||
HttpCode,
|
HttpCode,
|
||||||
Logger,
|
|
||||||
NotFoundException,
|
NotFoundException,
|
||||||
Param,
|
Param,
|
||||||
Put,
|
Put,
|
||||||
|
@ -12,6 +11,7 @@ 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 { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||||
import { NoteMetadataDto } from '../../../notes/note-metadata.dto';
|
import { NoteMetadataDto } from '../../../notes/note-metadata.dto';
|
||||||
import { NotesService } from '../../../notes/notes.service';
|
import { NotesService } from '../../../notes/notes.service';
|
||||||
import { UserInfoDto } from '../../../users/user-info.dto';
|
import { UserInfoDto } from '../../../users/user-info.dto';
|
||||||
|
@ -19,13 +19,14 @@ import { UsersService } from '../../../users/users.service';
|
||||||
|
|
||||||
@Controller('me')
|
@Controller('me')
|
||||||
export class MeController {
|
export class MeController {
|
||||||
private readonly logger = new Logger(MeController.name);
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
private readonly logger: ConsoleLoggerService,
|
||||||
private usersService: UsersService,
|
private usersService: UsersService,
|
||||||
private historyService: HistoryService,
|
private historyService: HistoryService,
|
||||||
private notesService: NotesService,
|
private notesService: NotesService,
|
||||||
) {}
|
) {
|
||||||
|
this.logger.setContext(MeController.name);
|
||||||
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
getMe(): UserInfoDto {
|
getMe(): UserInfoDto {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { LoggerModule } from '../../../logger/logger.module';
|
||||||
import { MediaController } from './media.controller';
|
import { MediaController } from './media.controller';
|
||||||
|
|
||||||
describe('Media Controller', () => {
|
describe('Media Controller', () => {
|
||||||
|
@ -7,6 +8,7 @@ describe('Media Controller', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
controllers: [MediaController],
|
controllers: [MediaController],
|
||||||
|
imports: [LoggerModule],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
controller = module.get<MediaController>(MediaController);
|
controller = module.get<MediaController>(MediaController);
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
import {
|
import {
|
||||||
Controller,
|
Controller,
|
||||||
Logger,
|
|
||||||
Post,
|
Post,
|
||||||
UploadedFile,
|
UploadedFile,
|
||||||
UseInterceptors,
|
UseInterceptors,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { FileInterceptor } from '@nestjs/platform-express';
|
import { FileInterceptor } from '@nestjs/platform-express';
|
||||||
|
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||||
|
|
||||||
@Controller('media')
|
@Controller('media')
|
||||||
export class MediaController {
|
export class MediaController {
|
||||||
private readonly logger = new Logger(MediaController.name);
|
constructor(private readonly logger: ConsoleLoggerService) {
|
||||||
|
this.logger.setContext(MediaController.name);
|
||||||
|
}
|
||||||
|
|
||||||
@Post('upload')
|
@Post('upload')
|
||||||
@UseInterceptors(FileInterceptor('file'))
|
@UseInterceptors(FileInterceptor('file'))
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||||
|
import { LoggerModule } from '../../../logger/logger.module';
|
||||||
import { AuthorColor } from '../../../notes/author-color.entity';
|
import { AuthorColor } from '../../../notes/author-color.entity';
|
||||||
import { Note } from '../../../notes/note.entity';
|
import { Note } from '../../../notes/note.entity';
|
||||||
import { NotesService } from '../../../notes/notes.service';
|
import { NotesService } from '../../../notes/notes.service';
|
||||||
|
@ -25,7 +26,7 @@ describe('Notes Controller', () => {
|
||||||
useValue: {},
|
useValue: {},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
imports: [RevisionsModule, UsersModule],
|
imports: [RevisionsModule, UsersModule, LoggerModule],
|
||||||
})
|
})
|
||||||
.overrideProvider(getRepositoryToken(Note))
|
.overrideProvider(getRepositoryToken(Note))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
|
|
@ -5,7 +5,6 @@ import {
|
||||||
Delete,
|
Delete,
|
||||||
Get,
|
Get,
|
||||||
Header,
|
Header,
|
||||||
Logger,
|
|
||||||
Param,
|
Param,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
|
@ -13,18 +12,20 @@ import {
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { Request } from 'express';
|
import { Request } from 'express';
|
||||||
import * as getRawBody from 'raw-body';
|
import * as getRawBody from 'raw-body';
|
||||||
|
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||||
import { NotePermissionsUpdateDto } from '../../../notes/note-permissions.dto';
|
import { NotePermissionsUpdateDto } from '../../../notes/note-permissions.dto';
|
||||||
import { NotesService } from '../../../notes/notes.service';
|
import { NotesService } from '../../../notes/notes.service';
|
||||||
import { RevisionsService } from '../../../revisions/revisions.service';
|
import { RevisionsService } from '../../../revisions/revisions.service';
|
||||||
|
|
||||||
@Controller('notes')
|
@Controller('notes')
|
||||||
export class NotesController {
|
export class NotesController {
|
||||||
private readonly logger = new Logger(NotesController.name);
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
private readonly logger: ConsoleLoggerService,
|
||||||
private noteService: NotesService,
|
private noteService: NotesService,
|
||||||
private revisionsService: RevisionsService,
|
private revisionsService: RevisionsService,
|
||||||
) {}
|
) {
|
||||||
|
this.logger.setContext(NotesController.name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract the raw markdown from the request body and create a new note with it
|
* Extract the raw markdown from the request body and create a new note with it
|
||||||
|
|
|
@ -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 { LoggerModule } from '../../logger/logger.module';
|
||||||
import { MonitoringModule } from '../../monitoring/monitoring.module';
|
import { MonitoringModule } from '../../monitoring/monitoring.module';
|
||||||
import { NotesModule } from '../../notes/notes.module';
|
import { NotesModule } from '../../notes/notes.module';
|
||||||
import { RevisionsModule } from '../../revisions/revisions.module';
|
import { RevisionsModule } from '../../revisions/revisions.module';
|
||||||
|
@ -16,6 +17,7 @@ import { MonitoringController } from './monitoring/monitoring.controller';
|
||||||
NotesModule,
|
NotesModule,
|
||||||
RevisionsModule,
|
RevisionsModule,
|
||||||
MonitoringModule,
|
MonitoringModule,
|
||||||
|
LoggerModule,
|
||||||
],
|
],
|
||||||
controllers: [
|
controllers: [
|
||||||
MeController,
|
MeController,
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { PublicApiModule } from './api/public/public-api.module';
|
import { PublicApiModule } from './api/public/public-api.module';
|
||||||
import { NotesModule } from './notes/notes.module';
|
|
||||||
import { UsersModule } from './users/users.module';
|
|
||||||
import { RevisionsModule } from './revisions/revisions.module';
|
|
||||||
import { AuthorsModule } from './authors/authors.module';
|
import { AuthorsModule } from './authors/authors.module';
|
||||||
import { HistoryModule } from './history/history.module';
|
|
||||||
import { MonitoringModule } from './monitoring/monitoring.module';
|
|
||||||
import { PermissionsModule } from './permissions/permissions.module';
|
|
||||||
import { GroupsModule } from './groups/groups.module';
|
import { GroupsModule } from './groups/groups.module';
|
||||||
|
import { HistoryModule } from './history/history.module';
|
||||||
|
import { LoggerModule } from './logger/logger.module';
|
||||||
|
import { MonitoringModule } from './monitoring/monitoring.module';
|
||||||
|
import { NotesModule } from './notes/notes.module';
|
||||||
|
import { PermissionsModule } from './permissions/permissions.module';
|
||||||
|
import { RevisionsModule } from './revisions/revisions.module';
|
||||||
|
import { UsersModule } from './users/users.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -27,6 +28,7 @@ import { GroupsModule } from './groups/groups.module';
|
||||||
MonitoringModule,
|
MonitoringModule,
|
||||||
PermissionsModule,
|
PermissionsModule,
|
||||||
GroupsModule,
|
GroupsModule,
|
||||||
|
LoggerModule,
|
||||||
],
|
],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
providers: [],
|
providers: [],
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
|
import { LoggerModule } from '../logger/logger.module';
|
||||||
import { HistoryService } from './history.service';
|
import { HistoryService } from './history.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [HistoryService],
|
providers: [HistoryService],
|
||||||
exports: [HistoryService],
|
exports: [HistoryService],
|
||||||
|
imports: [LoggerModule],
|
||||||
})
|
})
|
||||||
export class HistoryModule {}
|
export class HistoryModule {}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { LoggerModule } from '../logger/logger.module';
|
||||||
import { HistoryService } from './history.service';
|
import { HistoryService } from './history.service';
|
||||||
|
|
||||||
describe('HistoryService', () => {
|
describe('HistoryService', () => {
|
||||||
|
@ -7,6 +8,7 @@ describe('HistoryService', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
providers: [HistoryService],
|
providers: [HistoryService],
|
||||||
|
imports: [LoggerModule],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
service = module.get<HistoryService>(HistoryService);
|
service = module.get<HistoryService>(HistoryService);
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { ConsoleLoggerService } from '../logger/console-logger.service';
|
||||||
import { HistoryEntryUpdateDto } from './history-entry-update.dto';
|
import { HistoryEntryUpdateDto } from './history-entry-update.dto';
|
||||||
import { HistoryEntryDto } from './history-entry.dto';
|
import { HistoryEntryDto } from './history-entry.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class HistoryService {
|
export class HistoryService {
|
||||||
private readonly logger = new Logger(HistoryService.name);
|
constructor(private readonly logger: ConsoleLoggerService) {
|
||||||
|
this.logger.setContext(HistoryService.name);
|
||||||
|
}
|
||||||
|
|
||||||
getUserHistory(username: string): HistoryEntryDto[] {
|
getUserHistory(username: string): HistoryEntryDto[] {
|
||||||
//TODO: Use the database
|
//TODO: Use the database
|
||||||
|
|
|
@ -2,9 +2,13 @@ import { ValidationPipe } from '@nestjs/common';
|
||||||
import { NestFactory } from '@nestjs/core';
|
import { NestFactory } from '@nestjs/core';
|
||||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
|
import { NestConsoleLoggerService } from './logger/nest-console-logger.service';
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
|
const logger = await app.resolve(NestConsoleLoggerService);
|
||||||
|
logger.log('Switching logger', 'AppBootstrap');
|
||||||
|
app.useLogger(logger);
|
||||||
|
|
||||||
const swaggerOptions = new DocumentBuilder()
|
const swaggerOptions = new DocumentBuilder()
|
||||||
.setTitle('HedgeDoc')
|
.setTitle('HedgeDoc')
|
||||||
|
@ -21,6 +25,7 @@ async function bootstrap() {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
await app.listen(3000);
|
await app.listen(3000);
|
||||||
|
logger.log('Listening on port 3000', 'AppBootstrap');
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
|
import { LoggerModule } from '../logger/logger.module';
|
||||||
import { MonitoringService } from './monitoring.service';
|
import { MonitoringService } from './monitoring.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [MonitoringService],
|
providers: [MonitoringService],
|
||||||
exports: [MonitoringService],
|
exports: [MonitoringService],
|
||||||
|
imports: [LoggerModule],
|
||||||
})
|
})
|
||||||
export class MonitoringModule {}
|
export class MonitoringModule {}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { forwardRef, Module } from '@nestjs/common';
|
import { forwardRef, Module } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { LoggerModule } from '../logger/logger.module';
|
||||||
import { RevisionsModule } from '../revisions/revisions.module';
|
import { RevisionsModule } from '../revisions/revisions.module';
|
||||||
import { UsersModule } from '../users/users.module';
|
import { UsersModule } from '../users/users.module';
|
||||||
import { AuthorColor } from './author-color.entity';
|
import { AuthorColor } from './author-color.entity';
|
||||||
|
@ -11,6 +12,7 @@ import { NotesService } from './notes.service';
|
||||||
TypeOrmModule.forFeature([Note, AuthorColor]),
|
TypeOrmModule.forFeature([Note, AuthorColor]),
|
||||||
forwardRef(() => RevisionsModule),
|
forwardRef(() => RevisionsModule),
|
||||||
UsersModule,
|
UsersModule,
|
||||||
|
LoggerModule,
|
||||||
],
|
],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
providers: [NotesService],
|
providers: [NotesService],
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||||
|
import { LoggerModule } from '../logger/logger.module';
|
||||||
import { Authorship } from '../revisions/authorship.entity';
|
import { Authorship } from '../revisions/authorship.entity';
|
||||||
import { Revision } from '../revisions/revision.entity';
|
import { Revision } from '../revisions/revision.entity';
|
||||||
import { RevisionsModule } from '../revisions/revisions.module';
|
import { RevisionsModule } from '../revisions/revisions.module';
|
||||||
|
@ -23,7 +24,7 @@ describe('NotesService', () => {
|
||||||
useValue: {},
|
useValue: {},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
imports: [UsersModule, RevisionsModule],
|
imports: [UsersModule, RevisionsModule, LoggerModule],
|
||||||
})
|
})
|
||||||
.overrideProvider(getRepositoryToken(User))
|
.overrideProvider(getRepositoryToken(User))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common';
|
import { forwardRef, Inject, Injectable } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
import { ConsoleLoggerService } from '../logger/console-logger.service';
|
||||||
import { Revision } from '../revisions/revision.entity';
|
import { Revision } from '../revisions/revision.entity';
|
||||||
import { RevisionsService } from '../revisions/revisions.service';
|
import { RevisionsService } from '../revisions/revisions.service';
|
||||||
import { User } from '../users/user.entity';
|
import { User } from '../users/user.entity';
|
||||||
|
@ -16,14 +17,15 @@ import { NoteUtils } from './note.utils';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class NotesService {
|
export class NotesService {
|
||||||
private readonly logger = new Logger(NotesService.name);
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
private readonly logger: ConsoleLoggerService,
|
||||||
@InjectRepository(Note) private noteRepository: Repository<Note>,
|
@InjectRepository(Note) private noteRepository: Repository<Note>,
|
||||||
@Inject(UsersService) private usersService: UsersService,
|
@Inject(UsersService) private usersService: UsersService,
|
||||||
@Inject(forwardRef(() => RevisionsService))
|
@Inject(forwardRef(() => RevisionsService))
|
||||||
private revisionsService: RevisionsService,
|
private revisionsService: RevisionsService,
|
||||||
) {}
|
) {
|
||||||
|
this.logger.setContext(NotesService.name);
|
||||||
|
}
|
||||||
|
|
||||||
getUserNotes(username: string): NoteMetadataDto[] {
|
getUserNotes(username: string): NoteMetadataDto[] {
|
||||||
this.logger.warn('Using hardcoded data!');
|
this.logger.warn('Using hardcoded data!');
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { LoggerModule } from '../logger/logger.module';
|
||||||
import { NoteGroupPermission } from './note-group-permission.entity';
|
import { NoteGroupPermission } from './note-group-permission.entity';
|
||||||
import { NoteUserPermission } from './note-user-permission.entity';
|
import { NoteUserPermission } from './note-user-permission.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forFeature([NoteUserPermission, NoteGroupPermission]),
|
TypeOrmModule.forFeature([NoteUserPermission, NoteGroupPermission]),
|
||||||
|
LoggerModule,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class PermissionsModule {}
|
export class PermissionsModule {}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { forwardRef, Module } from '@nestjs/common';
|
import { forwardRef, Module } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { LoggerModule } from '../logger/logger.module';
|
||||||
import { NotesModule } from '../notes/notes.module';
|
import { NotesModule } from '../notes/notes.module';
|
||||||
import { Authorship } from './authorship.entity';
|
import { Authorship } from './authorship.entity';
|
||||||
import { Revision } from './revision.entity';
|
import { Revision } from './revision.entity';
|
||||||
|
@ -9,6 +10,7 @@ import { RevisionsService } from './revisions.service';
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forFeature([Revision, Authorship]),
|
TypeOrmModule.forFeature([Revision, Authorship]),
|
||||||
forwardRef(() => NotesModule),
|
forwardRef(() => NotesModule),
|
||||||
|
LoggerModule,
|
||||||
],
|
],
|
||||||
providers: [RevisionsService],
|
providers: [RevisionsService],
|
||||||
exports: [RevisionsService],
|
exports: [RevisionsService],
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||||
|
import { LoggerModule } from '../logger/logger.module';
|
||||||
import { AuthorColor } from '../notes/author-color.entity';
|
import { AuthorColor } from '../notes/author-color.entity';
|
||||||
import { Note } from '../notes/note.entity';
|
import { Note } from '../notes/note.entity';
|
||||||
import { NotesModule } from '../notes/notes.module';
|
import { NotesModule } from '../notes/notes.module';
|
||||||
|
@ -22,7 +23,7 @@ describe('RevisionsService', () => {
|
||||||
useValue: {},
|
useValue: {},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
imports: [NotesModule],
|
imports: [NotesModule, LoggerModule],
|
||||||
})
|
})
|
||||||
.overrideProvider(getRepositoryToken(Authorship))
|
.overrideProvider(getRepositoryToken(Authorship))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common';
|
import { forwardRef, Inject, Injectable } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
import { ConsoleLoggerService } from '../logger/console-logger.service';
|
||||||
import { NotesService } from '../notes/notes.service';
|
import { NotesService } from '../notes/notes.service';
|
||||||
import { RevisionMetadataDto } from './revision-metadata.dto';
|
import { RevisionMetadataDto } from './revision-metadata.dto';
|
||||||
import { RevisionDto } from './revision.dto';
|
import { RevisionDto } from './revision.dto';
|
||||||
|
@ -8,13 +9,14 @@ import { Revision } from './revision.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RevisionsService {
|
export class RevisionsService {
|
||||||
private readonly logger = new Logger(RevisionsService.name);
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
private readonly logger: ConsoleLoggerService,
|
||||||
@InjectRepository(Revision)
|
@InjectRepository(Revision)
|
||||||
private revisionRepository: Repository<Revision>,
|
private revisionRepository: Repository<Revision>,
|
||||||
@Inject(forwardRef(() => NotesService)) private notesService: NotesService,
|
@Inject(forwardRef(() => NotesService)) private notesService: NotesService,
|
||||||
) {}
|
) {
|
||||||
|
this.logger.setContext(RevisionsService.name);
|
||||||
|
}
|
||||||
|
|
||||||
async getNoteRevisionMetadatas(
|
async getNoteRevisionMetadatas(
|
||||||
noteIdOrAlias: string,
|
noteIdOrAlias: string,
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { LoggerModule } from '../logger/logger.module';
|
||||||
import { AuthToken } from './auth-token.entity';
|
import { AuthToken } from './auth-token.entity';
|
||||||
import { Identity } from './identity.entity';
|
import { Identity } from './identity.entity';
|
||||||
import { User } from './user.entity';
|
import { User } from './user.entity';
|
||||||
import { UsersService } from './users.service';
|
import { UsersService } from './users.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TypeOrmModule.forFeature([User, AuthToken, Identity])],
|
imports: [
|
||||||
|
TypeOrmModule.forFeature([User, AuthToken, Identity]),
|
||||||
|
LoggerModule,
|
||||||
|
],
|
||||||
providers: [UsersService],
|
providers: [UsersService],
|
||||||
exports: [UsersService],
|
exports: [UsersService],
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { LoggerModule } from '../logger/logger.module';
|
||||||
import { UsersService } from './users.service';
|
import { UsersService } from './users.service';
|
||||||
|
|
||||||
describe('UsersService', () => {
|
describe('UsersService', () => {
|
||||||
|
@ -7,6 +8,7 @@ describe('UsersService', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
providers: [UsersService],
|
providers: [UsersService],
|
||||||
|
imports: [LoggerModule],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
service = module.get<UsersService>(UsersService);
|
service = module.get<UsersService>(UsersService);
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { ConsoleLoggerService } from '../logger/console-logger.service';
|
||||||
import { UserInfoDto } from './user-info.dto';
|
import { UserInfoDto } from './user-info.dto';
|
||||||
import { User } from './user.entity';
|
import { User } from './user.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UsersService {
|
export class UsersService {
|
||||||
private readonly logger = new Logger(UsersService.name);
|
constructor(private readonly logger: ConsoleLoggerService) {
|
||||||
|
this.logger.setContext(UsersService.name);
|
||||||
|
}
|
||||||
|
|
||||||
getUserInfo(): UserInfoDto {
|
getUserInfo(): UserInfoDto {
|
||||||
//TODO: Use the database
|
//TODO: Use the database
|
||||||
|
@ -28,7 +31,7 @@ export class UsersService {
|
||||||
|
|
||||||
toUserDto(user: User | null | undefined): UserInfoDto | null {
|
toUserDto(user: User | null | undefined): UserInfoDto | null {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
this.logger.warn(`toUserDto recieved ${user} argument!`);
|
this.logger.warn(`Recieved ${user} argument!`, 'toUserDto');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import * as request from 'supertest';
|
import * as request from 'supertest';
|
||||||
import { PublicApiModule } from '../../src/api/public/public-api.module';
|
import { PublicApiModule } from '../../src/api/public/public-api.module';
|
||||||
import { GroupsModule } from '../../src/groups/groups.module';
|
import { GroupsModule } from '../../src/groups/groups.module';
|
||||||
|
import { LoggerModule } from '../../src/logger/logger.module';
|
||||||
import { NotesModule } from '../../src/notes/notes.module';
|
import { NotesModule } from '../../src/notes/notes.module';
|
||||||
import { NotesService } from '../../src/notes/notes.service';
|
import { NotesService } from '../../src/notes/notes.service';
|
||||||
import { PermissionsModule } from '../../src/permissions/permissions.module';
|
import { PermissionsModule } from '../../src/permissions/permissions.module';
|
||||||
|
@ -25,6 +26,7 @@ describe('Notes', () => {
|
||||||
autoLoadEntities: true,
|
autoLoadEntities: true,
|
||||||
synchronize: true,
|
synchronize: true,
|
||||||
}),
|
}),
|
||||||
|
LoggerModule,
|
||||||
],
|
],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue