prod-wag-backend-automate-s.../WebServices/management-frontend/src/eventRouters/appendersService/schemaList/events.ts

271 lines
6.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { z } from "zod";
import { flattenFieldDefinitions } from "@/eventRouters/schemas/zodSchemas";
interface EventData {
uu_id: string;
function_code: string;
function_class: string;
description?: string;
property_description?: string;
marketing_layer?: string;
cost?: number;
unit_price?: number;
endpoint_code: string;
endpoint_uu_id: string;
is_confirmed: boolean;
active: boolean;
deleted?: boolean;
created_at?: string;
updated_at?: string;
}
const errorMessages = {
en: {
function_code: "Function code is required",
function_class: "Function class is required",
endpoint_code: "Endpoint code is required",
endpoint_uu_id: "Endpoint UUID is required",
},
tr: {
function_code: "Fonksiyon kodu gereklidir",
function_class: "Fonksiyon sınıfı gereklidir",
endpoint_code: "Endpoint kodu gereklidir",
endpoint_uu_id: "Endpoint UUID gereklidir",
},
};
const getEventBaseSchema = (lang: "en" | "tr" = "en") =>
z.object({
uu_id: z.string().optional(),
function_code: z.string().min(1, errorMessages[lang].function_code),
function_class: z.string().min(1, errorMessages[lang].function_class),
description: z.string().optional(),
property_description: z.string().optional(),
marketing_layer: z.string().optional(),
cost: z.number().optional(),
unit_price: z.number().optional(),
endpoint_code: z.string().min(1, errorMessages[lang].endpoint_code),
endpoint_uu_id: z.string().min(1, errorMessages[lang].endpoint_uu_id),
is_confirmed: z.boolean().default(false),
active: z.boolean().default(true),
deleted: z.boolean().default(false),
created_at: z.string().optional(),
updated_at: z.string().optional(),
});
const EventBaseSchema = getEventBaseSchema("en");
const EventBaseTranslationTr = {
uu_id: "UUID",
function_code: "Fonksiyon kodu",
function_class: "Fonksiyon sınıfı",
description: "Açıklama",
property_description: "Özellik açıklama",
marketing_layer: "Pazarlama katmanı",
cost: "Maliyet",
unit_price: "Birim fiyatı",
endpoint_code: "Endpoint kodu",
endpoint_uu_id: "Endpoint UUID",
is_confirmed: "Onaylandı",
active: "Active",
deleted: "Deleted",
created_at: "Created At",
updated_at: "Updated At",
};
const EventBaseTranslationEn = {
uu_id: "UUID",
function_code: "Function code",
function_class: "Function class",
description: "Description",
property_description: "Property description",
marketing_layer: "Marketing layer",
cost: "Cost",
unit_price: "Unit price",
endpoint_code: "Endpoint code",
endpoint_uu_id: "Endpoint UUID",
is_confirmed: "Confirmed",
active: "Active",
deleted: "Deleted",
created_at: "Created At",
updated_at: "Updated At",
};
const eventBaseFieldDefinitions = {
identificationInfo: {
title: "Event Information",
order: 1,
fields: {
uu_id: {
type: "text",
label: {
tr: EventBaseTranslationTr.uu_id,
en: EventBaseTranslationEn.uu_id,
},
readOnly: true,
required: false,
},
function_code: {
type: "text",
label: {
tr: EventBaseTranslationTr.function_code,
en: EventBaseTranslationEn.function_code,
},
readOnly: false,
required: true,
},
function_class: {
type: "text",
label: {
tr: EventBaseTranslationTr.function_class,
en: EventBaseTranslationEn.function_class,
},
readOnly: false,
required: true,
},
description: {
type: "text",
label: {
tr: EventBaseTranslationTr.description,
en: EventBaseTranslationEn.description,
},
readOnly: false,
required: false,
},
property_description: {
type: "text",
label: {
tr: EventBaseTranslationTr.property_description,
en: EventBaseTranslationEn.property_description,
},
readOnly: false,
required: false,
},
marketing_layer: {
type: "text",
label: {
tr: EventBaseTranslationTr.marketing_layer,
en: EventBaseTranslationEn.marketing_layer,
},
readOnly: false,
required: false,
},
cost: {
type: "number",
label: {
tr: EventBaseTranslationTr.cost,
en: EventBaseTranslationEn.cost,
},
readOnly: false,
required: false,
},
unit_price: {
type: "number",
label: {
tr: EventBaseTranslationTr.unit_price,
en: EventBaseTranslationEn.unit_price,
},
readOnly: false,
required: false,
},
endpoint_code: {
type: "text",
label: {
tr: EventBaseTranslationTr.endpoint_code,
en: EventBaseTranslationEn.endpoint_code,
},
readOnly: false,
required: true,
},
endpoint_uu_id: {
type: "text",
label: {
tr: EventBaseTranslationTr.endpoint_uu_id,
en: EventBaseTranslationEn.endpoint_uu_id,
},
readOnly: false,
required: true,
},
},
},
statusInfo: {
title: "Status Information",
order: 3,
fields: {
active: {
type: "checkbox",
label: {
tr: EventBaseTranslationTr.active,
en: EventBaseTranslationEn.active,
},
readOnly: false,
required: false,
defaultValue: true,
},
deleted: {
type: "checkbox",
label: {
tr: EventBaseTranslationTr.deleted,
en: EventBaseTranslationEn.deleted,
},
readOnly: true,
required: false,
defaultValue: false,
},
is_confirmed: {
type: "checkbox",
label: {
tr: EventBaseTranslationTr.is_confirmed,
en: EventBaseTranslationEn.is_confirmed,
},
readOnly: false,
required: true,
},
},
},
systemInfo: {
title: "System Information",
order: 4,
fields: {
created_at: {
type: "date",
label: {
tr: EventBaseTranslationTr.created_at,
en: EventBaseTranslationEn.created_at,
},
readOnly: true,
required: false,
},
updated_at: {
type: "date",
label: {
tr: EventBaseTranslationTr.updated_at,
en: EventBaseTranslationEn.updated_at,
},
readOnly: true,
required: false,
},
},
},
};
const ViewEventSchema = EventBaseSchema;
const EventSchema = EventBaseSchema;
const eventFlatFieldDefinitions = flattenFieldDefinitions(
eventBaseFieldDefinitions
);
type EventFieldDefinitionsType = typeof eventFlatFieldDefinitions;
const eventFieldsByMode = {
view: Object.keys(eventBaseFieldDefinitions),
};
export type { EventData, EventFieldDefinitionsType };
export {
EventSchema,
eventFlatFieldDefinitions,
EventBaseTranslationEn,
EventBaseTranslationTr,
eventFieldsByMode,
};