mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 10:24:05 +00:00
refactor(nest): migrate tagService into TagsService DI (pilot)
Move the tag SQL from src/services/tagService.ts into TagsService over an injected DatabaseService (identical statements, #10b981 default, COALESCE semantics). Non-Nest consumers (MCP tools, plugin RPC host) go through the new tags.bridge.ts, which exports the legacy function names 1:1 from a module-level instance over the shared db Proxy — the settled pattern for the remaining legacy-service migrations (recipe documented in src/nest/README.md). Tests are DI-native: direct service construction in unit (with bridge delegation cases for the coverage gate) and DatabaseModule + real SQL in e2e.
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
import { db } from '../db/database';
|
||||
|
||||
export function listTags(userId: number) {
|
||||
return db.prepare('SELECT * FROM tags WHERE user_id = ? ORDER BY name ASC').all(userId);
|
||||
}
|
||||
|
||||
export function createTag(userId: number, name: string, color?: string) {
|
||||
const result = db.prepare(
|
||||
'INSERT INTO tags (user_id, name, color) VALUES (?, ?, ?)'
|
||||
).run(userId, name, color || '#10b981');
|
||||
return db.prepare('SELECT * FROM tags WHERE id = ?').get(result.lastInsertRowid);
|
||||
}
|
||||
|
||||
export function getTagByIdAndUser(tagId: number | string, userId: number) {
|
||||
return db.prepare('SELECT * FROM tags WHERE id = ? AND user_id = ?').get(tagId, userId);
|
||||
}
|
||||
|
||||
export function updateTag(tagId: number | string, name?: string, color?: string) {
|
||||
db.prepare('UPDATE tags SET name = COALESCE(?, name), color = COALESCE(?, color) WHERE id = ?')
|
||||
.run(name || null, color || null, tagId);
|
||||
return db.prepare('SELECT * FROM tags WHERE id = ?').get(tagId);
|
||||
}
|
||||
|
||||
export function deleteTag(tagId: number | string) {
|
||||
db.prepare('DELETE FROM tags WHERE id = ?').run(tagId);
|
||||
}
|
||||
Reference in New Issue
Block a user