Skip to content

Commit 3ac8993

Browse files
committed
refactor: lib/models
- move all interfaces to baseModel.ts - remove unused import
1 parent ded2174 commit 3ac8993

File tree

6 files changed

+79
-81
lines changed

6 files changed

+79
-81
lines changed

lib/models/author.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
// external modules
22

33
import {Model, DataTypes} from "sequelize";
4-
5-
export interface AuthorAttributes {
6-
id: string
7-
color: string
8-
}
4+
import {AuthorAttributes} from "./baseModel";
95

106
export class Author extends Model<AuthorAttributes> implements AuthorAttributes {
117
color: string;

lib/models/baseModel.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,71 @@ export interface BaseModelStatic extends Model {
2020

2121
associate(models: any): void
2222
}
23+
24+
export interface AuthorAttributes {
25+
id: string
26+
color: string
27+
}
28+
29+
export interface NoteAttributes {
30+
id?: string
31+
shortid?: string
32+
alias?: string
33+
permission?: string
34+
viewcount?: number
35+
title?: string
36+
content?: string
37+
authorship?: string
38+
lastchangeAt?: Date
39+
savedAt?: Date
40+
41+
ownerId?: string
42+
}
43+
44+
export interface RevisionAttributes {
45+
id: string
46+
patch: string
47+
lastContent: string
48+
content: string
49+
length: number
50+
authorship: string
51+
}
52+
53+
export interface BaseProfile {
54+
provider: string
55+
}
56+
57+
export interface GenericProfile extends BaseProfile {
58+
provider: string
59+
displayName?: string
60+
username?: string
61+
id?: string
62+
photos?: { value: string }[]
63+
avatarUrl?: string
64+
emails?: string[]
65+
photo?: string
66+
email?: string
67+
}
68+
69+
export interface DropboxProfile extends BaseProfile {
70+
provider: 'dropbox'
71+
emails?: { value: string }[]
72+
}
73+
74+
export interface UserProfile {
75+
name: string
76+
photo: string
77+
biggerphoto: string
78+
}
79+
80+
export interface UserAttributes {
81+
id: string
82+
profileid?: string
83+
profile?: string
84+
history?: string
85+
accessToken?: string
86+
refreshToken?: string
87+
deleteToken?: string
88+
email?: string
89+
password?: string
90+
}

lib/models/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// external modules
2-
import * as fs from "fs";
3-
import * as path from "path";
42
import {Model, Sequelize} from "sequelize";
53
import {cloneDeep} from "lodash";
64

@@ -9,15 +7,15 @@ import config from "../config";
97
import {logger} from "../logger";
108

119

12-
import {BaseModel} from "./baseModel";
10+
import {BaseModel, AuthorAttributes, NoteAttributes, RevisionAttributes, UserAttributes, GenericProfile} from "./baseModel";
1311

14-
import {Author, AuthorAttributes} from './author'
15-
import {User, UserAttributes} from './user'
16-
import {Revision, RevisionAttributes} from "./revision";
17-
import {Note, NoteAttributes} from './note'
12+
import {Author} from './author'
13+
import {User} from './user'
14+
import {Revision} from "./revision";
15+
import {Note} from './note'
1816

1917
export {Author, User, Revision, Note}
20-
export {AuthorAttributes, UserAttributes, RevisionAttributes, NoteAttributes}
18+
export {AuthorAttributes, UserAttributes, RevisionAttributes, NoteAttributes, GenericProfile}
2119

2220
const dbconfig = cloneDeep(config.db)
2321
dbconfig.logging = config.debug ? (data) => {

lib/models/note.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,13 @@ import config from "../config";
2020
import {logger} from "../logger";
2121
import {createNoteWithRevision, syncNote} from "../services/note";
2222
import {stripTags} from "../string";
23-
import {MySequelize} from "./baseModel";
23+
import {MySequelize, NoteAttributes} from "./baseModel";
2424

2525
const md = markdownIt()
2626
export const dmp = new DiffMatchPatch()
2727
// permission types
2828
const permissionTypes = ['freely', 'editable', 'limited', 'locked', 'protected', 'private']
2929

30-
export interface NoteAttributes {
31-
id?: string
32-
shortid?: string
33-
alias?: string
34-
permission?: string
35-
viewcount?: number
36-
title?: string
37-
content?: string
38-
authorship?: string
39-
lastchangeAt?: Date
40-
savedAt?: Date
41-
42-
ownerId?: string
43-
}
44-
4530
export class Note extends Model<NoteAttributes> implements NoteAttributes {
4631
alias: string;
4732
authorship: string;

lib/models/revision.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// external modules
2-
import {Model, Sequelize, Op, DataTypes} from "sequelize";
3-
import async from "async";
2+
import {Model, Op, DataTypes} from "sequelize";
43
import moment from "moment";
54
import * as childProcess from "child_process";
65
import shortId from "shortid";
@@ -10,7 +9,7 @@ import * as util from "util";
109
// core
1110
import config from "../config";
1211
import logger from "../logger";
13-
import {MySequelize} from "./baseModel";
12+
import {MySequelize, RevisionAttributes} from "./baseModel";
1413

1514
let dmpWorker = createDmpWorker()
1615
const dmpCallbackCache = {}
@@ -54,15 +53,6 @@ function sendDmpWorker(data, callback) {
5453
}
5554

5655

57-
export interface RevisionAttributes {
58-
id: string
59-
patch: string
60-
lastContent: string
61-
content: string
62-
length: number
63-
authorship: string
64-
}
65-
6656
export class Revision extends Model<RevisionAttributes> implements RevisionAttributes {
6757
authorship: string;
6858
content: string;

lib/models/user.ts

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,7 @@ import Scrypt from "scrypt-kdf";
33

44
import {logger} from "../logger";
55
import {generateAvatarURL} from "../letter-avatars";
6-
7-
8-
interface BaseProfile {
9-
provider: string
10-
}
11-
12-
interface DropboxProfile extends BaseProfile {
13-
provider: 'dropbox'
14-
emails?: { value: string }[]
15-
}
16-
17-
interface GenericProfile extends BaseProfile {
18-
provider: string
19-
displayName?: string
20-
username?: string
21-
id?: string
22-
photos?: { value: string }[]
23-
avatarUrl?: string
24-
emails?: string[]
25-
photo?: string
26-
email?: string
27-
}
28-
29-
interface UserProfile {
30-
name: string
31-
photo: string
32-
biggerphoto: string
33-
}
34-
35-
export interface UserAttributes {
36-
id: string
37-
profileid?: string
38-
profile?: string
39-
history?: string
40-
accessToken?: string
41-
refreshToken?: string
42-
deleteToken?: string
43-
email?: string
44-
password?: string
45-
}
6+
import {BaseProfile, DropboxProfile, GenericProfile, UserAttributes, UserProfile} from "./baseModel";
467

478
export class User extends Model<UserAttributes> implements UserAttributes {
489
accessToken: string;

0 commit comments

Comments
 (0)