diff --git a/backend/src/repositories/tacticRepository.ts b/backend/src/repositories/tacticRepository.ts index 2a69fb0..6f15c58 100644 --- a/backend/src/repositories/tacticRepository.ts +++ b/backend/src/repositories/tacticRepository.ts @@ -34,21 +34,43 @@ export async function getAllTactics() { .orderBy(tactic.mitre_id); } -export async function getTacticByMitreId(mitreId: string) { - const [result] = await db - .select({ - tacticId: tactic.tactic_id, - mitreId: tactic.mitre_id, - name: tactic.name, - description: tactic.description, - tacticEntryCreated: sql`DATE_FORMAT(${tactic.tactic_entry_created}, '%Y-%m-%d')`, - xMitreDeprecated: tactic.x_mitre_deprecated, - }) - .from(tactic) - .where(eq(tactic.mitre_id, mitreId)) - .limit(1); +export async function getTacticByMitreId( + mitreId: string, +) { + try { + const [result] = await db + .select({ + tacticId: tactic.tactic_id, + mitreId: tactic.mitre_id, + name: tactic.name, + description: tactic.description, + tacticEntryCreated: + tactic.tactic_entry_created, + }) + .from(tactic) + .where( + eq( + tactic.mitre_id, + mitreId, + ), + ) + .limit(1); + + if (!result) { + return null; + } - return result ?? null; + return { + ...result, + xMitreDeprecated: false, + }; + } catch (error) { + console.error( + "TACTIC ERROR:", + error, + ); + throw error; + } } export async function getTacticTechniques(mitreId: string, limit: number, offset: number) {