1
0
forked from Yara724/api
Files
yara724-api/src/client/entities/schema/client.schema.ts
SepehrYahyaee 4fabed77e5 YARA-1035
2026-06-20 14:51:01 +03:30

115 lines
3.8 KiB
TypeScript

import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import type { ExternalInquiryFlags } from "src/common/types/external-inquiry.types";
export type ClientDocument = ClientModel & Document;
/**
* Per-media (video/image/voice) byte bounds. Either bound is optional so a
* tenant can configure only one side (e.g. raise `maxBytes` without setting
* a floor). When a bound is missing the system-wide default is used (see
* {@link ClientService.getMediaLimits} for the defaults table).
*/
export class ClientMediaLimits {
@Prop({ type: Number, required: false })
minBytes?: number;
@Prop({ type: Number, required: false })
maxBytes?: number;
}
/**
* Bag of per-media-kind limits. Each kind is optional and any unset values
* fall back to the system default (see `ClientService.getMediaLimits`).
*
* Note: the system also keeps an absolute multer ceiling per upload route
* (e.g. 50MB for car-capture videos, 20MB for blame videos, 10MB for
* voice/signature/image). A client-configured `maxBytes` cannot exceed the
* route's multer ceiling because multer rejects oversize requests before
* the request reaches the policy check.
*/
export class ClientMediaSettings {
@Prop({ type: ClientMediaLimits, required: false })
video?: ClientMediaLimits;
@Prop({ type: ClientMediaLimits, required: false })
image?: ClientMediaLimits;
@Prop({ type: ClientMediaLimits, required: false })
voice?: ClientMediaLimits;
}
/**
* Per-insurer toggles for outbound inquiry HTTP. Each flag is AND-ed with the
* global `system_settings.externalApis.sandHubUseLiveApi` master switch.
*/
export class ClientExternalInquirySettings implements Partial<ExternalInquiryFlags> {
@Prop({ type: Boolean, required: false, default: false })
thirdPartyPlate?: boolean;
@Prop({ type: Boolean, required: false, default: false })
carBodyPlate?: boolean;
@Prop({ type: Boolean, required: false, default: false })
personalIdentity?: boolean;
@Prop({ type: Boolean, required: false, default: false })
sheba?: boolean;
@Prop({ type: Boolean, required: false, default: false })
drivingLicense?: boolean;
@Prop({ type: Boolean, required: false, default: false })
carOwnership?: boolean;
}
/**
* Per-tenant tunables. Add new policy fields here; consumers read them via
* `ClientService` with documented defaults so older client documents keep
* working when a field is missing.
*/
export class ClientSettings {
/**
* Max number of days between the accident and the moment a CAR_BODY blame
* file is allowed to be submitted. When unset, consumers fall back to the
* system default (see {@link ClientService.getCarBodyAccidentMaxAgeDays}).
*/
@Prop({ type: Number, required: false })
carBodyAccidentMaxAgeDays?: number;
/**
* Per-kind media upload bounds (V2 upload endpoints). Unset kinds /
* bounds fall back to the defaults in `ClientService.getMediaLimits`.
*/
@Prop({ type: ClientMediaSettings, required: false })
media?: ClientMediaSettings;
/** Per-inquiry live/mock toggles (see {@link ClientExternalInquirySettings}). */
@Prop({ type: ClientExternalInquirySettings, required: false })
externalInquiries?: ClientExternalInquirySettings;
}
@Schema({ collection: "clients", versionKey: false })
export class ClientModel {
@Prop({ required: true, unique: true, type: Object })
clientName: {
persian: string;
english: string;
};
@Prop({ required: false, unique: false, type: Object })
property: {
smsApiKey: string;
};
@Prop({ required: true, unique: false })
useExpertMode: "legal" | "genuine";
@Prop({ required: true, unique: false })
clientCode: number;
@Prop({ type: ClientSettings, required: false, default: {} })
settings?: ClientSettings;
}
export const ClientDbSchema = SchemaFactory.createForClass(ClientModel);