v2: выделение валидации — validate() в crud, db/queries получает готовый cidr
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
// ═══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
const q = require('../db/queries');
|
||||
const { validate } = require('../validators');
|
||||
|
||||
async function resolve(clientId) {
|
||||
return q.getOrCreateCompany(clientId, clientId);
|
||||
@@ -26,13 +27,15 @@ async function list(clientId, includeDeleted = false) {
|
||||
}
|
||||
|
||||
async function add(clientId, cidr, comment, email, impBy) {
|
||||
const { cidr: validated, wasNormalized } = validate(cidr);
|
||||
const co = await resolve(clientId);
|
||||
return q.createEntry(co.id, cidr, comment, email, impBy);
|
||||
return q.createEntry(co.id, validated, comment, email, impBy, wasNormalized);
|
||||
}
|
||||
|
||||
async function edit(entryId, clientId, cidr, comment, email, impBy) {
|
||||
const { cidr: validated, wasNormalized } = validate(cidr);
|
||||
const co = await resolve(clientId);
|
||||
return q.updateEntry(entryId, co.id, cidr, comment, email, impBy);
|
||||
return q.updateEntry(entryId, co.id, validated, comment, email, impBy, wasNormalized);
|
||||
}
|
||||
|
||||
async function remove(entryId, clientId, email, impBy) {
|
||||
|
||||
Reference in New Issue
Block a user