From 9d4e3a54d767e3d62329a4dec96fb6a8df597167 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sat, 25 Jul 2020 20:07:39 +0200 Subject: [PATCH] Add HistoryModule This contains the module, a service (which only returns mock data), a model and two DTOs for history entries. Signed-off-by: David Mehren --- src/history/history-entry-update.dto.ts | 6 ++ src/history/history-entry.dto.ts | 9 +++ src/history/history.module.ts | 8 +++ src/history/history.service.spec.ts | 18 ++++++ src/history/history.service.ts | 82 +++++++++++++++++++++++++ 5 files changed, 123 insertions(+) create mode 100644 src/history/history-entry-update.dto.ts create mode 100644 src/history/history-entry.dto.ts create mode 100644 src/history/history.module.ts create mode 100644 src/history/history.service.spec.ts create mode 100644 src/history/history.service.ts diff --git a/src/history/history-entry-update.dto.ts b/src/history/history-entry-update.dto.ts new file mode 100644 index 000000000..6d481ff0a --- /dev/null +++ b/src/history/history-entry-update.dto.ts @@ -0,0 +1,6 @@ +import { IsBoolean } from 'class-validator'; + +export class HistoryEntryUpdateDto { + @IsBoolean() + pinStatus: boolean; +} diff --git a/src/history/history-entry.dto.ts b/src/history/history-entry.dto.ts new file mode 100644 index 000000000..4899c971e --- /dev/null +++ b/src/history/history-entry.dto.ts @@ -0,0 +1,9 @@ +import { IsBoolean, ValidateNested } from 'class-validator'; +import { NoteMetadataDto } from '../notes/note-metadata.dto'; + +export class HistoryEntryDto { + @ValidateNested() + metadata: NoteMetadataDto; + @IsBoolean() + pinStatus: boolean; +} diff --git a/src/history/history.module.ts b/src/history/history.module.ts new file mode 100644 index 000000000..ee910252e --- /dev/null +++ b/src/history/history.module.ts @@ -0,0 +1,8 @@ +import { Module } from '@nestjs/common'; +import { HistoryService } from './history.service'; + +@Module({ + providers: [HistoryService], + exports: [HistoryService], +}) +export class HistoryModule {} diff --git a/src/history/history.service.spec.ts b/src/history/history.service.spec.ts new file mode 100644 index 000000000..b79a1c6e4 --- /dev/null +++ b/src/history/history.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { HistoryService } from './history.service'; + +describe('HistoryService', () => { + let service: HistoryService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [HistoryService], + }).compile(); + + service = module.get(HistoryService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/src/history/history.service.ts b/src/history/history.service.ts new file mode 100644 index 000000000..f520cba25 --- /dev/null +++ b/src/history/history.service.ts @@ -0,0 +1,82 @@ +import { Injectable } from '@nestjs/common'; +import { HistoryEntryUpdateDto } from './history-entry-update.dto'; +import { HistoryEntryDto } from './history-entry.dto'; + +@Injectable() +export class HistoryService { + getUserHistory(username: string): HistoryEntryDto[] { + //TODO: Use the database + return [ + { + metadata: { + 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, + }, + pinStatus: false, + }, + ]; + } + + updateHistoryEntry( + noteId: string, + updateDto: HistoryEntryUpdateDto, + ): HistoryEntryDto { + //TODO: Use the database + return { + metadata: { + 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, + }, + pinStatus: updateDto.pinStatus, + }; + } + + deleteHistoryEntry(note: string) { + //TODO: Use the database and actually do stuff + throw new Error('Not implemented'); + } +}