Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

tekenaja

const axios = require('axios')

let tekenUrl = 'https://apix.sandbox-111094.com/v2/data'
let tekenApiKey = ''

const tekenProvince = async () => {
	const resProvince = await axios.get(`${tekenUrl}/province`, {
		headers: { apikey: tekenApiKey }
	})

	return Object.keys(resProvince.data.data).map((val, index) => {
		return { id: val, name: Object.values(resProvince.data.data)[index] }
	})
}

const tekenDistrict = async () => {
	const data = await tekenProvince()
	let listData = []

	const districtData = await data.map(async (val) => {
		const resDistrict = await axios.get(`${tekenUrl}/district?province=${val.id}`, {
			headers: { apikey: tekenApiKey }
		})

		const newDistrictData = []
		Object.keys(resDistrict.data.data).forEach((district, index) => {
			newDistrictData.push({ id: district, name: Object.values(resDistrict.data.data)[index] })
		})
		return newDistrictData
	})

	for (let i in districtData) {
		listData.push({ province: data[i], district: await districtData.flat(Infinity)[i] })
	}

	return listData
}

const tekenSubDistrict = async () => {
	let dukcapil = []

	const district = await tekenDistrict()
	const data = await district.map(async ({ province, district }) => {
		let listData = []

		let subdistrictData = await district.map(async ({ id }) => {
			const resSubdistrict = await axios.get(`${tekenUrl}/subdistrict?province=${province.id}&district=${id}`, {
				headers: { apikey: tekenApiKey }
			})
			return resSubdistrict.data.data
		})

		for (let i in subdistrictData) {
			listData.push(await subdistrictData[i])
		}

		return listData
	})

	for (let i in data) {
		dukcapil.push(await data[i])
	}

	return dukcapil
}

;(async () => {
	const data = await tekenSubDistrict()
	console.log(data.length)
})()
Comment

PREVIOUS NEXT
Code Example
Javascript :: typeorm caching queries limit 
Javascript :: HimalayanCoffeeHouse Noida 
Javascript :: filter state based on text field react 
Javascript :: custom validator Whitelisting 
Javascript :: joi validation error message in path parameter value array to string 
Javascript :: How To Start Any Program In Background Using Vbscript 
Javascript :: yarn redux devtool 
Javascript :: reverse not working react 
Javascript :: stdi nodejs 
Javascript :: eslint failed to load react 
Javascript :: send data with next 
Javascript :: Without a custom hook example in react 
Javascript :: Spread syntax in ES6 
Javascript :: hide header in next js page 
Javascript :: cypress contains regex 
Javascript :: merge json data in main.go in golang 
Javascript :: react native red Half Circle bubble 
Javascript :: how to get csrf token javascript document query selector 
Javascript :: Parametro angulara con ruta y recarga de componente 
Javascript :: react show new app 
Javascript :: node app not visible in browser aws ec2 
Javascript :: Javascript - The file size is measured in bytes 
Javascript :: react Fractional rating 
Javascript :: AJAX XML - update new live data and prevent returning old chache data 
Javascript :: js letter animation 
Javascript :: take site to top after clicking in react 
Javascript :: find star index of string javascript 
Javascript :: catch the last item in a array js 
Javascript :: convert milliseconds to hours minutes seconds days javascript 
Javascript :: how to check if jquery element is loaded 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =