forked from Yara724/api
Mirrored previous lookups for accident-ways
This commit is contained in:
@@ -95,5 +95,113 @@ export class LookupsController {
|
||||
async getAccidentCulpritType() {
|
||||
return await this.lookupsService.getAccidentCulpritType();
|
||||
}
|
||||
|
||||
@Get("accident-way")
|
||||
@ApiOkResponse({
|
||||
description: "Returns accident way options for the add-accident-fields step",
|
||||
schema: {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: { type: "number", example: 9 },
|
||||
label: { type: "string", example: "جلو به پهلو" },
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
async getAccidentWay() {
|
||||
return await this.lookupsService.getAccidentWay();
|
||||
}
|
||||
|
||||
@Get("accident-reason")
|
||||
@ApiOkResponse({
|
||||
description:
|
||||
"Returns accident reason options for the add-accident-fields step",
|
||||
schema: {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: { type: "number", example: 23 },
|
||||
label: { type: "string", example: "عدم رعايت فاصله جانبی" },
|
||||
fanavaran: { type: "number", example: 3 },
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
async getAccidentReason() {
|
||||
return await this.lookupsService.getAccidentReason();
|
||||
}
|
||||
|
||||
@Get("accident-type")
|
||||
@ApiOkResponse({
|
||||
description:
|
||||
"Returns accident type options for the add-accident-fields step",
|
||||
schema: {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: { type: "number", example: 3 },
|
||||
label: {
|
||||
type: "string",
|
||||
example: "برخورد یک وسیله نقلیه با وسیله نقلیه پارک شده",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
async getAccidentType() {
|
||||
return await this.lookupsService.getAccidentType();
|
||||
}
|
||||
|
||||
@Get("accident-fields")
|
||||
@ApiOkResponse({
|
||||
description:
|
||||
"Returns all three accident field lookup lists in one call — drop-in replacement for the deprecated expert-blame/request/accident-fields endpoint",
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
accidentWay: {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: { type: "number", example: 9 },
|
||||
label: { type: "string", example: "جلو به پهلو" },
|
||||
},
|
||||
},
|
||||
},
|
||||
accidentReason: {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: { type: "number", example: 23 },
|
||||
label: { type: "string", example: "عدم رعايت فاصله جانبی" },
|
||||
fanavaran: { type: "number", example: 3 },
|
||||
},
|
||||
},
|
||||
},
|
||||
accidentType: {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: { type: "number", example: 3 },
|
||||
label: {
|
||||
type: "string",
|
||||
example: "برخورد یک وسیله نقلیه با وسیله نقلیه پارک شده",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
async getAccidentFields() {
|
||||
return await this.lookupsService.getAccidentFields();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user