stuff done
This commit is contained in:
88
lib/nova-post-helper.ts
Normal file
88
lib/nova-post-helper.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import cache from 'next/cache'
|
||||
|
||||
export const NP_SETTLEMENT_KYIV_REF = 'e718a680-4b33-11e4-ab6d-005056801329'
|
||||
|
||||
export type Street = {
|
||||
SettlementStreetRef: string
|
||||
Present: string
|
||||
StreetsTypeDescription: string
|
||||
SettlementStreetDescription: string
|
||||
SettlementStreetDescriptionRu: string
|
||||
}
|
||||
|
||||
export type Settlement = {
|
||||
Ref: string
|
||||
Description: string
|
||||
DescriptionRu: string
|
||||
AreaDescription: string
|
||||
AreaDescriptionRu: string
|
||||
SettlementTypeDescription: string
|
||||
SettlementTypeDescriptionRu: string
|
||||
}
|
||||
|
||||
export type Warehouse = {
|
||||
Ref: string
|
||||
Description: string
|
||||
DescriptionRu: string
|
||||
CityDescription: string
|
||||
CityDescriptionRu: string
|
||||
SettlementDescription: string
|
||||
AreaDescription: string
|
||||
SettlementRegionsDescription: string
|
||||
SettlementTypeDescription: string
|
||||
SettlementTypeDescriptionRu: string
|
||||
Longitude: string
|
||||
Latitude: string
|
||||
}
|
||||
|
||||
export const getApi = async (url: string) => {
|
||||
//TODO: need implement caching
|
||||
return await fetch(url)
|
||||
}
|
||||
|
||||
export const formatSettlement = (
|
||||
city: Settlement,
|
||||
locale: string = 'uk'
|
||||
): string => {
|
||||
if (!city) return ''
|
||||
|
||||
if (locale === 'ru') {
|
||||
const {DescriptionRu, AreaDescriptionRu, SettlementTypeDescriptionRu} = city
|
||||
// https://www.alta.ru/fias/socrname/
|
||||
const type = SettlementTypeDescriptionRu.replace(
|
||||
'поселок городского типа',
|
||||
'пгт '
|
||||
)
|
||||
.replace('поселок', 'п. ')
|
||||
.replace('село', 'с. ')
|
||||
.replace('город', 'г. ')
|
||||
|
||||
return (
|
||||
type +
|
||||
DescriptionRu.replace(`(${AreaDescriptionRu} обл.)`, '')
|
||||
.replace(`(${AreaDescriptionRu} обл)`, '')
|
||||
.replace(`${AreaDescriptionRu} обл., `, '')
|
||||
.trim() +
|
||||
` (${AreaDescriptionRu} обл.)`
|
||||
)
|
||||
} else {
|
||||
const {Description, AreaDescription, SettlementTypeDescription} = city
|
||||
const type = SettlementTypeDescription.replace(
|
||||
'селище міського типу',
|
||||
'смт '
|
||||
)
|
||||
.replace('село', 'с. ')
|
||||
.replace('селище', 'с-ще ')
|
||||
.replace('місто', 'м. ')
|
||||
|
||||
return (
|
||||
type +
|
||||
Description.replace(`(${AreaDescription} обл.)`, '')
|
||||
.replace(`(${AreaDescription} обл)`, '')
|
||||
.replace(`(село)`, '')
|
||||
.replace(`${AreaDescription} обл., `, '')
|
||||
.trim() +
|
||||
` (${AreaDescription} обл.)`
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user