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'); + } +}