From b05022945c8416689e41cb9990e2f2e56dbcf99b Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 26 Jul 2020 17:28:58 +0200 Subject: [PATCH] Add NotesService Signed-off-by: David Mehren --- src/notes/notes.module.ts | 3 +++ src/notes/notes.service.spec.ts | 18 +++++++++++++++ src/notes/notes.service.ts | 39 +++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 src/notes/notes.service.spec.ts create mode 100644 src/notes/notes.service.ts diff --git a/src/notes/notes.module.ts b/src/notes/notes.module.ts index b267951f9..d869d692a 100644 --- a/src/notes/notes.module.ts +++ b/src/notes/notes.module.ts @@ -1,9 +1,12 @@ import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { Note } from './note.entity'; +import { NotesService } from './notes.service'; @Module({ imports: [TypeOrmModule.forFeature([Note])], controllers: [], + providers: [NotesService], + exports: [NotesService], }) export class NotesModule {} diff --git a/src/notes/notes.service.spec.ts b/src/notes/notes.service.spec.ts new file mode 100644 index 000000000..18f1c22c6 --- /dev/null +++ b/src/notes/notes.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { NotesService } from './notes.service'; + +describe('NotesService', () => { + let service: NotesService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [NotesService], + }).compile(); + + service = module.get(NotesService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts new file mode 100644 index 000000000..cf66b0190 --- /dev/null +++ b/src/notes/notes.service.ts @@ -0,0 +1,39 @@ +import { Injectable, Logger } from "@nestjs/common"; +import { NoteMetadataDto } from './note-metadata.dto'; + +@Injectable() +export class NotesService { + private readonly logger = new Logger(NotesService.name); + + getUserNotes(username: string): NoteMetadataDto[] { + this.logger.warn('Using hardcoded data!'); + return [ + { + alias: null, + createTime: new Date(), + description: 'Very descriptive text.', + editedBy: [], + id: 'foobar-barfoo', + permission: { + owner: { + displayName: 'foo', + userName: 'fooUser', + email: 'foo@example.com', + photo: '', + }, + sharedTo: [], + }, + tags: [], + title: 'Title!', + updateTime: new Date(), + updateUser: { + displayName: 'foo', + userName: 'fooUser', + email: 'foo@example.com', + photo: '', + }, + viewCount: 42, + }, + ]; + } +}