forked from Yara724/api
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
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<any> {
|
|
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<any> {
|
|
return await this.getLookup("accident-causes");
|
|
}
|
|
|
|
async getAccidentReportType(): Promise<any> {
|
|
return await this.getLookup("accident-report-type");
|
|
}
|
|
|
|
async getVehicleUseTypes(): Promise<any> {
|
|
return await this.getLookup("vehicle-use-types");
|
|
}
|
|
|
|
async getDmgPayMethod(): Promise<any> {
|
|
return await this.getLookup("dmg-pay-method");
|
|
}
|
|
|
|
async getDrivingLicenceTypes(): Promise<any> {
|
|
return await this.getLookup("driving-licence-types");
|
|
}
|
|
|
|
async getAccidentCulpritType(): Promise<any> {
|
|
return await this.getLookup("accident-culprit-type");
|
|
}
|
|
}
|