Files
info-target-mobile/screens/auth/login/lib/api.ts
Samandar Turgunboyev 22c1688781 register update
2026-03-18 17:56:26 +05:00

173 lines
4.2 KiB
TypeScript

import httpClient from '@/api/httpClient';
import { API_URLS } from '@/api/URLs';
import axios, { AxiosResponse } from 'axios';
interface ConfirmBody {
status: boolean;
data: {
detail: string;
token: {
access: string;
refresh: string;
};
};
}
export interface GetInfo {
VATRegCode: null | string
VATRegStatus: null | string
account: string
accountant: null | string
address: string
bankAccount: string
bankCode: string
director: string | null
directorPinfl: string | null
directorTin: null | string
fullName: string
fullname: string
isBudget: number
isItd: boolean
mfo: string
na1Code: null | string
na1Name: null | string
name: string
ns10Code: number
ns11Code: number
oked: null | string
peasantFarm: boolean
personalNum: string
privateNotary: boolean
regDate: null | string
selfEmployment: boolean
shortName: string
shortname: string
statusCode: null | string
statusName: null | string
tin: string
}
export interface GetDistrict {
districtId: string,
regionId: number,
districtCode: number,
name: string
}
export interface GetRegion {
regionId: number,
name: string
}
export interface GetTokens {
status: boolean,
data: {
links: {
previous: null | string,
next: null | string
},
total_items: number,
total_pages: number,
page_size: number,
current_page: number,
results:
{
id: number,
key: string,
value: string,
is_active: boolean
}[]
}
}
export const auth_api = {
async login(body: { phone: string }) {
const res = await httpClient.post(API_URLS.LOGIN, body);
return res;
},
async verify_otp(body: { code: string; phone: string }): Promise<AxiosResponse<ConfirmBody>> {
const res = await httpClient.post(API_URLS.LoginConfirm, body);
return res;
},
async resend_otp(body: { phone: string }) {
const res = await httpClient.post(API_URLS.ResendOTP, body);
return res;
},
async get_info(body: { value: string, token: string, tokenName: string }): Promise<AxiosResponse<GetInfo>> {
try {
const res = await axios.get(`https://testapi3.didox.uz/v1/utils/info/${body.value}`, {
headers: {
"Accept-Language": "uz",
[body.tokenName]: body.token
}
});
return res;
} catch (error) {
throw error;
}
},
async get_district(): Promise<AxiosResponse<GetDistrict[]>> {
try {
const res = await axios.get(`https://testapi3.didox.uz/v1/districts/all/`, {
headers: {
"Accept-Language": "uz",
"Partner-Authorization": `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MzYsInN0YXR1cyI6IkFDVElWRSIsIm5hbWUiOiJcIkZFTElYIC0gSVRTXCIgTUNISiIsInJvbGUiOiJQQVJUTkVSIiwidGluIjoiMzA3NTA0MzQ4IiwiaWF0IjoxNzczMzkyMjcwfQ.Q-cIBl4Z784Fq5jdRUEVYF2iaUd7_5RD2sFsJeh-Xno `
}
});
return res;
} catch (error) {
throw error;
}
},
async get_region(): Promise<AxiosResponse<GetRegion[]>> {
try {
const res = await axios.get(`https://testapi3.didox.uz/v1/regions/all/`, {
headers: {
"Accept-Language": "uz",
"Partner-Authorization": `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MzYsInN0YXR1cyI6IkFDVElWRSIsIm5hbWUiOiJcIkZFTElYIC0gSVRTXCIgTUNISiIsInJvbGUiOiJQQVJUTkVSIiwidGluIjoiMzA3NTA0MzQ4IiwiaWF0IjoxNzczMzkyMjcwfQ.Q-cIBl4Z784Fq5jdRUEVYF2iaUd7_5RD2sFsJeh-Xno `
}
});
return res;
} catch (error) {
throw error;
}
},
async register(body: {
phone: string;
stir: string;
person_type: string;
referral: string;
activate_types: number[];
director_full_name: string;
first_name: string;
last_name: string;
district: number;
address: number;
company_name: string;
}) {
const res = await httpClient.post(API_URLS.Register, body);
return res;
},
async register_confirm(body: { phone: string; code: string }) {
const res = await httpClient.post(API_URLS.Register_Confirm, body);
return res;
},
async register_resend(body: { phone: string }) {
const res = await httpClient.post(API_URLS.Register_Resend, body);
return res;
},
async get_tokens(): Promise<AxiosResponse<GetTokens>> {
const res = httpClient.get(API_URLS.GetTokens)
return res
},
};