New project structure
Beta of extract.js for extracting english locale
This commit is contained in:
parent
e18d2b2f84
commit
2edbd67205
247 changed files with 6405 additions and 4237 deletions
77
server/models/blacklist.js
Normal file
77
server/models/blacklist.js
Normal file
|
@ -0,0 +1,77 @@
|
|||
'use strict';
|
||||
|
||||
const knex = require('../lib/knex');
|
||||
const dtHelpers = require('../lib/dt-helpers');
|
||||
const shares = require('./shares');
|
||||
const tools = require('../lib/tools');
|
||||
|
||||
async function listDTAjax(context, params) {
|
||||
shares.enforceGlobalPermission(context, 'manageBlacklist');
|
||||
|
||||
return await dtHelpers.ajaxList(
|
||||
params,
|
||||
builder => builder
|
||||
.from('blacklist'),
|
||||
['blacklist.email']
|
||||
);
|
||||
}
|
||||
|
||||
async function search(context, offset, limit, search) {
|
||||
return await knex.transaction(async tx => {
|
||||
shares.enforceGlobalPermission(context, 'manageBlacklist');
|
||||
|
||||
search = '%' + search + '%';
|
||||
|
||||
const count = await tx('blacklist').where('email', 'like', search).count('* as count').first().count;
|
||||
|
||||
const rows = await tx('blacklist').where('email', 'like', search).offset(offset).limit(limit);
|
||||
|
||||
return {
|
||||
emails: rows.map(row => row.email),
|
||||
total: count
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async function add(context, email) {
|
||||
return await knex.transaction(async tx => {
|
||||
shares.enforceGlobalPermission(context, 'manageBlacklist');
|
||||
|
||||
const existing = await tx('blacklist').where('email', email).first();
|
||||
if (!existing) {
|
||||
await tx('blacklist').insert({email});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function remove(context, email) {
|
||||
shares.enforceGlobalPermission(context, 'manageBlacklist');
|
||||
await knex('blacklist').where('email', email).del();
|
||||
}
|
||||
|
||||
async function isBlacklisted(email) {
|
||||
const existing = await knex('blacklist').where('email', email).first();
|
||||
return !!existing;
|
||||
}
|
||||
|
||||
async function serverValidate(context, data) {
|
||||
shares.enforceGlobalPermission(context, 'manageBlacklist');
|
||||
const result = {};
|
||||
|
||||
if (data.email) {
|
||||
const user = await knex('blacklist').where('email', data.email).first();
|
||||
|
||||
result.email = {};
|
||||
result.email.invalid = await tools.validateEmail(data.email) !== 0;
|
||||
result.email.exists = !!user;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.add = add;
|
||||
module.exports.remove = remove;
|
||||
module.exports.search = search;
|
||||
module.exports.isBlacklisted = isBlacklisted;
|
||||
module.exports.serverValidate = serverValidate;
|
Loading…
Add table
Add a link
Reference in a new issue