import { Injectable, Logger, NotFoundException } from "@nestjs/common"; import { LookupDbService } from "./entities/db-service/lookup.db.service"; @Injectable() export class LookupsService { private readonly logger = new Logger(LookupsService.name); constructor(private readonly lookupDbService: LookupDbService) {} /** * Returns stored `response` for a lookup document by `name` in the lookups collection. */ async getLookup(lookupName: string): Promise { const doc = await this.lookupDbService.findOne({ name: lookupName }); if (!doc) { this.logger.warn(`Lookup not found in database: ${lookupName}`); throw new NotFoundException(`Lookup "${lookupName}" not found`); } return doc.response; } async getAccidentCauses(): Promise { return await this.getLookup("accident-causes"); } async getAccidentReportType(): Promise { return await this.getLookup("accident-report-type"); } async getVehicleUseTypes(): Promise { return await this.getLookup("vehicle-use-types"); } async getDmgPayMethod(): Promise { return await this.getLookup("dmg-pay-method"); } async getDrivingLicenceTypes(): Promise { return await this.getLookup("driving-licence-types"); } async getAccidentCulpritType(): Promise { return await this.getLookup("accident-culprit-type"); } }