Commit 0ef4b430 authored by Jarrod's avatar Jarrod 💬

Add zhdict models and admin

parent 13e752e0
module.exports = {
friendlyName: 'Get admin dashboard',
description: '',
fn: async function(inputs) {
let dashboard = {
users: await User.count(),
words: await Word.count(),
wordLists: await WordList.count(),
searches24hr: await DictionarySearchLog.count({ createdAt: { '>=': Date.now() } })
}
if (typeof Comment !== 'undefined') {
dashboard.comments = await Comment.count()
}
return { dashboard }
}
}
\ No newline at end of file
......@@ -10,6 +10,7 @@ module.exports = new Pluggable({
dir: __dirname,
actions: {
// Public routes
/*
'GET /dictionary/:word': { action: 'get-entry', cache: 30 },
'GET /sentences/:word': { action: 'get-sentences', cache: 30 },
......@@ -18,6 +19,12 @@ module.exports = new Pluggable({
'GET /radicals': { action: 'radicals', cache: 86400 },
'GET /radicals/:radical': { action: 'get-radical', cache: 86400 },
*/
// Admin Routes
'GET /admin/dashboard': {
action: 'admin/dashboard',
permission: 'admin'
},
},
helpers: {
......
/**
* DictionarySearchLog.js
*
* A log of all dictionary searches
*/
module.exports = {
attributes: {
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
query: {
type: 'string',
required: true,
description: 'Search term'
},
ip: {
type: 'string',
description: 'IP address of requesting user'
},
totalResults: {
type: 'number',
isInteger: true,
description: 'Number of search results returned',
},
user: {
model: 'user'
},
},
extend: {
user: {
dictionarySearches: {
collection: 'dictionarysearchlog',
via: 'user'
}
}
}
};
/**
* ExampleSentence.js
*
* An example sentence
*/
module.exports = {
attributes: {
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
aggregateId: {
type: 'string'
},
simplified: {
type: 'string',
required: true,
description: 'Simplified variant of sentence',
example: '请问鸡蛋在哪里?'
},
traditional: {
type: 'string',
required: true,
description: 'Traditional variant of sentence',
example: '請問雞蛋在哪裡?'
},
tokens: {
type: 'json',
defaultsTo: []
},
pinyin: {
type: 'string',
description: 'Pinyin pronunciation',
example: 'Qǐngwèn jīdàn zài nǎlǐ?'
},
translations: {
type: 'json',
description: 'Array of English translations',
},
audio: {
type: 'string',
description: 'Simplified radical'
},
author: {
type: 'string',
},
source: {
type: 'string',
},
sourceId: {
type: 'string',
},
translationAuthors: {
type: 'json',
defaultsTo: []
},
}
};
/**
* Word.js
*
* A dictionary entry
*/
module.exports = {
attributes: {
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
aggregateId: {
type: 'string'
},
simplified: {
type: 'string',
required: true,
description: 'Simplified variant of word',
example: '中国'
},
traditional: {
type: 'string',
required: true,
description: 'Traditional variant of word',
example: '中國'
},
pinyin: {
type: 'string',
description: 'Pinyin pronunciation',
example: 'zhong1 guo2'
},
pronunciation: {
type: 'json',
description: 'Formatted pronunciation (array)',
},
definitions: {
type: 'json',
description: 'Array of English meanings'
},
radicalSimplified: {
type: 'string',
description: 'Simplified radical'
},
radicalTraditional: {
type: 'string',
description: 'Simplified radical'
},
strokesSimplified: {
type: 'number',
isInteger: true,
allowNull: true,
description: 'Simplified character stroke count'
},
strokesTraditional: {
type: 'number',
isInteger: true,
allowNull: true,
description: 'Traditional character stroke count'
},
strokesMinRadSimplified: {
type: 'number',
isInteger: true,
allowNull: true,
description: 'Simplified character stroke count minus radical strokes'
},
strokesMinRadTraditional: {
type: 'number',
isInteger: true,
allowNull: true,
description: 'Traditional character stroke count minus radical strokes'
},
variants: {
type: 'json',
description: 'Character variants'
},
frequency: {
type: 'number',
allowNull: true,
description: 'Character/word frequency'
},
hskLevel: {
type: 'number',
isInteger: true,
allowNull: true,
description: 'HSK Level for this word'
}
}
};
/**
* WordList.js
*
* A list of dictionary words
*/
module.exports = {
attributes: {
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
name: {
type: 'string',
required: true,
description: 'Name of the list'
},
user: {
model: 'user'
},
// words: {
// collection: 'word',
// }
},
extend: {
user: {
wordLists: {
collection: 'wordlist',
via: 'user'
}
}
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment