added text endpoint
This commit is contained in:
parent
0f5be58093
commit
e0592eb581
@ -48,3 +48,8 @@ export type Station = Root<{
|
||||
_region: Select;
|
||||
_foto: Image[];
|
||||
}>;
|
||||
|
||||
export type TextResponse = Root<{
|
||||
_name: string;
|
||||
_znachenie: string | null;
|
||||
}>;
|
||||
|
||||
@ -1,6 +1,13 @@
|
||||
import { isEmpty } from 'lodash';
|
||||
|
||||
import { Discount, Image, Job, Partner, Station } from '../@types';
|
||||
import {
|
||||
Discount,
|
||||
Image,
|
||||
Job,
|
||||
Partner,
|
||||
Station,
|
||||
TextResponse,
|
||||
} from '../@types';
|
||||
|
||||
export const presentImage = (images: Image[]) =>
|
||||
isEmpty(images) ? null : `${process.env.TAYLOR_MEDIA_URL}/${images[0].url}`;
|
||||
@ -46,3 +53,9 @@ export const presentStations = (stations: Station) =>
|
||||
region: !isEmpty(station._region) ? station._region[0].name : null,
|
||||
image: presentImage(station._foto),
|
||||
}));
|
||||
|
||||
export const presentTexts = (texts: TextResponse) =>
|
||||
texts.records.map((item) => ({
|
||||
key: item._name,
|
||||
value: item._znachenie,
|
||||
}));
|
||||
|
||||
@ -67,3 +67,12 @@ export const discountsRequest = {
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const textsRequest = {
|
||||
_kontentSajta: {
|
||||
records: {
|
||||
_name: true,
|
||||
_znachenie: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
14
src/app/api/text/route.ts
Normal file
14
src/app/api/text/route.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { presentTexts } from '@/app/api-utlities/presenters';
|
||||
import { textsRequest } from '@/app/api-utlities/requests/common';
|
||||
import { requestTaylor } from '@/app/api-utlities/utilities/taylor.client';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const response = await requestTaylor(textsRequest);
|
||||
|
||||
return new Response(
|
||||
JSON.stringify(presentTexts(response.data._kontentSajta)),
|
||||
{
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
},
|
||||
);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user