refactor: knex remaining models
This commit is contained in:
@@ -1,46 +1,85 @@
|
||||
exports.up = knex => {
|
||||
return knex.schema
|
||||
// -------------------------------------
|
||||
// GROUPS
|
||||
// -------------------------------------
|
||||
// =====================================
|
||||
// MODEL TABLES
|
||||
// =====================================
|
||||
// ASSETS ------------------------------
|
||||
.createTable('assets', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('filename').notNullable()
|
||||
table.string('basename').notNullable()
|
||||
table.string('ext').notNullable()
|
||||
table.enum('kind', ['binary', 'image']).notNullable().defaultTo('binary')
|
||||
table.string('mime').notNullable().defaultTo('application/octet-stream')
|
||||
table.integer('fileSize').unsigned().comment('In kilobytes')
|
||||
table.jsonb('metadata')
|
||||
table.string('createdAt').notNullable()
|
||||
table.string('updatedAt').notNullable()
|
||||
})
|
||||
// ASSET FOLDERS -----------------------
|
||||
.createTable('assetFolders', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('name').notNullable()
|
||||
table.string('slug').notNullable()
|
||||
table.integer('parentId').unsigned().references('id').inTable('assetFolders')
|
||||
})
|
||||
// COMMENTS ----------------------------
|
||||
.createTable('comments', table => {
|
||||
table.increments('id').primary()
|
||||
table.text('content').notNullable()
|
||||
table.string('createdAt').notNullable()
|
||||
table.string('updatedAt').notNullable()
|
||||
})
|
||||
// GROUPS ------------------------------
|
||||
.createTable('groups', table => {
|
||||
table.increments('id').primary()
|
||||
|
||||
table.string('name').notNullable()
|
||||
table.string('createdAt').notNullable()
|
||||
table.string('updatedAt').notNullable()
|
||||
})
|
||||
// -------------------------------------
|
||||
// LOCALES
|
||||
// -------------------------------------
|
||||
// LOCALES -----------------------------
|
||||
.createTable('locales', table => {
|
||||
table.increments('id').primary()
|
||||
|
||||
table.string('code', 2).notNullable().unique()
|
||||
table.json('strings')
|
||||
table.jsonb('strings')
|
||||
table.boolean('isRTL').notNullable().defaultTo(false)
|
||||
table.string('name').notNullable()
|
||||
table.string('nativeName').notNullable()
|
||||
table.string('createdAt').notNullable()
|
||||
table.string('updatedAt').notNullable()
|
||||
})
|
||||
// -------------------------------------
|
||||
// SETTINGS
|
||||
// -------------------------------------
|
||||
.createTable('settings', table => {
|
||||
// PAGES -------------------------------
|
||||
.createTable('pages', table => {
|
||||
table.increments('id').primary()
|
||||
|
||||
table.string('key').notNullable().unique()
|
||||
table.json('value')
|
||||
table.string('path').notNullable()
|
||||
table.string('title').notNullable()
|
||||
table.string('description')
|
||||
table.boolean('isPublished').notNullable().defaultTo(false)
|
||||
table.string('publishStartDate')
|
||||
table.string('publishEndDate')
|
||||
table.text('content')
|
||||
table.string('createdAt').notNullable()
|
||||
table.string('updatedAt').notNullable()
|
||||
})
|
||||
// -------------------------------------
|
||||
// USERS
|
||||
// -------------------------------------
|
||||
// SETTINGS ----------------------------
|
||||
.createTable('settings', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('key').notNullable().unique()
|
||||
table.jsonb('value')
|
||||
table.string('createdAt').notNullable()
|
||||
table.string('updatedAt').notNullable()
|
||||
})
|
||||
// TAGS --------------------------------
|
||||
.createTable('tags', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('tag').notNullable().unique()
|
||||
table.string('title')
|
||||
table.string('createdAt').notNullable()
|
||||
table.string('updatedAt').notNullable()
|
||||
})
|
||||
// USERS -------------------------------
|
||||
.createTable('users', table => {
|
||||
table.increments('id').primary()
|
||||
|
||||
table.string('email').notNullable()
|
||||
table.string('name').notNullable()
|
||||
table.string('provider').notNullable().defaultTo('local')
|
||||
@@ -54,22 +93,52 @@ exports.up = knex => {
|
||||
|
||||
table.unique(['provider', 'email'])
|
||||
})
|
||||
// -------------------------------------
|
||||
// USER GROUPS
|
||||
// -------------------------------------
|
||||
// =====================================
|
||||
// RELATION TABLES
|
||||
// =====================================
|
||||
// PAGE TAGS ---------------------------
|
||||
.createTable('pageTags', table => {
|
||||
table.increments('id').primary()
|
||||
table.integer('pageId').unsigned().references('id').inTable('pages')
|
||||
table.integer('tagId').unsigned().references('id').inTable('tags')
|
||||
})
|
||||
// USER GROUPS -------------------------
|
||||
.createTable('userGroups', table => {
|
||||
table.increments('id').primary()
|
||||
|
||||
table.integer('userId').unsigned().references('id').inTable('users')
|
||||
table.integer('groupId').unsigned().references('id').inTable('groups')
|
||||
})
|
||||
// =====================================
|
||||
// REFERENCES
|
||||
// =====================================
|
||||
.table('assets', table => {
|
||||
table.integer('folderId').unsigned().references('id').inTable('assetFolders')
|
||||
table.integer('authorId').unsigned().references('id').inTable('users')
|
||||
})
|
||||
.table('comments', table => {
|
||||
table.integer('pageId').unsigned().references('id').inTable('pages')
|
||||
table.integer('authorId').unsigned().references('id').inTable('users')
|
||||
})
|
||||
.table('pages', table => {
|
||||
table.string('locale', 2).references('code').inTable('locales')
|
||||
table.integer('authorId').unsigned().references('id').inTable('users')
|
||||
})
|
||||
.table('users', table => {
|
||||
table.string('locale', 2).references('code').inTable('locales')
|
||||
})
|
||||
}
|
||||
|
||||
exports.down = knex => {
|
||||
return knex.schema
|
||||
.dropTableIfExists('userGroups')
|
||||
.dropTableIfExists('pageTags')
|
||||
.dropTableIfExists('assets')
|
||||
.dropTableIfExists('assetFolders')
|
||||
.dropTableIfExists('comments')
|
||||
.dropTableIfExists('groups')
|
||||
.dropTableIfExists('locales')
|
||||
.dropTableIfExists('pages')
|
||||
.dropTableIfExists('settings')
|
||||
.dropTableIfExists('tags')
|
||||
.dropTableIfExists('users')
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
const Model = require('objection').Model
|
||||
|
||||
/**
|
||||
* Settings model
|
||||
* Groups model
|
||||
*/
|
||||
module.exports = class Group extends Model {
|
||||
static get tableName() { return 'groups' }
|
||||
@@ -21,11 +21,10 @@ module.exports = class Group extends Model {
|
||||
}
|
||||
|
||||
static get relationMappings() {
|
||||
const User = require('./users')
|
||||
return {
|
||||
users: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: User,
|
||||
modelClass: require('./users'),
|
||||
join: {
|
||||
from: 'groups.id',
|
||||
through: {
|
||||
|
70
server/db/models/pages.js
Normal file
70
server/db/models/pages.js
Normal file
@@ -0,0 +1,70 @@
|
||||
const Model = require('objection').Model
|
||||
|
||||
/**
|
||||
* Pages model
|
||||
*/
|
||||
module.exports = class Page extends Model {
|
||||
static get tableName() { return 'pages' }
|
||||
|
||||
static get jsonSchema () {
|
||||
return {
|
||||
type: 'object',
|
||||
required: ['path', 'title'],
|
||||
|
||||
properties: {
|
||||
id: {type: 'integer'},
|
||||
path: {type: 'string'},
|
||||
title: {type: 'string'},
|
||||
description: {type: 'string'},
|
||||
isPublished: {type: 'boolean'},
|
||||
publishStartDate: {type: 'string'},
|
||||
publishEndDate: {type: 'string'},
|
||||
content: {type: 'string'},
|
||||
|
||||
createdAt: {type: 'string'},
|
||||
updatedAt: {type: 'string'}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static get relationMappings() {
|
||||
return {
|
||||
tags: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: require('./tags'),
|
||||
join: {
|
||||
from: 'pages.id',
|
||||
through: {
|
||||
from: 'pageTags.pageId',
|
||||
to: 'pageTags.tagId'
|
||||
},
|
||||
to: 'tags.id'
|
||||
}
|
||||
},
|
||||
author: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: require('./users'),
|
||||
join: {
|
||||
from: 'pages.authorId',
|
||||
to: 'users.id'
|
||||
}
|
||||
},
|
||||
locale: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: require('./locales'),
|
||||
join: {
|
||||
from: 'users.locale',
|
||||
to: 'locales.code'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$beforeUpdate() {
|
||||
this.updatedAt = new Date().toISOString()
|
||||
}
|
||||
$beforeInsert() {
|
||||
this.createdAt = new Date().toISOString()
|
||||
this.updatedAt = new Date().toISOString()
|
||||
}
|
||||
}
|
49
server/db/models/tags.js
Normal file
49
server/db/models/tags.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const Model = require('objection').Model
|
||||
|
||||
/**
|
||||
* Tags model
|
||||
*/
|
||||
module.exports = class Tag extends Model {
|
||||
static get tableName() { return 'tags' }
|
||||
|
||||
static get jsonSchema () {
|
||||
return {
|
||||
type: 'object',
|
||||
required: ['tag'],
|
||||
|
||||
properties: {
|
||||
id: {type: 'integer'},
|
||||
tag: {type: 'string'},
|
||||
title: {type: 'string'},
|
||||
|
||||
createdAt: {type: 'string'},
|
||||
updatedAt: {type: 'string'}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static get relationMappings() {
|
||||
return {
|
||||
pages: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: require('./pages'),
|
||||
join: {
|
||||
from: 'tags.id',
|
||||
through: {
|
||||
from: 'pageTags.tagId',
|
||||
to: 'pageTags.pageId'
|
||||
},
|
||||
to: 'pages.id'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$beforeUpdate() {
|
||||
this.updatedAt = new Date().toISOString()
|
||||
}
|
||||
$beforeInsert() {
|
||||
this.createdAt = new Date().toISOString()
|
||||
this.updatedAt = new Date().toISOString()
|
||||
}
|
||||
}
|
@@ -29,6 +29,7 @@ module.exports = class User extends Model {
|
||||
role: {type: 'string', enum: ['admin', 'guest', 'user']},
|
||||
tfaIsActive: {type: 'boolean', default: false},
|
||||
tfaSecret: {type: 'string'},
|
||||
locale: {type: 'string'},
|
||||
createdAt: {type: 'string'},
|
||||
updatedAt: {type: 'string'}
|
||||
}
|
||||
@@ -36,11 +37,10 @@ module.exports = class User extends Model {
|
||||
}
|
||||
|
||||
static get relationMappings() {
|
||||
const Group = require('./groups')
|
||||
return {
|
||||
groups: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: Group,
|
||||
modelClass: require('./groups'),
|
||||
join: {
|
||||
from: 'users.id',
|
||||
through: {
|
||||
@@ -79,7 +79,7 @@ module.exports = class User extends Model {
|
||||
}
|
||||
|
||||
async verifyPassword(pwd) {
|
||||
if (await bcrypt.compare(this.password, pwd) === true) {
|
||||
if (await bcrypt.compare(pwd, this.password) === true) {
|
||||
return true
|
||||
} else {
|
||||
throw new WIKI.Error.AuthLoginFailed()
|
||||
|
51
server/graph/resolvers/page.js
Normal file
51
server/graph/resolvers/page.js
Normal file
@@ -0,0 +1,51 @@
|
||||
const graphHelper = require('../../helpers/graph')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
Query: {
|
||||
async pages() { return {} }
|
||||
},
|
||||
Mutation: {
|
||||
async pages() { return {} }
|
||||
},
|
||||
PageQuery: {
|
||||
async list(obj, args, context, info) {
|
||||
return WIKI.db.groups.query().select(
|
||||
'groups.*',
|
||||
WIKI.db.groups.relatedQuery('users').count().as('userCount')
|
||||
)
|
||||
},
|
||||
async single(obj, args, context, info) {
|
||||
return WIKI.db.groups.query().findById(args.id)
|
||||
}
|
||||
},
|
||||
PageMutation: {
|
||||
async create(obj, args) {
|
||||
const group = await WIKI.db.pages.query().insertAndFetch({
|
||||
name: args.name
|
||||
})
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Group created successfully.'),
|
||||
group
|
||||
}
|
||||
},
|
||||
async delete(obj, args) {
|
||||
await WIKI.db.groups.query().deleteById(args.id)
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Group has been deleted.')
|
||||
}
|
||||
},
|
||||
async update(obj, args) {
|
||||
await WIKI.db.groups.query().patch({ name: args.name }).where('id', args.id)
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Group has been updated.')
|
||||
}
|
||||
}
|
||||
},
|
||||
Page: {
|
||||
// comments(pg) {
|
||||
// return pg.$relatedQuery('comments')
|
||||
// }
|
||||
}
|
||||
}
|
78
server/graph/schemas/page.graphql
Normal file
78
server/graph/schemas/page.graphql
Normal file
@@ -0,0 +1,78 @@
|
||||
# ===============================================
|
||||
# PAGES
|
||||
# ===============================================
|
||||
|
||||
extend type Query {
|
||||
pages: PageQuery
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
pages: PageMutation
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# QUERIES
|
||||
# -----------------------------------------------
|
||||
|
||||
type PageQuery {
|
||||
list(
|
||||
filter: String
|
||||
orderBy: String
|
||||
): [PageMinimal]
|
||||
|
||||
single(
|
||||
id: Int!
|
||||
): Page
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# MUTATIONS
|
||||
# -----------------------------------------------
|
||||
|
||||
type PageMutation {
|
||||
create(
|
||||
description: String
|
||||
isPublished: Boolean
|
||||
locale: String
|
||||
path: String!
|
||||
publishEndDate: Date
|
||||
publishStartDate: Date
|
||||
tags: [String]
|
||||
title: String!
|
||||
): PageResponse
|
||||
|
||||
update(
|
||||
id: Int!
|
||||
name: String!
|
||||
): DefaultResponse
|
||||
|
||||
delete(
|
||||
id: Int!
|
||||
): DefaultResponse
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# TYPES
|
||||
# -----------------------------------------------
|
||||
|
||||
type PageResponse {
|
||||
responseResult: ResponseStatus!
|
||||
page: Page
|
||||
}
|
||||
|
||||
type PageMinimal {
|
||||
id: Int!
|
||||
name: String!
|
||||
userCount: Int
|
||||
createdAt: Date!
|
||||
updatedAt: Date!
|
||||
}
|
||||
|
||||
type Page {
|
||||
id: Int!
|
||||
name: String!
|
||||
rights: [Right]
|
||||
users: [User]
|
||||
createdAt: Date!
|
||||
updatedAt: Date!
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Associate DB Model relations
|
||||
*/
|
||||
module.exports = db => {
|
||||
db.User.belongsToMany(db.Group, { through: 'userGroups' })
|
||||
db.Group.belongsToMany(db.User, { through: 'userGroups' })
|
||||
db.Group.hasMany(db.Right)
|
||||
db.Right.belongsTo(db.Group)
|
||||
db.Document.belongsToMany(db.Tag, { through: 'documentTags' })
|
||||
db.Document.hasMany(db.Comment)
|
||||
db.Tag.belongsToMany(db.Document, { through: 'documentTags' })
|
||||
db.File.belongsTo(db.Folder)
|
||||
db.Folder.hasMany(db.File)
|
||||
db.Comment.belongsTo(db.Document)
|
||||
db.Comment.belongsTo(db.User, { as: 'author' })
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Comment schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let commentSchema = sequelize.define('comment', {
|
||||
content: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true
|
||||
})
|
||||
|
||||
return commentSchema
|
||||
}
|
@@ -1,64 +0,0 @@
|
||||
/**
|
||||
* Document schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let documentSchema = sequelize.define('setting', {
|
||||
path: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
title: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
len: [2, 255]
|
||||
}
|
||||
},
|
||||
subtitle: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
defaultValue: ''
|
||||
},
|
||||
parentPath: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
defaultValue: ''
|
||||
},
|
||||
parentTitle: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
defaultValue: ''
|
||||
},
|
||||
isDirectory: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
},
|
||||
isEntry: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
},
|
||||
isDraft: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
},
|
||||
searchContent: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
defaultValue: ''
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true,
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['path']
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
return documentSchema
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
/**
|
||||
* File schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let fileSchema = sequelize.define('file', {
|
||||
category: {
|
||||
type: DataTypes.ENUM('binary', 'image'),
|
||||
allowNull: false,
|
||||
defaultValue: 'binary'
|
||||
},
|
||||
mime: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
defaultValue: 'application/octet-stream'
|
||||
},
|
||||
extra: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: true
|
||||
},
|
||||
filename: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
basename: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
filesize: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
isInt: true,
|
||||
min: 0
|
||||
}
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true
|
||||
})
|
||||
|
||||
return fileSchema
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
/**
|
||||
* Folder schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let folderSchema = sequelize.define('folder', {
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true,
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['name']
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
return folderSchema
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Group schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let groupSchema = sequelize.define('group', {
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true
|
||||
})
|
||||
|
||||
return groupSchema
|
||||
}
|
@@ -1,39 +0,0 @@
|
||||
/**
|
||||
* Locale schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let localeSchema = sequelize.define('locale', {
|
||||
code: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
strings: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: true
|
||||
},
|
||||
isRTL: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
nativeName: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true,
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['code']
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
return localeSchema
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
/**
|
||||
* Right schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let rightSchema = sequelize.define('right', {
|
||||
path: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
role: {
|
||||
type: DataTypes.ENUM('read', 'write', 'manage'),
|
||||
allowNull: false,
|
||||
defaultValue: 'read'
|
||||
},
|
||||
exact: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
},
|
||||
allow: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true,
|
||||
indexes: [
|
||||
{
|
||||
fields: ['path']
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
return rightSchema
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
/**
|
||||
* Settings schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let settingSchema = sequelize.define('setting', {
|
||||
key: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
config: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true,
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['key']
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
return settingSchema
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
/**
|
||||
* Tags schema
|
||||
*/
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let tagSchema = sequelize.define('tag', {
|
||||
key: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
version: true,
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['key']
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
return tagSchema
|
||||
}
|
@@ -23,12 +23,12 @@ module.exports = {
|
||||
}).then((user) => {
|
||||
if (user) {
|
||||
return user.verifyPassword(uPassword).then(() => {
|
||||
return done(null, user) || true
|
||||
done(null, user)
|
||||
}).catch((err) => {
|
||||
return done(err, null)
|
||||
done(err, null)
|
||||
})
|
||||
} else {
|
||||
return done(new WIKI.Error.AuthLoginFailed(), null)
|
||||
done(new WIKI.Error.AuthLoginFailed(), null)
|
||||
}
|
||||
}).catch((err) => {
|
||||
done(err, null)
|
||||
|
@@ -250,6 +250,8 @@ module.exports = () => {
|
||||
app.post('/finalize', async (req, res) => {
|
||||
WIKI.telemetry.sendEvent('setup', 'finalize')
|
||||
|
||||
console.error('DUDE')
|
||||
|
||||
try {
|
||||
// Upgrade from WIKI.js 1.x?
|
||||
if (req.body.upgrade) {
|
||||
@@ -307,6 +309,16 @@ module.exports = () => {
|
||||
{ key: 'uploads', value: WIKI.config.uploads }
|
||||
])
|
||||
|
||||
// Create default locale
|
||||
WIKI.logger.info('Installing default locale...')
|
||||
await WIKI.db.locales.query().insert({
|
||||
code: 'en',
|
||||
strings: require('./locales/default.json'),
|
||||
isRTL: false,
|
||||
name: 'English',
|
||||
nativeName: 'English'
|
||||
})
|
||||
|
||||
// Create root administrator
|
||||
WIKI.logger.info('Creating root administrator...')
|
||||
await WIKI.db.users.query().insert({
|
||||
@@ -315,6 +327,7 @@ module.exports = () => {
|
||||
password: req.body.adminPassword,
|
||||
name: 'Administrator',
|
||||
role: 'admin',
|
||||
locale: 'en',
|
||||
tfaIsActive: false
|
||||
})
|
||||
|
||||
@@ -331,20 +344,11 @@ module.exports = () => {
|
||||
name: 'Guest',
|
||||
password: '',
|
||||
role: 'guest',
|
||||
locale: 'en',
|
||||
tfaIsActive: false
|
||||
})
|
||||
}
|
||||
|
||||
// Create default locale
|
||||
WIKI.logger.info('Installing default locale...')
|
||||
await WIKI.db.locales.query().insert({
|
||||
code: 'en',
|
||||
strings: require('./locales/default.json'),
|
||||
isRTL: false,
|
||||
name: 'English',
|
||||
nativeName: 'English'
|
||||
})
|
||||
|
||||
WIKI.logger.info('Setup is complete!')
|
||||
res.json({
|
||||
ok: true,
|
||||
|
Reference in New Issue
Block a user