From e641681483aab028e7aa787c95147c5d8b4449ac Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 12 Apr 2020 13:52:50 +0200 Subject: [PATCH] ESLint fixes in models Signed-off-by: David Mehren --- lib/models/author.ts | 28 ++++++++++++++++++--------- lib/models/index.ts | 7 +++---- lib/models/note.ts | 16 +++++++-------- lib/models/revision.ts | 44 ++++++++++++++++++++++-------------------- lib/models/temp.ts | 2 +- lib/models/user.ts | 40 ++++++++++++++++++++++++-------------- 6 files changed, 80 insertions(+), 57 deletions(-) diff --git a/lib/models/author.ts b/lib/models/author.ts index 40b047b75..d4d092f83 100644 --- a/lib/models/author.ts +++ b/lib/models/author.ts @@ -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 { @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 } diff --git a/lib/models/index.ts b/lib/models/index.ts index 696547bf9..33c5199e9 100644 --- a/lib/models/index.ts +++ b/lib/models/index.ts @@ -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) { diff --git a/lib/models/note.ts b/lib/models/note.ts index a4f94076c..a69813b6c 100644 --- a/lib/models/note.ts +++ b/lib/models/note.ts @@ -58,7 +58,7 @@ export class NoteMetadata { opengraph: any } -@Table({paranoid: false}) +@Table({ paranoid: false }) export class Note extends Model { @PrimaryKey @Default(Sequelize.UUIDV4) @@ -75,7 +75,7 @@ export class Note extends Model { @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 { @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 { 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 { 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) } diff --git a/lib/models/revision.ts b/lib/models/revision.ts index e933bbaf8..5d624f9e4 100644 --- a/lib/models/revision.ts +++ b/lib/models/revision.ts @@ -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 { @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 { 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 { 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 { 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({ diff --git a/lib/models/temp.ts b/lib/models/temp.ts index f7c128fdb..c6a64ebc8 100644 --- a/lib/models/temp.ts +++ b/lib/models/temp.ts @@ -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 { diff --git a/lib/models/user.ts b/lib/models/user.ts index af827ba29..50e906724 100644 --- a/lib/models/user.ts +++ b/lib/models/user.ts @@ -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 { @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 { - 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 { } } + verifyPassword (attempt: string): Promise { + return scrypt.verify(Buffer.from(this.password, 'hex'), attempt) + } + parseProfile (profile: string): PhotoProfile | null { try { const parsedProfile: Profile = JSON.parse(profile)