import {z} from 'zod' export type GetApiIrSymbolSurveysCompanySurveyIdResponsesArgs = {symbol: string, companySurveyId: number, offset?: number | undefined, limit?: number | undefined}; export type GetApiIrSymbolSurveysCompanySurveyIdResponsesOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const fireAntApiModelsSurveysSurveyAnswerItem = z.object({answerId: z.number().int().optional(), responseId: z.number().int().optional(), questionId: z.number().int().optional(), questionText: z.string().optional(), questionType: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7), z.literal(8), z.literal(9), z.literal(10), z.literal(11), z.literal(12), z.literal(13), z.literal(14), z.literal(15), z.literal(16), z.literal(17)]).optional(), orderIndex: z.number().int().optional(), optionId: z.number().int().optional(), optionText: z.string().optional(), optionValue: z.string().optional(), isOther: z.boolean().optional(), subOptionId: z.number().int().optional(), subOptionText: z.string().optional(), answerText: z.string().optional(), answerNumber: z.number().optional(), answerDate: z.string().optional(), answerDateEnd: z.string().optional(), answerNumberEnd: z.number().optional()}); export const fireAntApiModelsIRIRSurveyResponseItem = z.object({respondentNumber: z.number().int().optional(), submittedDate: z.string().optional(), durationSeconds: z.number().int().optional(), answerCount: z.number().int().optional(), answers: z.array(fireAntApiModelsSurveysSurveyAnswerItem).optional()}); export const fireAntApiModelsIRIRPagedResultFireAntApiModelsIRIRSurveyResponseItem = z.object({items: z.array(fireAntApiModelsIRIRSurveyResponseItem).optional(), totalCount: z.number().int().optional(), offset: z.number().int().optional(), limit: z.number().int().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 }; /** * Phản hồi khảo sát đã ẩn danh. Công ty đọc được nội dung trả lời nhưng không * biết ai trả lời: không có tên đăng nhập, địa chỉ IP hay thiết bị. * * GET /ir/{symbol}/surveys/{companySurveyId}/responses */ export const getApiIrSymbolSurveysCompanySurveyIdResponses = async (args: GetApiIrSymbolSurveysCompanySurveyIdResponsesArgs, options?: GetApiIrSymbolSurveysCompanySurveyIdResponsesOptions) => { const {baseUrl = "https://api.fireant.vn", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/ir/${encodeURIComponent(String(args.symbol))}/surveys/${encodeURIComponent(String(args.companySurveyId))}/responses${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(fireAntApiModelsIRIRPagedResultFireAntApiModelsIRIRSurveyResponseItem, await res.json()) };