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