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 <git@herrmehren.de>
This commit is contained in:
David Mehren 2020-07-25 20:07:39 +02:00
parent 27126bcde1
commit 9d4e3a54d7
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
5 changed files with 123 additions and 0 deletions

View file

@ -0,0 +1,6 @@
import { IsBoolean } from 'class-validator';
export class HistoryEntryUpdateDto {
@IsBoolean()
pinStatus: boolean;
}

View file

@ -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;
}

View file

@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { HistoryService } from './history.service';
@Module({
providers: [HistoryService],
exports: [HistoryService],
})
export class HistoryModule {}

View file

@ -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>(HistoryService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

View file

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