import {z} from 'zod' export type FireAntApiModelsIRIREventChangeRequest = {type?: (1 | 2 | 3 | 4 | 5 | 6 | 7) | undefined, title: string, description?: string | undefined, startDate?: string | undefined, endDate?: string | undefined, location?: string | undefined, onlineUrl?: string | undefined, publishToSymbolPage?: boolean | undefined, reminderEnabled?: boolean | undefined, reminderLeadHours?: number | undefined, status?: (0 | 1 | 2 | 3) | undefined, allowRegistration?: boolean | undefined, livestreamPostId?: number | undefined}; export type UpdateApiIrSymbolEventsEventIdArgs = {symbol: string, eventId: number, body: FireAntApiModelsIRIREventChangeRequest}; export type UpdateApiIrSymbolEventsEventIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const fireAntApiModelsIRIREventItem = z.object({eventId: z.number().int().optional(), companyId: z.number().int().optional(), type: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7)]).optional(), title: z.string().optional(), description: z.string().optional(), startDate: z.string().optional(), endDate: z.string().optional(), location: z.string().optional(), onlineUrl: z.string().optional(), livestreamPostId: z.number().int().optional(), allowRegistration: z.boolean().optional(), registrations: z.number().int().optional(), publishToSymbolPage: z.boolean().optional(), publishedPostId: z.number().int().optional(), reminderEnabled: z.boolean().optional(), reminderLeadHours: z.number().int().optional(), reminderSentDate: z.string().optional(), status: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3)]).optional(), createdBy: z.string().optional(), createdDate: z.string().optional(), modifiedBy: z.string().optional(), modifiedDate: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Sửa sự kiện * * PUT /ir/{symbol}/events/{eventId} */ export const updateApiIrSymbolEventsEventId = async (args: UpdateApiIrSymbolEventsEventIdArgs, options?: UpdateApiIrSymbolEventsEventIdOptions) => { const {baseUrl = "https://api.fireant.vn", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/ir/${encodeURIComponent(String(args.symbol))}/events/${encodeURIComponent(String(args.eventId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(fireAntApiModelsIRIREventItem, await res.json()) };