project: rename services -> api
api/user: get domainName from auth service
This commit is contained in:
parent
8b9c261783
commit
7bbde70631
@ -1,5 +1,5 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { fetchUser } from 'services/user';
|
||||
import { getUser } from 'api/user/query';
|
||||
import styled from 'styled-components';
|
||||
import { Flex } from 'UIKit/grid';
|
||||
import { min } from 'UIKit/mq';
|
||||
@ -19,7 +19,7 @@ const UserText = styled.span`
|
||||
`;
|
||||
|
||||
function User() {
|
||||
const { data: user } = useQuery(['user'], () => fetchUser());
|
||||
const { data: user } = useQuery(['user'], () => getUser());
|
||||
|
||||
return <UserText>{user?.displayName}</UserText>;
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import axios from 'axios';
|
||||
import { love } from './tools';
|
||||
import type { User } from './types';
|
||||
|
||||
export async function fetchUser(config: AxiosRequestConfig) {
|
||||
export async function getUser(config: AxiosRequestConfig) {
|
||||
const user = await axios
|
||||
.get<User>(process.env.NEXT_PUBLIC_URL_GET_USER || '', config)
|
||||
.then((res) => love(res.data));
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import type { User } from './types';
|
||||
|
||||
export function love(user: User) {
|
||||
@ -7,9 +8,3 @@ export function love(user: User) {
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
export function getDomainName(user: User) {
|
||||
const { username, domain } = user;
|
||||
|
||||
return `${domain}\\${username}`;
|
||||
}
|
||||
@ -5,4 +5,5 @@ export type User = {
|
||||
position: string;
|
||||
mail: string;
|
||||
domain: string;
|
||||
domainName: string;
|
||||
};
|
||||
@ -8,6 +8,7 @@ const users = {
|
||||
position: 'Бизнес-аналитик',
|
||||
mail: 'akalinina@evoleasing.ru',
|
||||
domain: 'EVOLEASING',
|
||||
domainName: 'EVOLEASING\\akalinina',
|
||||
},
|
||||
vchikalkin: {
|
||||
username: 'vchikalkin',
|
||||
@ -16,6 +17,7 @@ const users = {
|
||||
domain: 'EVOLEASING',
|
||||
department: 'IT',
|
||||
position: 'Старший разработчик',
|
||||
domainName: 'EVOLEASING\\vchikalkin',
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
/* eslint-disable object-curly-newline */
|
||||
import { useApolloClient } from '@apollo/client';
|
||||
import { dehydrate, QueryClient } from '@tanstack/react-query';
|
||||
import { getUser } from 'api/user/query';
|
||||
import initializeApollo from 'apollo/client';
|
||||
import * as Calculation from 'Components/Calculation';
|
||||
import Output from 'Components/Output';
|
||||
@ -8,7 +9,6 @@ import Head from 'next/head';
|
||||
import getData, { getOwnerData } from 'process/init/get-data';
|
||||
import injectDefaultReactions from 'process/init/inject-reactions/default';
|
||||
import { useEffect } from 'react';
|
||||
import { fetchUser } from 'services/user';
|
||||
import { useStore } from 'stores/hooks';
|
||||
import styled from 'styled-components';
|
||||
import { Box } from 'UIKit/grid';
|
||||
@ -63,7 +63,7 @@ export const getServerSideProps = async ({ req }) => {
|
||||
const { cookie = '' } = req.headers;
|
||||
|
||||
// prettier-ignore
|
||||
const fetchUserQuery = () => fetchUser({
|
||||
const queryGetUser = () => getUser({
|
||||
headers: {
|
||||
cookie,
|
||||
},
|
||||
@ -71,7 +71,7 @@ export const getServerSideProps = async ({ req }) => {
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
const user = await queryClient.fetchQuery(['user'], fetchUserQuery);
|
||||
const user = await queryClient.fetchQuery(['user'], queryGetUser);
|
||||
|
||||
const apolloClient = initializeApollo();
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import type { ApolloClient, NormalizedCache } from '@apollo/client';
|
||||
import { gql } from '@apollo/client';
|
||||
import { getDomainName } from 'services/user/tools';
|
||||
import type { User } from 'services/user/types';
|
||||
import type { User } from 'api/user/types';
|
||||
import type { GetOwnerData, GetOwnerDataVariables } from './__generated__/GetOwnerData';
|
||||
|
||||
const QUERY_GET_OWNER_DATA = gql`
|
||||
@ -24,7 +23,7 @@ export default async function getOwnerData(
|
||||
const { data: ownerData } = await apolloClient.query<GetOwnerData, GetOwnerDataVariables>({
|
||||
query: QUERY_GET_OWNER_DATA,
|
||||
variables: {
|
||||
domainname: getDomainName(user),
|
||||
domainname: user.domainName,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user