Major architectural improvements: - Created models/services layer for better separation of concerns - Location model with async methods for database operations - ProfanityWord model for content moderation - DatabaseService for centralized database management - ProfanityFilterService refactored to use models - Refactored frontend map implementations to share common code - MapBase class extracts 60-70% of duplicate functionality - Refactored implementations extend MapBase for specific features - Maintained unique geocoding capabilities per implementation - Updated server.js to use new service architecture - All routes now use async/await with models instead of raw queries - Enhanced error handling and maintainability 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
96 lines
No EOL
2.4 KiB
JavaScript
96 lines
No EOL
2.4 KiB
JavaScript
class ProfanityWord {
|
|
constructor(db) {
|
|
this.db = db;
|
|
}
|
|
|
|
async getAll() {
|
|
return new Promise((resolve, reject) => {
|
|
this.db.all(
|
|
'SELECT id, word, severity, category, created_at, created_by FROM profanity_words ORDER BY created_at DESC',
|
|
[],
|
|
(err, rows) => {
|
|
if (err) return reject(err);
|
|
resolve(rows);
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
async loadWords() {
|
|
return new Promise((resolve, reject) => {
|
|
this.db.all(
|
|
'SELECT word, severity, category FROM profanity_words',
|
|
[],
|
|
(err, rows) => {
|
|
if (err) return reject(err);
|
|
resolve(rows);
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
async create(word, severity, category, createdBy = 'admin') {
|
|
return new Promise((resolve, reject) => {
|
|
this.db.run(
|
|
'INSERT INTO profanity_words (word, severity, category, created_by) VALUES (?, ?, ?, ?)',
|
|
[word.toLowerCase(), severity, category, createdBy],
|
|
function(err) {
|
|
if (err) return reject(err);
|
|
resolve({
|
|
id: this.lastID,
|
|
word: word.toLowerCase(),
|
|
severity,
|
|
category,
|
|
created_by: createdBy
|
|
});
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
async update(id, word, severity, category) {
|
|
return new Promise((resolve, reject) => {
|
|
this.db.run(
|
|
'UPDATE profanity_words SET word = ?, severity = ?, category = ? WHERE id = ?',
|
|
[word.toLowerCase(), severity, category, id],
|
|
function(err) {
|
|
if (err) return reject(err);
|
|
resolve({ changes: this.changes });
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
async delete(id) {
|
|
return new Promise((resolve, reject) => {
|
|
this.db.run(
|
|
'DELETE FROM profanity_words WHERE id = ?',
|
|
[id],
|
|
function(err) {
|
|
if (err) return reject(err);
|
|
resolve({ changes: this.changes });
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
async initializeTable() {
|
|
return new Promise((resolve, reject) => {
|
|
this.db.run(`
|
|
CREATE TABLE IF NOT EXISTS profanity_words (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
word TEXT NOT NULL UNIQUE,
|
|
severity TEXT NOT NULL,
|
|
category TEXT NOT NULL,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
created_by TEXT DEFAULT 'system'
|
|
)
|
|
`, (err) => {
|
|
if (err) return reject(err);
|
|
resolve();
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = ProfanityWord; |