project: rename services -> api

api/user: get domainName from auth service
This commit is contained in:
Chika 2022-08-31 16:18:10 +03:00
parent 8b9c261783
commit 7bbde70631
7 changed files with 12 additions and 15 deletions

View File

@ -1,5 +1,5 @@
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { fetchUser } from 'services/user'; import { getUser } from 'api/user/query';
import styled from 'styled-components'; import styled from 'styled-components';
import { Flex } from 'UIKit/grid'; import { Flex } from 'UIKit/grid';
import { min } from 'UIKit/mq'; import { min } from 'UIKit/mq';
@ -19,7 +19,7 @@ const UserText = styled.span`
`; `;
function User() { function User() {
const { data: user } = useQuery(['user'], () => fetchUser()); const { data: user } = useQuery(['user'], () => getUser());
return <UserText>{user?.displayName}</UserText>; return <UserText>{user?.displayName}</UserText>;
} }

View File

@ -4,7 +4,7 @@ import axios from 'axios';
import { love } from './tools'; import { love } from './tools';
import type { User } from './types'; import type { User } from './types';
export async function fetchUser(config: AxiosRequestConfig) { export async function getUser(config: AxiosRequestConfig) {
const user = await axios const user = await axios
.get<User>(process.env.NEXT_PUBLIC_URL_GET_USER || '', config) .get<User>(process.env.NEXT_PUBLIC_URL_GET_USER || '', config)
.then((res) => love(res.data)); .then((res) => love(res.data));

View File

@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
import type { User } from './types'; import type { User } from './types';
export function love(user: User) { export function love(user: User) {
@ -7,9 +8,3 @@ export function love(user: User) {
return user; return user;
} }
export function getDomainName(user: User) {
const { username, domain } = user;
return `${domain}\\${username}`;
}

View File

@ -5,4 +5,5 @@ export type User = {
position: string; position: string;
mail: string; mail: string;
domain: string; domain: string;
domainName: string;
}; };

View File

@ -8,6 +8,7 @@ const users = {
position: 'Бизнес-аналитик', position: 'Бизнес-аналитик',
mail: 'akalinina@evoleasing.ru', mail: 'akalinina@evoleasing.ru',
domain: 'EVOLEASING', domain: 'EVOLEASING',
domainName: 'EVOLEASING\\akalinina',
}, },
vchikalkin: { vchikalkin: {
username: 'vchikalkin', username: 'vchikalkin',
@ -16,6 +17,7 @@ const users = {
domain: 'EVOLEASING', domain: 'EVOLEASING',
department: 'IT', department: 'IT',
position: 'Старший разработчик', position: 'Старший разработчик',
domainName: 'EVOLEASING\\vchikalkin',
}, },
}; };

View File

@ -1,6 +1,7 @@
/* eslint-disable object-curly-newline */ /* eslint-disable object-curly-newline */
import { useApolloClient } from '@apollo/client'; import { useApolloClient } from '@apollo/client';
import { dehydrate, QueryClient } from '@tanstack/react-query'; import { dehydrate, QueryClient } from '@tanstack/react-query';
import { getUser } from 'api/user/query';
import initializeApollo from 'apollo/client'; import initializeApollo from 'apollo/client';
import * as Calculation from 'Components/Calculation'; import * as Calculation from 'Components/Calculation';
import Output from 'Components/Output'; import Output from 'Components/Output';
@ -8,7 +9,6 @@ import Head from 'next/head';
import getData, { getOwnerData } from 'process/init/get-data'; import getData, { getOwnerData } from 'process/init/get-data';
import injectDefaultReactions from 'process/init/inject-reactions/default'; import injectDefaultReactions from 'process/init/inject-reactions/default';
import { useEffect } from 'react'; import { useEffect } from 'react';
import { fetchUser } from 'services/user';
import { useStore } from 'stores/hooks'; import { useStore } from 'stores/hooks';
import styled from 'styled-components'; import styled from 'styled-components';
import { Box } from 'UIKit/grid'; import { Box } from 'UIKit/grid';
@ -63,7 +63,7 @@ export const getServerSideProps = async ({ req }) => {
const { cookie = '' } = req.headers; const { cookie = '' } = req.headers;
// prettier-ignore // prettier-ignore
const fetchUserQuery = () => fetchUser({ const queryGetUser = () => getUser({
headers: { headers: {
cookie, cookie,
}, },
@ -71,7 +71,7 @@ export const getServerSideProps = async ({ req }) => {
const queryClient = new QueryClient(); const queryClient = new QueryClient();
const user = await queryClient.fetchQuery(['user'], fetchUserQuery); const user = await queryClient.fetchQuery(['user'], queryGetUser);
const apolloClient = initializeApollo(); const apolloClient = initializeApollo();

View File

@ -1,7 +1,6 @@
import type { ApolloClient, NormalizedCache } from '@apollo/client'; import type { ApolloClient, NormalizedCache } from '@apollo/client';
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
import { getDomainName } from 'services/user/tools'; import type { User } from 'api/user/types';
import type { User } from 'services/user/types';
import type { GetOwnerData, GetOwnerDataVariables } from './__generated__/GetOwnerData'; import type { GetOwnerData, GetOwnerDataVariables } from './__generated__/GetOwnerData';
const QUERY_GET_OWNER_DATA = gql` const QUERY_GET_OWNER_DATA = gql`
@ -24,7 +23,7 @@ export default async function getOwnerData(
const { data: ownerData } = await apolloClient.query<GetOwnerData, GetOwnerDataVariables>({ const { data: ownerData } = await apolloClient.query<GetOwnerData, GetOwnerDataVariables>({
query: QUERY_GET_OWNER_DATA, query: QUERY_GET_OWNER_DATA,
variables: { variables: {
domainname: getDomainName(user), domainname: user.domainName,
}, },
}); });