mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-03-15 03:53:03 +00:00
ESLint fixes in models
Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
64b88e8488
commit
e641681483
6 changed files with 80 additions and 57 deletions
|
@ -1,31 +1,41 @@
|
|||
import { AutoIncrement, Table, Column, DataType, PrimaryKey, Model, BelongsTo, createIndexDecorator, ForeignKey } from 'sequelize-typescript'
|
||||
import { Note, User } from './index';
|
||||
import {
|
||||
AutoIncrement,
|
||||
BelongsTo,
|
||||
Column,
|
||||
createIndexDecorator,
|
||||
DataType,
|
||||
ForeignKey,
|
||||
Model,
|
||||
PrimaryKey,
|
||||
Table
|
||||
} from 'sequelize-typescript'
|
||||
import { Note, User } from './index'
|
||||
|
||||
const NoteUserIndex = createIndexDecorator({unique: true});
|
||||
const NoteUserIndex = createIndexDecorator({ unique: true })
|
||||
|
||||
@Table
|
||||
export class Author extends Model<Author> {
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Column(DataType.INTEGER)
|
||||
id: number;
|
||||
id: number
|
||||
|
||||
@Column(DataType.STRING)
|
||||
color: string;
|
||||
color: string
|
||||
|
||||
@ForeignKey(() => Note)
|
||||
@NoteUserIndex
|
||||
@Column(DataType.UUID)
|
||||
noteId: string;
|
||||
noteId: string
|
||||
|
||||
@BelongsTo(() => Note, { foreignKey: 'noteId', onDelete: 'CASCADE', constraints: false, hooks: true })
|
||||
note: Note;
|
||||
note: Note
|
||||
|
||||
@ForeignKey(() => User)
|
||||
@NoteUserIndex
|
||||
@Column(DataType.UUID)
|
||||
userId: string;
|
||||
userId: string
|
||||
|
||||
@BelongsTo(() => User, { foreignKey: 'userId', onDelete: 'CASCADE', constraints: false, hooks: true })
|
||||
user: User;
|
||||
user: User
|
||||
}
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
import { Sequelize } from 'sequelize-typescript'
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { Author } from './author'
|
||||
import { Note } from './note'
|
||||
import { Revision } from './revision'
|
||||
import { Temp } from './temp'
|
||||
import { User } from './user'
|
||||
|
||||
import { logger } from '../logger'
|
||||
import { config } from '../config'
|
||||
|
||||
const { cloneDeep } = require('lodash')
|
||||
const dbconfig = cloneDeep(config.db)
|
||||
dbconfig.logging = config.debug ? (data) => {
|
||||
dbconfig.logging = config.debug ? (data): void => {
|
||||
logger.info(data)
|
||||
} : false
|
||||
|
||||
export let sequelize: any
|
||||
export let sequelize: Sequelize
|
||||
|
||||
// Heroku specific
|
||||
if (config.dbURL) {
|
||||
|
|
|
@ -58,7 +58,7 @@ export class NoteMetadata {
|
|||
opengraph: any
|
||||
}
|
||||
|
||||
@Table({paranoid: false})
|
||||
@Table({ paranoid: false })
|
||||
export class Note extends Model<Note> {
|
||||
@PrimaryKey
|
||||
@Default(Sequelize.UUIDV4)
|
||||
|
@ -75,7 +75,7 @@ export class Note extends Model<Note> {
|
|||
@Column(DataType.STRING)
|
||||
alias: string
|
||||
|
||||
@Column(DataType.ENUM({values: Object.keys(PermissionEnum).map(k => PermissionEnum[k])}))
|
||||
@Column(DataType.ENUM({ values: Object.keys(PermissionEnum).map(k => PermissionEnum[k]) }))
|
||||
permission: PermissionEnum
|
||||
|
||||
@AllowNull(false)
|
||||
|
@ -95,20 +95,20 @@ export class Note extends Model<Note> {
|
|||
@Column
|
||||
ownerId: string
|
||||
|
||||
@BelongsTo(() => User, {foreignKey: 'ownerId', constraints: false, onDelete: 'CASCADE', hooks: true})
|
||||
@BelongsTo(() => User, { foreignKey: 'ownerId', constraints: false, onDelete: 'CASCADE', hooks: true })
|
||||
owner: User
|
||||
|
||||
@ForeignKey(() => User)
|
||||
@Column
|
||||
lastchangeuserId: string
|
||||
|
||||
@BelongsTo(() => User, {foreignKey: 'lastchangeuserId', constraints: false})
|
||||
@BelongsTo(() => User, { foreignKey: 'lastchangeuserId', constraints: false })
|
||||
lastchangeuser: User
|
||||
|
||||
@HasMany(() => Revision, {foreignKey: 'noteId', constraints: false})
|
||||
@HasMany(() => Revision, { foreignKey: 'noteId', constraints: false })
|
||||
revisions: Revision[]
|
||||
|
||||
@HasMany(() => Author, {foreignKey: 'noteId', constraints: false})
|
||||
@HasMany(() => Author, { foreignKey: 'noteId', constraints: false })
|
||||
authors: Author[]
|
||||
|
||||
@Column(DataType.TEXT)
|
||||
|
@ -120,7 +120,7 @@ export class Note extends Model<Note> {
|
|||
this.setDataValue('title', Utils.stripNullByte(value))
|
||||
}
|
||||
|
||||
@Column(DataType.TEXT({length: 'long'}))
|
||||
@Column(DataType.TEXT({ length: 'long' }))
|
||||
get content (): string {
|
||||
return Utils.processData(this.getDataValue('content'), '')
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ export class Note extends Model<Note> {
|
|||
this.setDataValue('content', Utils.stripNullByte(value))
|
||||
}
|
||||
|
||||
@Column(DataType.TEXT({length: 'long'}))
|
||||
@Column(DataType.TEXT({ length: 'long' }))
|
||||
get authorship (): string {
|
||||
return Utils.processData(this.getDataValue('authorship'), [], JSON.parse)
|
||||
}
|
||||
|
|
|
@ -6,21 +6,21 @@ import { Utils } from '../utils'
|
|||
import Sequelize from 'sequelize'
|
||||
// core
|
||||
import { logger } from '../logger'
|
||||
import async = require('async');
|
||||
import moment = require('moment');
|
||||
import childProcess = require('child_process');
|
||||
import shortId = require('shortid');
|
||||
import path = require('path');
|
||||
import async = require('async')
|
||||
import moment = require('moment')
|
||||
import childProcess = require('child_process')
|
||||
import shortId = require('shortid')
|
||||
import path = require('path')
|
||||
|
||||
const Op = Sequelize.Op
|
||||
|
||||
const dmpCallbackCache = {}
|
||||
|
||||
class Data {
|
||||
msg;
|
||||
cacheKey;
|
||||
error;
|
||||
result;
|
||||
msg
|
||||
cacheKey
|
||||
error
|
||||
result
|
||||
}
|
||||
|
||||
function createDmpWorker (): ChildProcess {
|
||||
|
@ -66,7 +66,17 @@ export class Revision extends Model<Revision> {
|
|||
@IsUUID(4)
|
||||
@PrimaryKey
|
||||
@Column
|
||||
id: string;
|
||||
id: string
|
||||
|
||||
@Column(DataType.INTEGER)
|
||||
length: number
|
||||
|
||||
@ForeignKey(() => Note)
|
||||
@Column(DataType.UUID)
|
||||
noteId: string
|
||||
|
||||
@BelongsTo(() => Note, { foreignKey: 'noteId', constraints: false, onDelete: 'CASCADE', hooks: true })
|
||||
note: Note
|
||||
|
||||
@Column(DataType.TEXT({ length: 'long' }))
|
||||
get patch (): string {
|
||||
|
@ -95,9 +105,6 @@ export class Revision extends Model<Revision> {
|
|||
this.setDataValue('content', Utils.stripNullByte(value))
|
||||
}
|
||||
|
||||
@Column(DataType.INTEGER)
|
||||
length: number
|
||||
|
||||
@Column(DataType.TEXT({ length: 'long' }))
|
||||
get authorship (): string {
|
||||
return Utils.processData(this.getDataValue('authorship'), [], JSON.parse)
|
||||
|
@ -107,13 +114,6 @@ export class Revision extends Model<Revision> {
|
|||
this.setDataValue('authorship', value ? JSON.stringify(value) : value)
|
||||
}
|
||||
|
||||
@ForeignKey(() => Note)
|
||||
@Column(DataType.UUID)
|
||||
noteId: string
|
||||
|
||||
@BelongsTo(() => Note, { foreignKey: 'noteId', constraints: false, onDelete: 'CASCADE', hooks: true })
|
||||
note: Note;
|
||||
|
||||
static getNoteRevisions (note: Note, callback): void {
|
||||
Revision.findAll({
|
||||
where: {
|
||||
|
@ -122,9 +122,11 @@ export class Revision extends Model<Revision> {
|
|||
order: [['createdAt', 'DESC']]
|
||||
}).then(function (revisions) {
|
||||
class RevisionDataActions { // TODO: Fix Type in actions.ts
|
||||
time;
|
||||
time
|
||||
|
||||
length
|
||||
}
|
||||
|
||||
const data: RevisionDataActions[] = []
|
||||
revisions.forEach(function (revision) {
|
||||
data.push({
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { DataType, Model, Table, PrimaryKey, Column, Default } from 'sequelize-typescript'
|
||||
import { generate as shortIdGenerate, isValid as shortIdIsValid } from "shortid";
|
||||
import { generate as shortIdGenerate } from 'shortid'
|
||||
|
||||
@Table
|
||||
export class Temp extends Model<Temp> {
|
||||
|
|
|
@ -1,5 +1,17 @@
|
|||
import { Note } from './note'
|
||||
import { Table, BeforeCreate, BeforeUpdate, HasMany, Unique, IsEmail, Column, DataType, PrimaryKey, Model, Default } from 'sequelize-typescript'
|
||||
import {
|
||||
BeforeCreate,
|
||||
BeforeUpdate,
|
||||
Column,
|
||||
DataType,
|
||||
Default,
|
||||
HasMany,
|
||||
IsEmail,
|
||||
Model,
|
||||
PrimaryKey,
|
||||
Table,
|
||||
Unique
|
||||
} from 'sequelize-typescript'
|
||||
import scrypt from 'scrypt-kdf'
|
||||
import { generateAvatarURL } from '../letter-avatars'
|
||||
import { logger } from '../logger'
|
||||
|
@ -41,37 +53,33 @@ export class User extends Model<User> {
|
|||
@PrimaryKey
|
||||
@Default(UUIDV4)
|
||||
@Column(DataType.UUID)
|
||||
id: string;
|
||||
id: string
|
||||
|
||||
@Unique
|
||||
@Column(DataType.STRING)
|
||||
profileid: string;
|
||||
profileid: string
|
||||
|
||||
@Column(DataType.TEXT)
|
||||
profile: string;
|
||||
profile: string
|
||||
|
||||
@Column(DataType.TEXT)
|
||||
history: string;
|
||||
history: string
|
||||
|
||||
@Column(DataType.TEXT)
|
||||
accessToken: string;
|
||||
accessToken: string
|
||||
|
||||
@Column(DataType.TEXT)
|
||||
refreshToken: string;
|
||||
refreshToken: string
|
||||
|
||||
@Column(DataType.UUID)
|
||||
deleteToken: string;
|
||||
deleteToken: string
|
||||
|
||||
@IsEmail
|
||||
@Column(DataType.TEXT)
|
||||
email: string;
|
||||
email: string
|
||||
|
||||
@Column(DataType.TEXT)
|
||||
password: string;
|
||||
|
||||
verifyPassword (attempt: string): Promise<boolean> {
|
||||
return scrypt.verify(Buffer.from(this.password, 'hex'), attempt)
|
||||
}
|
||||
password: string
|
||||
|
||||
@HasMany(() => Note, { foreignKey: 'lastchangeuserId', constraints: false })
|
||||
@HasMany(() => Note, { foreignKey: 'ownerId', constraints: false })
|
||||
|
@ -180,6 +188,10 @@ export class User extends Model<User> {
|
|||
}
|
||||
}
|
||||
|
||||
verifyPassword (attempt: string): Promise<boolean> {
|
||||
return scrypt.verify(Buffer.from(this.password, 'hex'), attempt)
|
||||
}
|
||||
|
||||
parseProfile (profile: string): PhotoProfile | null {
|
||||
try {
|
||||
const parsedProfile: Profile = JSON.parse(profile)
|
||||
|
|
Loading…
Reference in a new issue