Mirrored previous lookups for accident-ways

This commit is contained in:
SepehrYahyaee
2026-06-16 11:31:41 +03:30
parent b008eda11b
commit 4bd88ff0dd
2 changed files with 148 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
import { readFile } from "node:fs/promises";
import { Injectable, Logger, NotFoundException } from "@nestjs/common";
import { LookupDbService } from "./entities/db-service/lookup.db.service";
@@ -42,4 +43,43 @@ export class LookupsService {
async getAccidentCulpritType(): Promise<any> {
return await this.getLookup("accident-culprit-type");
}
async getAccidentWay(): Promise<{ id: number; label: string }[]> {
const raw: { id: number; persianLabel: string }[] = JSON.parse(
await readFile("src/static/ACCIDENT_WAY.json", "utf-8"),
);
return raw.map((item) => ({ id: item.id, label: item.persianLabel }));
}
async getAccidentReason(): Promise<
{ id: number; label: string; fanavaran: number }[]
> {
const raw: { id: number; persianLabel: string; fanavaranID: number }[] =
JSON.parse(await readFile("src/static/ACCIDENT_REASON.json", "utf-8"));
return raw.map((item) => ({
id: item.id,
label: item.persianLabel,
fanavaran: item.fanavaranID,
}));
}
async getAccidentType(): Promise<{ id: number; label: string }[]> {
const raw: { id: number; persianLabel: string }[] = JSON.parse(
await readFile("src/static/ACCIDENT_TYPE.json", "utf-8"),
);
return raw.map((item) => ({ id: item.id, label: item.persianLabel }));
}
async getAccidentFields(): Promise<{
accidentWay: { id: number; label: string }[];
accidentReason: { id: number; label: string; fanavaran: number }[];
accidentType: { id: number; label: string }[];
}> {
const [accidentWay, accidentReason, accidentType] = await Promise.all([
this.getAccidentWay(),
this.getAccidentReason(),
this.getAccidentType(),
]);
return { accidentWay, accidentReason, accidentType };
}
}