refactor taylor requests
This commit is contained in:
parent
7272c30b2c
commit
69c2e898cf
@ -22,84 +22,84 @@ export interface Select {
|
||||
}
|
||||
|
||||
export type Discount = Root<{
|
||||
_name: string;
|
||||
_opisanie: string;
|
||||
_do: string;
|
||||
_foto: Image[];
|
||||
zagolovok: string;
|
||||
opisanie: string;
|
||||
do: string;
|
||||
foto: Image[];
|
||||
}>;
|
||||
|
||||
export type Job = Root<{
|
||||
id: number;
|
||||
_name: string;
|
||||
_type: Select[];
|
||||
_localtio: Select[];
|
||||
_tags: Select[];
|
||||
zagolovok: string;
|
||||
tip: Select[];
|
||||
lokaciya: Select[];
|
||||
tegi: Select[];
|
||||
}>;
|
||||
|
||||
export type Partner = Root<{
|
||||
id: number;
|
||||
_name: string;
|
||||
_image: Image[];
|
||||
nazvanie: string;
|
||||
izobrozhenie: Image[];
|
||||
}>;
|
||||
|
||||
export type Station = Root<{
|
||||
_name: string;
|
||||
_opisanie: string;
|
||||
_adress: string;
|
||||
_chasyRaboty: Select;
|
||||
_lat: number;
|
||||
_long: number;
|
||||
_avtomojka: boolean;
|
||||
_dtCopy: boolean;
|
||||
_avtomojkaCopy: boolean;
|
||||
_ai92Copy: boolean;
|
||||
_ai95Copy: boolean;
|
||||
_z100Copy: boolean;
|
||||
_propanCopy: boolean;
|
||||
_zaryadnayaStanci: boolean;
|
||||
_miniMarketCop: boolean;
|
||||
_region: Select[];
|
||||
_foto: Image[];
|
||||
imya: string;
|
||||
opisanie: string;
|
||||
adress: string;
|
||||
chasyraboty: Select[];
|
||||
lat: number;
|
||||
long: number;
|
||||
avtomojka: boolean;
|
||||
ai92: boolean;
|
||||
ai95: boolean;
|
||||
z100: boolean;
|
||||
propan: boolean;
|
||||
zaryadnayastanciya: boolean;
|
||||
dt: boolean;
|
||||
minimarket: boolean;
|
||||
tualet: boolean;
|
||||
region: Select[];
|
||||
foto: Image[];
|
||||
}>;
|
||||
|
||||
export type TextResponse = Root<{
|
||||
_name: string;
|
||||
_znachenie: string | null;
|
||||
klyuchneizmenyat: string;
|
||||
znachenie: string | null;
|
||||
}>;
|
||||
|
||||
export type Team = Root<{
|
||||
_foto: Image[];
|
||||
_zvanie: string;
|
||||
_name: string;
|
||||
foto: Image[];
|
||||
zvanie: string;
|
||||
polnoeimya: string;
|
||||
}>;
|
||||
|
||||
export type History = Root<{
|
||||
_name: string;
|
||||
_god: string;
|
||||
_opisanie: string;
|
||||
zagolovok: string;
|
||||
god: string;
|
||||
opisanie: string;
|
||||
}>;
|
||||
|
||||
export type Review = Root<{
|
||||
id: number;
|
||||
_name: string;
|
||||
_otzyv: string;
|
||||
_rejting: number;
|
||||
polnoeimya: string;
|
||||
otzyv: string;
|
||||
rejting: number;
|
||||
}>;
|
||||
|
||||
export type Charity = Root<{
|
||||
_name: string;
|
||||
_opisanie: string;
|
||||
_data: string;
|
||||
_lokaciya: string;
|
||||
_foto: Image[];
|
||||
zagolovok: string;
|
||||
opisanie: string;
|
||||
data: string;
|
||||
lokaciya: string;
|
||||
foto: Image[];
|
||||
}>;
|
||||
|
||||
export type Certificate = Root<{
|
||||
_name: string;
|
||||
_opisanie: string;
|
||||
_dataVydachi: string;
|
||||
_dejstvitelenDo: string;
|
||||
_foto: Image[];
|
||||
nazvanie: string;
|
||||
opisanie: string;
|
||||
datavydachi: string;
|
||||
dejstvitelenDo: string;
|
||||
foto: Image[];
|
||||
}>;
|
||||
|
||||
export type TeamMembers = ReturnType<typeof presentTeamMembers>;
|
||||
|
||||
@ -12,6 +12,7 @@ export const requestTaylor = async (query: object, variables?: object) => {
|
||||
headers: {
|
||||
Authorization: process.env.TAYLOR_API_TOKEN || '',
|
||||
'Content-type': 'application/json',
|
||||
schema: 'readable',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -24,94 +24,94 @@ export const presentSelect = (selectItems: Select[]) =>
|
||||
export const presentPartners = (partners: Partner) =>
|
||||
partners.records.map((record, index) => ({
|
||||
id: index + 1,
|
||||
name: record._name,
|
||||
poster: presentImage(record._image),
|
||||
name: record.nazvanie,
|
||||
poster: presentImage(record.izobrozhenie),
|
||||
}));
|
||||
|
||||
export const presentJobs = (jobs: Job) =>
|
||||
jobs.records.map((job, index) => ({
|
||||
id: index + 1,
|
||||
name: job._name,
|
||||
tags: job._tags.map((tag) => tag.name),
|
||||
location: presentSelect(job._localtio),
|
||||
type: presentSelect(job._type),
|
||||
name: job.zagolovok,
|
||||
tags: job.tegi.map((tag) => tag.name),
|
||||
location: presentSelect(job.lokaciya),
|
||||
type: presentSelect(job.tip),
|
||||
}));
|
||||
|
||||
export const presentTeamMembers = (members: Team) =>
|
||||
members.records.map((member) => ({
|
||||
name: member._name,
|
||||
photo: presentImage(member._foto),
|
||||
profession: member._zvanie,
|
||||
name: member.polnoeimya,
|
||||
photo: presentImage(member.foto),
|
||||
profession: member.zvanie,
|
||||
}));
|
||||
|
||||
export const presentHistoryItems = (historyItems: History) =>
|
||||
historyItems.records.map((item) => ({
|
||||
name: item._name,
|
||||
year: item._god,
|
||||
description: item._opisanie,
|
||||
name: item.zagolovok,
|
||||
year: item.god,
|
||||
description: item.opisanie,
|
||||
}));
|
||||
|
||||
export const presentDiscounts = (discounts: Discount) =>
|
||||
discounts.records.map((discount, index) => ({
|
||||
id: index + 1,
|
||||
name: discount._name,
|
||||
description: discount._opisanie,
|
||||
expiresAt: discount._do,
|
||||
image: presentImage(discount._foto),
|
||||
name: discount.zagolovok,
|
||||
description: discount.opisanie,
|
||||
expiresAt: discount.do,
|
||||
image: presentImage(discount.foto),
|
||||
}));
|
||||
|
||||
export const presentStations = (stations: Station) =>
|
||||
stations.records.map((station, index) => ({
|
||||
id: index + 1,
|
||||
name: station._name,
|
||||
description: station._opisanie,
|
||||
address: station._adress,
|
||||
workingHours: station._chasyRaboty?.name || null,
|
||||
latitude: station._lat,
|
||||
longitude: station._long,
|
||||
carWash: station._avtomojka || false,
|
||||
ai92: station._dtCopy || false,
|
||||
ai95: station._ai92Copy || false,
|
||||
dt: station._avtomojkaCopy || false,
|
||||
z100: station._ai95Copy || false,
|
||||
propan: station._z100Copy || false,
|
||||
electricCharge: station._propanCopy || false,
|
||||
miniMarket: station._zaryadnayaStanci || false,
|
||||
toilet: station._miniMarketCop || false,
|
||||
region: presentSelect(station._region),
|
||||
image: presentImage(station._foto),
|
||||
name: station.imya,
|
||||
description: station.opisanie,
|
||||
address: station.adress,
|
||||
workingHours: presentSelect(station.chasyraboty),
|
||||
latitude: station.lat,
|
||||
longitude: station.long,
|
||||
carWash: station.avtomojka || false,
|
||||
ai92: station.ai92 || false,
|
||||
ai95: station.ai95 || false,
|
||||
dt: station.dt || false,
|
||||
z100: station.z100 || false,
|
||||
propan: station.propan || false,
|
||||
electricCharge: station.zaryadnayastanciya || false,
|
||||
miniMarket: station.minimarket || false,
|
||||
toilet: station.tualet || false,
|
||||
region: presentSelect(station.region),
|
||||
image: presentImage(station.foto),
|
||||
}));
|
||||
|
||||
export const presentTexts = (texts: TextResponse) =>
|
||||
texts.records.map((item) => ({
|
||||
key: item._name,
|
||||
value: item._znachenie,
|
||||
key: item.klyuchneizmenyat,
|
||||
value: item.znachenie,
|
||||
}));
|
||||
|
||||
export const presentReviews = (reviews: Review) =>
|
||||
reviews.records.map((review) => ({
|
||||
id: review.id,
|
||||
fullname: review._name,
|
||||
review: review._otzyv,
|
||||
rating: review._rejting,
|
||||
fullname: review.polnoeimya,
|
||||
review: review.otzyv,
|
||||
rating: review.rejting,
|
||||
}));
|
||||
|
||||
export const presentCharities = (charities: Charity) =>
|
||||
charities.records.map((charity, index) => ({
|
||||
id: index + 1,
|
||||
name: charity._name,
|
||||
description: charity._opisanie,
|
||||
date: charity._data,
|
||||
location: charity._lokaciya,
|
||||
image: presentImage(charity._foto),
|
||||
name: charity.zagolovok,
|
||||
description: charity.opisanie,
|
||||
date: charity.data,
|
||||
location: charity.lokaciya,
|
||||
image: presentImage(charity.foto),
|
||||
}));
|
||||
|
||||
export const presentCertificates = (certificates: Certificate) =>
|
||||
certificates.records.map((certificate, index) => ({
|
||||
id: index + 1,
|
||||
name: certificate._name,
|
||||
description: certificate._opisanie,
|
||||
issuedAt: certificate._dataVydachi,
|
||||
validUntil: certificate._dejstvitelenDo,
|
||||
image: presentImage(certificate._foto),
|
||||
name: certificate.nazvanie,
|
||||
description: certificate.opisanie,
|
||||
issuedAt: certificate.datavydachi,
|
||||
validUntil: certificate.dejstvitelenDo,
|
||||
image: presentImage(certificate.foto),
|
||||
}));
|
||||
|
||||
@ -1,29 +1,29 @@
|
||||
import { EnumType, VariableType } from 'json-to-graphql-query';
|
||||
|
||||
export const stationsRequest = {
|
||||
_azs: {
|
||||
azs: {
|
||||
records: {
|
||||
_name: true,
|
||||
_opisanie: true,
|
||||
_adress: true,
|
||||
_chasyRaboty: {
|
||||
imya: true,
|
||||
opisanie: true,
|
||||
adress: true,
|
||||
chasyraboty: {
|
||||
name: true,
|
||||
},
|
||||
_lat: true,
|
||||
_long: true,
|
||||
_avtomojka: true,
|
||||
_dtCopy: true, // ai92
|
||||
_ai92Copy: true, // ai95
|
||||
_ai95Copy: true, // z100
|
||||
_z100Copy: true, // propan
|
||||
_propanCopy: true, // electricCharge
|
||||
_avtomojkaCopy: true, // DT
|
||||
_zaryadnayaStanci: true, // miniMarket
|
||||
_miniMarketCop: true, // toilet
|
||||
_region: {
|
||||
lat: true,
|
||||
long: true,
|
||||
avtomojka: true,
|
||||
ai92: true,
|
||||
ai95: true,
|
||||
z100: true,
|
||||
propan: true,
|
||||
zaryadnayastanciya: true,
|
||||
dt: true,
|
||||
minimarket: true,
|
||||
tualet: true,
|
||||
region: {
|
||||
name: true,
|
||||
},
|
||||
_foto: {
|
||||
foto: {
|
||||
url: true,
|
||||
},
|
||||
},
|
||||
@ -31,13 +31,13 @@ export const stationsRequest = {
|
||||
};
|
||||
|
||||
export const stationsWithImageRequest = {
|
||||
_azs: {
|
||||
azs: {
|
||||
__args: {
|
||||
filtersSet: {
|
||||
conjunction: new EnumType('and'),
|
||||
filtersSet: [
|
||||
{
|
||||
field: new EnumType('_foto'),
|
||||
field: new EnumType('foto'),
|
||||
operator: 'isNotEmpty',
|
||||
value: [],
|
||||
},
|
||||
@ -46,26 +46,27 @@ export const stationsWithImageRequest = {
|
||||
},
|
||||
|
||||
records: {
|
||||
_name: true,
|
||||
_opisanie: true,
|
||||
_adress: true,
|
||||
_chasyRaboty: {
|
||||
imya: true,
|
||||
opisanie: true,
|
||||
adress: true,
|
||||
chasyraboty: {
|
||||
name: true,
|
||||
},
|
||||
_lat: true,
|
||||
_long: true,
|
||||
_avtomojka: true,
|
||||
_dtCopy: true, // ai92
|
||||
_ai92Copy: true, // ai95
|
||||
_ai95Copy: true, // z100
|
||||
_z100Copy: true, // propan
|
||||
_propanCopy: true, // electricCharge
|
||||
_zaryadnayaStanci: true, // miniMarket
|
||||
_miniMarketCop: true, // toilet
|
||||
_region: {
|
||||
lat: true,
|
||||
long: true,
|
||||
avtomojka: true,
|
||||
ai92: true,
|
||||
ai95: true,
|
||||
z100: true,
|
||||
propan: true,
|
||||
zaryadnayastanciya: true,
|
||||
dt: true,
|
||||
minimarket: true,
|
||||
tualet: true,
|
||||
region: {
|
||||
name: true,
|
||||
},
|
||||
_foto: {
|
||||
foto: {
|
||||
url: true,
|
||||
},
|
||||
},
|
||||
@ -73,10 +74,10 @@ export const stationsWithImageRequest = {
|
||||
};
|
||||
|
||||
export const partnersRequest = {
|
||||
_partners: {
|
||||
partnyory: {
|
||||
records: {
|
||||
_name: true,
|
||||
_image: {
|
||||
nazvanie: true,
|
||||
izobrozhenie: {
|
||||
url: true,
|
||||
},
|
||||
},
|
||||
@ -84,16 +85,16 @@ export const partnersRequest = {
|
||||
};
|
||||
|
||||
export const jobsRequest = {
|
||||
_vacancies: {
|
||||
vakansii: {
|
||||
records: {
|
||||
_name: true,
|
||||
_tags: {
|
||||
zagolovok: true,
|
||||
tegi: {
|
||||
name: true,
|
||||
},
|
||||
_type: {
|
||||
tip: {
|
||||
name: true,
|
||||
},
|
||||
_localtio: {
|
||||
lokaciya: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
@ -101,57 +102,57 @@ export const jobsRequest = {
|
||||
};
|
||||
|
||||
export const discountsRequest = {
|
||||
_akcii: {
|
||||
akcii: {
|
||||
records: {
|
||||
_name: true,
|
||||
_opisanie: true,
|
||||
_do: true,
|
||||
_foto: {
|
||||
url: true,
|
||||
zagolovok: true,
|
||||
opisanie: true,
|
||||
do: true,
|
||||
foto: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const textsRequest = {
|
||||
_kontentSajta: {
|
||||
tekstovyjkontentsajta: {
|
||||
records: {
|
||||
_name: true,
|
||||
_znachenie: true,
|
||||
znachenie: true,
|
||||
klyuchneizmenyat: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const teamRequest = {
|
||||
_komanda: {
|
||||
komanda: {
|
||||
records: {
|
||||
_foto: {
|
||||
foto: {
|
||||
url: true,
|
||||
},
|
||||
_zvanie: true,
|
||||
_name: true,
|
||||
zvanie: true,
|
||||
polnoeimya: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const historyRequest = {
|
||||
_istoriya: {
|
||||
istoriyakompanii: {
|
||||
records: {
|
||||
_name: true,
|
||||
_god: true,
|
||||
_opisanie: true,
|
||||
zagolovok: true,
|
||||
god: true,
|
||||
opisanie: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const reviewsRequest = {
|
||||
_otzyvy: {
|
||||
otzyvy: {
|
||||
__args: {
|
||||
filtersSet: {
|
||||
conjunction: new EnumType('and'),
|
||||
filtersSet: [
|
||||
{
|
||||
field: new EnumType('_status'),
|
||||
field: new EnumType('status'),
|
||||
operator: 'contains',
|
||||
value: 'Опубликовано',
|
||||
},
|
||||
@ -160,21 +161,21 @@ export const reviewsRequest = {
|
||||
},
|
||||
records: {
|
||||
id: true,
|
||||
_name: true,
|
||||
_otzyv: true,
|
||||
_rejting: true,
|
||||
polnoeimya: true,
|
||||
otzyv: true,
|
||||
rejting: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const charityRequest = {
|
||||
_blagotvoriteln: {
|
||||
blagotvoritelnyjfond: {
|
||||
records: {
|
||||
_name: true,
|
||||
_opisanie: true,
|
||||
_data: true,
|
||||
_lokaciya: true,
|
||||
_foto: {
|
||||
zagolovok: true,
|
||||
opisanie: true,
|
||||
data: true,
|
||||
lokaciya: true,
|
||||
foto: {
|
||||
url: true,
|
||||
},
|
||||
},
|
||||
@ -182,13 +183,13 @@ export const charityRequest = {
|
||||
};
|
||||
|
||||
export const certificatesRequest = {
|
||||
_sertifikaty: {
|
||||
sertifikaty: {
|
||||
records: {
|
||||
_name: true,
|
||||
_opisanie: true,
|
||||
_dataVydachi: true,
|
||||
_dejstvitelenDo: true,
|
||||
_foto: {
|
||||
nazvanie: true,
|
||||
opisanie: true,
|
||||
datavydachi: true,
|
||||
dejstvitelendo: true,
|
||||
foto: {
|
||||
url: true,
|
||||
},
|
||||
},
|
||||
@ -199,7 +200,7 @@ export const createReviewMutation = {
|
||||
__variables: {
|
||||
review: 'TableOtzyvyMutationParameters',
|
||||
},
|
||||
_otzyvy: {
|
||||
otzyvy: {
|
||||
createRecord: {
|
||||
__args: {
|
||||
records: [new VariableType('review')],
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { NextRequest } from 'next/server';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { requestTaylor } from '@/app/api-utlities/clients/taylor.client';
|
||||
import { createReviewMutation } from '@/app/api-utlities/requests/common';
|
||||
@ -15,9 +14,9 @@ export const POST = async (req: NextRequest) => {
|
||||
{ mutation: createReviewMutation },
|
||||
{
|
||||
review: {
|
||||
_name: validatedRequest.name,
|
||||
_otzyv: validatedRequest.reviewMessage,
|
||||
_rejting: validatedRequest.rating,
|
||||
polnoeimya: validatedRequest.name,
|
||||
otzyv: validatedRequest.reviewMessage,
|
||||
rejting: validatedRequest.rating,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
@ -37,10 +37,10 @@ export const mainPageApi = taylorAPI.injectEndpoints({
|
||||
|
||||
transformResponse: (response: any) => {
|
||||
return {
|
||||
partners: presentPartners(response.data._partners),
|
||||
jobs: presentJobs(response.data._vacancies),
|
||||
discounts: presentDiscounts(response.data._akcii),
|
||||
stations: presentStations(response.data._azs),
|
||||
partners: presentPartners(response.data.partnyory),
|
||||
jobs: presentJobs(response.data.vakansii),
|
||||
discounts: presentDiscounts(response.data.akcii),
|
||||
stations: presentStations(response.data.azs),
|
||||
};
|
||||
},
|
||||
}),
|
||||
@ -56,10 +56,10 @@ export const mainPageApi = taylorAPI.injectEndpoints({
|
||||
|
||||
transformResponse: (response: any) => {
|
||||
return {
|
||||
team: presentTeamMembers(response.data._komanda),
|
||||
history: presentHistoryItems(response.data._istoriya),
|
||||
stations: presentStations(response.data._azs),
|
||||
reviews: presentReviews(response.data._otzyvy),
|
||||
team: presentTeamMembers(response.data.komanda),
|
||||
history: presentHistoryItems(response.data.istoriyakompanii),
|
||||
stations: presentStations(response.data.azs),
|
||||
reviews: presentReviews(response.data.otzyvy),
|
||||
};
|
||||
},
|
||||
}),
|
||||
@ -75,7 +75,7 @@ export const mainPageApi = taylorAPI.injectEndpoints({
|
||||
|
||||
transformResponse: (response: any) => {
|
||||
return {
|
||||
charities: presentCharities(response.data._blagotvoriteln),
|
||||
charities: presentCharities(response.data.blagotvoritelnyjfond),
|
||||
};
|
||||
},
|
||||
}),
|
||||
@ -91,7 +91,7 @@ export const mainPageApi = taylorAPI.injectEndpoints({
|
||||
|
||||
transformResponse: (response: any) => {
|
||||
return {
|
||||
certificates: presentCertificates(response.data._sertifikaty),
|
||||
certificates: presentCertificates(response.data.sertifikaty),
|
||||
};
|
||||
},
|
||||
}),
|
||||
|
||||
@ -6,6 +6,7 @@ const baseQuery = fetchBaseQuery({
|
||||
baseUrl: process.env.TAYLOR_API_ENDPOINT,
|
||||
headers: {
|
||||
Authorization: process.env.TAYLOR_API_TOKEN || '',
|
||||
schema: 'readable',
|
||||
},
|
||||
next: {
|
||||
tags: [FetchTags.TAYLOR],
|
||||
|
||||
@ -18,7 +18,7 @@ export const textControlApi = taylorAPI.injectEndpoints({
|
||||
}),
|
||||
|
||||
transformResponse: (response: any) => {
|
||||
return presentTexts(response.data._kontentSajta);
|
||||
return presentTexts(response.data.tekstovyjkontentsajta);
|
||||
},
|
||||
}),
|
||||
}),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user