NotesService: Get more note metadata from the database

Some previously hardcoded metadata-values are now retrieved from the database.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2020-09-19 17:40:50 +02:00
parent e1e0e45434
commit 6805c2a41e
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
2 changed files with 39 additions and 21 deletions

View file

@ -1,11 +1,17 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { RevisionsModule } from '../revisions/revisions.module';
import { UsersModule } from '../users/users.module';
import { AuthorColor } from './author-color.entity';
import { Note } from './note.entity';
import { NotesService } from './notes.service';
@Module({
imports: [TypeOrmModule.forFeature([Note, AuthorColor])],
imports: [
TypeOrmModule.forFeature([Note, AuthorColor]),
RevisionsModule,
UsersModule,
],
controllers: [],
providers: [NotesService],
exports: [NotesService],

View file

@ -1,8 +1,9 @@
import { Injectable, Logger } from '@nestjs/common';
import { Inject, Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Revision } from '../revisions/revision.entity';
import { User } from '../users/user.entity';
import { UsersService } from '../users/users.service';
import { NoteMetadataDto } from './note-metadata.dto';
import {
NotePermissionsDto,
@ -10,6 +11,7 @@ import {
} from './note-permissions.dto';
import { NoteDto } from './note.dto';
import { Note } from './note.entity';
import { NoteUtils } from './note.utils';
@Injectable()
export class NotesService {
@ -17,6 +19,7 @@ export class NotesService {
constructor(
@InjectRepository(Note) private noteRepository: Repository<Note>,
@Inject(UsersService) private usersService: UsersService,
) {}
getUserNotes(username: string): NoteMetadataDto[] {
@ -75,32 +78,41 @@ export class NotesService {
}
getCurrentContent(note: Note) {
return note.revisions[note.revisions.length - 1].content;
return this.getLastRevision(note).content;
}
getMetadata(note: Note) {
getLastRevision(note: Note) {
return note.revisions[note.revisions.length - 1];
}
getMetadata(note: Note): NoteMetadataDto {
return {
alias: note.alias,
createTime: new Date(),
description: 'Very descriptive text.',
editedBy: [],
// TODO: Convert DB UUID to base64
id: note.id,
alias: note.alias,
title: NoteUtils.parseTitle(note),
// TODO: Get actual createTime
createTime: new Date(),
description: NoteUtils.parseDescription(note),
editedBy: note.authorColors.map(authorColor => authorColor.user.userName),
// TODO: Extract into method
permission: {
owner: {
displayName: 'foo',
userName: 'fooUser',
email: 'foo@example.com',
photo: '',
},
sharedToUsers: [],
sharedToGroups: [],
owner: this.usersService.toUserDto(note.owner),
sharedToUsers: note.userPermissions.map(noteUserPermission => ({
user: this.usersService.toUserDto(noteUserPermission.user),
canEdit: noteUserPermission.canEdit,
})),
sharedToGroups: note.groupPermissions.map(noteGroupPermission => ({
group: noteGroupPermission.group,
canEdit: noteGroupPermission.canEdit,
})),
},
tags: [],
title: 'Title!',
updateTime: new Date(),
tags: NoteUtils.parseTags(note),
updateTime: this.getLastRevision(note).createdAt,
// TODO: Get actual updateUser
updateUser: {
displayName: 'foo',
userName: 'fooUser',
displayName: 'Hardcoded User',
userName: 'hardcoded',
email: 'foo@example.com',
photo: '',
},