Refonte: Ksuite 6.58E/user + site 69E/an + domaines + Office + Calendrier + emails extras

This commit is contained in:
2026-08-24 13:18:55 +00:00
parent 8cd9e75682
commit 6a3b16f1e9
4 changed files with 256 additions and 163 deletions
+5 -19
View File
@@ -22,39 +22,25 @@ db.exec(`
company_name TEXT NOT NULL,
parent_id INTEGER,
sort_order INTEGER DEFAULT 0,
has_cloud INTEGER DEFAULT 0,
cloud_details TEXT DEFAULT '',
has_website INTEGER DEFAULT 0,
website_wordpress INTEGER DEFAULT 0,
website_managed_by TEXT DEFAULT '',
website_details TEXT DEFAULT '',
has_emails INTEGER DEFAULT 0,
email_count INTEGER DEFAULT 0,
email_addresses TEXT DEFAULT '[]',
has_team INTEGER DEFAULT 0,
team_members TEXT DEFAULT '[]',
has_office INTEGER DEFAULT 0,
has_calendar INTEGER DEFAULT 0,
domains_list TEXT DEFAULT '[]',
extra_email_count INTEGER DEFAULT 0,
extra_email_cost REAL DEFAULT 0,
notes TEXT DEFAULT '',
monthly_price REAL DEFAULT 0,
cloud_cost REAL DEFAULT 0,
website_cost REAL DEFAULT 0,
email_cost REAL DEFAULT 0,
user_cost REAL DEFAULT 0,
created_at TEXT DEFAULT (datetime('now')),
updated_at TEXT DEFAULT (datetime('now')),
FOREIGN KEY (parent_id) REFERENCES domains(id)
);
`);
// Migration: add cost columns if missing
const columns = db.prepare('PRAGMA table_info(domains)').all().map(c => c.name);
const addCostCol = (col) => {
if (!columns.includes(col)) db.exec('ALTER TABLE domains ADD COLUMN ' + col + ' REAL DEFAULT 0');
};
addCostCol('cloud_cost');
addCostCol('website_cost');
addCostCol('email_cost');
addCostCol('user_cost');
const userCount = db.prepare('SELECT COUNT(*) as count FROM users').get().count;
if (userCount === 0) {
const insert = db.prepare('INSERT INTO users (username, password_hash, name, role) VALUES (?, ?, ?, ?)');
+16 -16
View File
@@ -8,43 +8,43 @@ const app = express();
app.use(cors());
app.use(express.json());
const DOMAIN_FIELDS = [
'has_website', 'website_wordpress', 'website_managed_by', 'website_details',
'has_team', 'team_members', 'has_office', 'has_calendar',
'domains_list', 'extra_email_count', 'extra_email_cost', 'notes'
];
const ADMIN_FIELDS = ['monthly_price'];
app.post('/api/login', (req, res) => {
const { username, password } = req.body;
const user = db.prepare('SELECT * FROM users WHERE username = ?').get(username);
if (!user || !bcrypt.compareSync(password, user.password_hash)) {
return res.status(401).json({ error: 'Identifiants incorrects' });
}
const token = generateToken(user);
res.json({ token, user: { id: user.id, name: user.name, role: user.role } });
res.json({ token: generateToken(user), user: { id: user.id, name: user.name, role: user.role } });
});
app.get('/api/domains', authMiddleware, (req, res) => {
const domains = db.prepare('SELECT * FROM domains ORDER BY sort_order, id').all();
const parent = domains.find(d => !d.parent_id);
const children = domains.filter(d => d.parent_id);
if (req.user.role === 'client') {
domains.forEach(d => { delete d.monthly_price; delete d.cloud_cost; delete d.website_cost; delete d.email_cost; delete d.user_cost; });
}
if (req.user.role === 'client') domains.forEach(d => { delete d.monthly_price; });
res.json({ parent, children });
});
app.get('/api/domains/:id', authMiddleware, (req, res) => {
const domain = db.prepare('SELECT * FROM domains WHERE id = ?').get(req.params.id);
if (!domain) return res.status(404).json({ error: 'Domaine non trouve' });
if (req.user.role === 'client') { delete domain.monthly_price; delete domain.cloud_cost; delete domain.website_cost; delete domain.email_cost; delete domain.user_cost; }
res.json(domain);
const d = db.prepare('SELECT * FROM domains WHERE id = ?').get(req.params.id);
if (!d) return res.status(404).json({ error: 'Domaine non trouve' });
if (req.user.role === 'client') delete d.monthly_price;
res.json(d);
});
app.put('/api/domains/:id', authMiddleware, (req, res) => {
const domain = db.prepare('SELECT * FROM domains WHERE id = ?').get(req.params.id);
if (!domain) return res.status(404).json({ error: 'Domaine non trouve' });
const fields = [
'has_cloud', 'cloud_details', 'has_website', 'website_wordpress',
'website_managed_by', 'website_details', 'has_emails', 'email_count',
'email_addresses', 'has_team', 'team_members', 'notes'
];
if (req.user.role === 'admin') fields.push('monthly_price', 'cloud_cost', 'website_cost', 'email_cost', 'user_cost');
const fields = [...DOMAIN_FIELDS];
if (req.user.role === 'admin') fields.push(...ADMIN_FIELDS);
const updates = {};
fields.forEach(f => { if (req.body[f] !== undefined) updates[f] = req.body[f]; });
@@ -56,7 +56,7 @@ app.put('/api/domains/:id', authMiddleware, (req, res) => {
db.prepare('UPDATE domains SET ' + setClause + ' WHERE id = ?').run(...values);
const updated = db.prepare('SELECT * FROM domains WHERE id = ?').get(req.params.id);
if (req.user.role === 'client') { delete updated.monthly_price; delete updated.cloud_cost; delete updated.website_cost; delete updated.email_cost; delete updated.user_cost; }
if (req.user.role === 'client') delete updated.monthly_price;
res.json(updated);
});