mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 09:45:37 -04:00
Add NoteModule
This contains the module, a model which was adapted from the old code and two DTOs. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
b528d7f76e
commit
56d5a2e1b1
6 changed files with 196 additions and 1 deletions
36
src/notes/note-metadata.dto.ts
Normal file
36
src/notes/note-metadata.dto.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
import {
|
||||
IsArray,
|
||||
IsDate,
|
||||
IsNumber,
|
||||
IsString,
|
||||
ValidateNested,
|
||||
} from 'class-validator';
|
||||
import { UserInfoDto } from '../users/user-info.dto';
|
||||
import { NotePermissionsDto } from './note-permissions.dto';
|
||||
|
||||
export class NoteMetadataDto {
|
||||
@IsString()
|
||||
id: string;
|
||||
@IsString()
|
||||
alias: string;
|
||||
@IsString()
|
||||
title: string;
|
||||
@IsString()
|
||||
description: string;
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
tags: string[];
|
||||
@IsDate()
|
||||
updateTime: Date;
|
||||
@ValidateNested()
|
||||
updateUser: UserInfoDto;
|
||||
@IsNumber()
|
||||
viewCount: number;
|
||||
@IsDate()
|
||||
createTime: Date;
|
||||
@IsArray()
|
||||
@ValidateNested()
|
||||
editedBy: UserInfoDto['userName'][];
|
||||
@ValidateNested()
|
||||
permission: NotePermissionsDto;
|
||||
}
|
17
src/notes/note-permissions.dto.ts
Normal file
17
src/notes/note-permissions.dto.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { IsArray, IsBoolean, ValidateNested } from 'class-validator';
|
||||
import { UserInfoDto } from '../users/user-info.dto';
|
||||
|
||||
export class NotePermissionEntryDto {
|
||||
@ValidateNested()
|
||||
user: UserInfoDto;
|
||||
@IsBoolean()
|
||||
canEdit: boolean;
|
||||
}
|
||||
|
||||
export class NotePermissionsDto {
|
||||
@ValidateNested()
|
||||
owner: UserInfoDto;
|
||||
@ValidateNested()
|
||||
@IsArray()
|
||||
sharedTo: NotePermissionEntryDto[];
|
||||
}
|
120
src/notes/note.entity.ts
Normal file
120
src/notes/note.entity.ts
Normal file
|
@ -0,0 +1,120 @@
|
|||
import { generate as shortIdGenerate } from 'shortid';
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { Author } from '../authors/author.entity';
|
||||
import { Revision } from '../revisions/revision.entity';
|
||||
import { User } from '../users/user.entity';
|
||||
|
||||
// permission types
|
||||
enum PermissionEnum {
|
||||
freely = 'freely',
|
||||
editable = 'editable',
|
||||
limited = 'limited',
|
||||
locked = 'locked',
|
||||
protected = 'protected',
|
||||
private = 'private',
|
||||
}
|
||||
|
||||
@Entity('Notes')
|
||||
export class Note {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
unique: true,
|
||||
})
|
||||
shortid: string;
|
||||
|
||||
@Column({
|
||||
unique: true,
|
||||
nullable: true,
|
||||
})
|
||||
alias: string;
|
||||
|
||||
@Column({
|
||||
type: 'text',
|
||||
})
|
||||
permission: PermissionEnum;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
default: 0,
|
||||
})
|
||||
viewcount: number;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
lastchangeAt: Date;
|
||||
|
||||
@Column()
|
||||
savedAt: Date;
|
||||
|
||||
@ManyToOne(_ => User, { onDelete: 'CASCADE' })
|
||||
owner: User;
|
||||
|
||||
@ManyToOne(_ => User)
|
||||
lastchangeuser: User;
|
||||
|
||||
@OneToMany(
|
||||
_ => Revision,
|
||||
revision => revision.note,
|
||||
)
|
||||
revisions: Revision[];
|
||||
|
||||
@OneToMany(
|
||||
_ => Author,
|
||||
author => author.note,
|
||||
)
|
||||
authors: Author[];
|
||||
|
||||
@Column({
|
||||
type: 'text',
|
||||
nullable: true,
|
||||
})
|
||||
title: string;
|
||||
|
||||
@Column({
|
||||
type: 'text',
|
||||
})
|
||||
content: string;
|
||||
|
||||
@Column({
|
||||
type: 'text',
|
||||
nullable: true,
|
||||
})
|
||||
authorship: string;
|
||||
|
||||
constructor(
|
||||
shortid: string,
|
||||
alias: string,
|
||||
permission: PermissionEnum,
|
||||
lastchangeAt: Date,
|
||||
savedAt: Date,
|
||||
owner: User,
|
||||
title: string,
|
||||
content: string,
|
||||
authorship: string,
|
||||
) {
|
||||
if (shortid) {
|
||||
this.shortid = shortid;
|
||||
} else {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
this.shortid = shortIdGenerate() as string;
|
||||
}
|
||||
this.alias = alias;
|
||||
this.permission = permission;
|
||||
this.lastchangeAt = lastchangeAt;
|
||||
this.savedAt = savedAt;
|
||||
this.owner = owner;
|
||||
this.title = title;
|
||||
this.content = content;
|
||||
this.authorship = authorship;
|
||||
}
|
||||
}
|
9
src/notes/notes.module.ts
Normal file
9
src/notes/notes.module.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Note } from './note.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Note])],
|
||||
controllers: [],
|
||||
})
|
||||
export class NotesModule {}
|
Loading…
Add table
Add a link
Reference in a new issue