v2: разделение слоёв — crud/index.js API-слой, user/ и test/ через crud
This commit is contained in:
+10
-12
@@ -4,6 +4,7 @@
|
||||
// ═══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
const express = require('express');
|
||||
const crud = require('../crud');
|
||||
const q = require('../db/queries');
|
||||
const { pool } = require('../db');
|
||||
|
||||
@@ -30,25 +31,25 @@ function createTestRouter() {
|
||||
|
||||
switch (action) {
|
||||
// ── LIST ──
|
||||
case 'list':
|
||||
const entries = await q.listEntries(company.id, req.query.deleted === '1');
|
||||
return res.json({ ok: true, entries, count: entries.length, company: { id: company.id, client_id: company.client_id } });
|
||||
case 'list': {
|
||||
const { entries, used, limit } = await crud.list(clientId, req.query.deleted === '1');
|
||||
return res.json({ ok: true, entries, count: entries.length, used, limit }); }
|
||||
|
||||
// ── ADD ──
|
||||
case 'add': {
|
||||
const r = await q.createEntry(company.id, req.query.cidr || '', req.query.comment || '', email, impBy);
|
||||
const r = await crud.add(clientId, req.query.cidr || '', req.query.comment || '', email, impBy);
|
||||
return res.json({ ok: true, entry: r.entry, wasNormalized: r.wasNormalized });
|
||||
}
|
||||
|
||||
// ── EDIT ──
|
||||
case 'edit': {
|
||||
const r = await q.updateEntry(parseInt(req.query.id), company.id, req.query.cidr || '', req.query.comment || '', email, impBy);
|
||||
const r = await crud.edit(parseInt(req.query.id), clientId, req.query.cidr || '', req.query.comment || '', email, impBy);
|
||||
return res.json({ ok: true, entry: r.entry, wasNormalized: r.wasNormalized });
|
||||
}
|
||||
|
||||
// ── DELETE ──
|
||||
case 'delete':
|
||||
await q.deleteEntry(parseInt(req.query.id), company.id, email, impBy);
|
||||
await crud.remove(parseInt(req.query.id), clientId, email, impBy);
|
||||
return res.json({ ok: true });
|
||||
|
||||
// ── AUDIT ──
|
||||
@@ -112,10 +113,9 @@ function createTestRouter() {
|
||||
const impBy = idx === 3 ? 'real@nubes.ru' : null;
|
||||
const prefix = cidPrefix[idx];
|
||||
tasks.push((async () => {
|
||||
const co = await q.getOrCreateCompany(clientId, clientId);
|
||||
for (let j = 0; j < perCompany; j++) {
|
||||
try {
|
||||
await q.createEntry(co.id, prefix + '.0.' + j + '.0/24', 'chaos', email, impBy);
|
||||
await crud.add(clientId, prefix + '.0.' + j + '.0/24', 'chaos', email, impBy);
|
||||
ok++;
|
||||
} catch (e) { errors++; }
|
||||
}
|
||||
@@ -127,12 +127,10 @@ function createTestRouter() {
|
||||
const checks = [];
|
||||
let totalEntries = 0, totalAudit = 0, anyDupes = false, anyOverLimit = false;
|
||||
for (const clientId of cids) {
|
||||
const co = await q.getOrCreateCompany(clientId, clientId);
|
||||
const entries = await q.listEntries(co.id);
|
||||
const { entries, limit } = await crud.list(clientId);
|
||||
const cidrs = entries.map(e => e.value_cidr);
|
||||
const dupes = cidrs.length !== new Set(cidrs).size;
|
||||
const limit = await q.getLimit(co);
|
||||
const audit = await q.getAudit(co.id);
|
||||
const audit = await q.getAudit((await q.getOrCreateCompany(clientId, clientId)).id);
|
||||
totalEntries += entries.length;
|
||||
totalAudit += audit.length;
|
||||
if (dupes) anyDupes = true;
|
||||
|
||||
Reference in New Issue
Block a user