get user & domain from cookies
This commit is contained in:
parent
3509bf8007
commit
0b94ad000d
@ -26,6 +26,7 @@
|
|||||||
"express-ntlm": "^2.5.2",
|
"express-ntlm": "^2.5.2",
|
||||||
"graphql": "^15.4.0",
|
"graphql": "^15.4.0",
|
||||||
"helmet": "^4.2.0",
|
"helmet": "^4.2.0",
|
||||||
|
"js-cookie": "^2.2.1",
|
||||||
"lodash": "^4.17.20",
|
"lodash": "^4.17.20",
|
||||||
"luxon": "^1.25.0",
|
"luxon": "^1.25.0",
|
||||||
"mobx": "^6.0.4",
|
"mobx": "^6.0.4",
|
||||||
|
|||||||
@ -9,80 +9,75 @@ import systemUserQuery from './queries/systemUserQuery';
|
|||||||
|
|
||||||
export default () =>
|
export default () =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
getUser()
|
const { username: UserName, domainname: DomainName, FullName } = getUser();
|
||||||
.then(({ UserName, DomainName, FullName }) => {
|
|
||||||
Promise.all([
|
|
||||||
CrmService.crmgqlquery({
|
|
||||||
...initialOwnerQuery,
|
|
||||||
variables: {
|
|
||||||
statecode: 0,
|
|
||||||
fullName: FullName,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
CrmService.crmgqlquery(optionsQuery),
|
|
||||||
CrmService.crmgqlquery(staticDataQuery),
|
|
||||||
CrmService.crmgqlquery({
|
|
||||||
...systemUserQuery,
|
|
||||||
variables: { username: `${DomainName}\\${UserName}` },
|
|
||||||
}),
|
|
||||||
CrmService.crmgqlquery(insuranceQuery),
|
|
||||||
])
|
|
||||||
.then(
|
|
||||||
([
|
|
||||||
{ entities: ownerOptions },
|
|
||||||
{ entities: initialOptions },
|
|
||||||
{ entities: staticEntities },
|
|
||||||
{
|
|
||||||
entities: { systemuser },
|
|
||||||
},
|
|
||||||
{ entities: insuranceCompanies },
|
|
||||||
]) => {
|
|
||||||
CalculationStore.applyOptions(ownerOptions);
|
|
||||||
CalculationStore.applyOptions(initialOptions);
|
|
||||||
CalculationStore.applyStaticData(staticEntities);
|
|
||||||
CalculationStore.applyStaticData({ systemuser: [systemuser] });
|
|
||||||
CalculationStore.setTableColumns('tableInsurance')({
|
|
||||||
options: { ...insuranceCompanies },
|
|
||||||
});
|
|
||||||
|
|
||||||
const supplierCurrency = CalculationStore.options.selectSupplierCurrency?.find(
|
Promise.all([
|
||||||
x => x.isocurrencycode === 'RUB',
|
CrmService.crmgqlquery({
|
||||||
);
|
...initialOwnerQuery,
|
||||||
if (supplierCurrency)
|
variables: {
|
||||||
CalculationStore.setValue(
|
statecode: 0,
|
||||||
'supplierCurrency',
|
fullName: FullName,
|
||||||
supplierCurrency.transactioncurrencyid,
|
},
|
||||||
);
|
}),
|
||||||
|
CrmService.crmgqlquery(optionsQuery),
|
||||||
const evo_sot_coefficient_type = staticEntities.evo_sot_coefficient_type.find(
|
CrmService.crmgqlquery(staticDataQuery),
|
||||||
x => x.evo_id === 'BONUS_LEASING',
|
CrmService.crmgqlquery({
|
||||||
);
|
...systemUserQuery,
|
||||||
|
variables: { username: `${DomainName}\\${UserName}` },
|
||||||
const evo_coefficient_bonus = staticEntities.evo_coefficient.find(
|
}),
|
||||||
x =>
|
CrmService.crmgqlquery(insuranceQuery),
|
||||||
x.evo_job_titleid === systemuser.evo_job_titleid &&
|
])
|
||||||
x.evo_sot_coefficient_typeid ===
|
.then(
|
||||||
evo_sot_coefficient_type?.evo_sot_coefficient_typeid,
|
([
|
||||||
);
|
{ entities: ownerOptions },
|
||||||
|
{ entities: initialOptions },
|
||||||
if (
|
{ entities: staticEntities },
|
||||||
evo_coefficient_bonus &&
|
{
|
||||||
evo_coefficient_bonus.evo_sot_coefficient
|
entities: { systemuser },
|
||||||
) {
|
},
|
||||||
CalculationStore.setValue(
|
{ entities: insuranceCompanies },
|
||||||
'saleBonus',
|
]) => {
|
||||||
evo_coefficient_bonus.evo_sot_coefficient * 100,
|
CalculationStore.applyOptions(ownerOptions);
|
||||||
);
|
CalculationStore.applyOptions(initialOptions);
|
||||||
}
|
CalculationStore.applyStaticData(staticEntities);
|
||||||
|
CalculationStore.applyStaticData({ systemuser: [systemuser] });
|
||||||
resolve();
|
CalculationStore.setTableColumns('tableInsurance')({
|
||||||
},
|
options: { ...insuranceCompanies },
|
||||||
)
|
|
||||||
.catch(err => {
|
|
||||||
reject(err);
|
|
||||||
throw err;
|
|
||||||
});
|
});
|
||||||
})
|
|
||||||
|
const supplierCurrency = CalculationStore.options.selectSupplierCurrency?.find(
|
||||||
|
x => x.isocurrencycode === 'RUB',
|
||||||
|
);
|
||||||
|
if (supplierCurrency)
|
||||||
|
CalculationStore.setValue(
|
||||||
|
'supplierCurrency',
|
||||||
|
supplierCurrency.transactioncurrencyid,
|
||||||
|
);
|
||||||
|
|
||||||
|
const evo_sot_coefficient_type = staticEntities.evo_sot_coefficient_type.find(
|
||||||
|
x => x.evo_id === 'BONUS_LEASING',
|
||||||
|
);
|
||||||
|
|
||||||
|
const evo_coefficient_bonus = staticEntities.evo_coefficient.find(
|
||||||
|
x =>
|
||||||
|
x.evo_job_titleid === systemuser.evo_job_titleid &&
|
||||||
|
x.evo_sot_coefficient_typeid ===
|
||||||
|
evo_sot_coefficient_type?.evo_sot_coefficient_typeid,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
evo_coefficient_bonus &&
|
||||||
|
evo_coefficient_bonus.evo_sot_coefficient
|
||||||
|
) {
|
||||||
|
CalculationStore.setValue(
|
||||||
|
'saleBonus',
|
||||||
|
evo_coefficient_bonus.evo_sot_coefficient * 100,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
reject(err);
|
reject(err);
|
||||||
throw err;
|
throw err;
|
||||||
|
|||||||
@ -1,26 +1,26 @@
|
|||||||
import CalculationService from 'client/services/CalculationService';
|
|
||||||
import { User } from 'core/types/user';
|
import { User } from 'core/types/user';
|
||||||
import { domainName } from 'core/constants/domain';
|
import Cookies from 'js-cookie';
|
||||||
|
|
||||||
|
function getUserObj(user: User) {
|
||||||
|
return {
|
||||||
|
...user,
|
||||||
|
fullname: `${user.domainname}\\${user.username}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getUser = (): User => {
|
||||||
|
const { username, domainname } = Cookies.get();
|
||||||
|
|
||||||
export const getUser = async (): Promise<User> => {
|
|
||||||
function getFullName(user: User) {
|
|
||||||
return `${user.DomainName}\\${user.UserName}`;
|
|
||||||
}
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
const savedUser = localStorage.getItem('user');
|
if (!username || !domainname) {
|
||||||
if (savedUser) {
|
const username = prompt('Enter username');
|
||||||
const user = JSON.parse(savedUser);
|
const domainname = prompt('Enter domainname');
|
||||||
if (user.UserName) {
|
if (username && domainname) {
|
||||||
return { ...user, FullName: getFullName(user) };
|
Cookies.set('username', username);
|
||||||
|
Cookies.set('domainname', domainname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var username = prompt('Enter username');
|
|
||||||
const user: User = { UserName: username || '', DomainName: domainName };
|
|
||||||
localStorage.setItem('user', JSON.stringify(user));
|
|
||||||
return { ...user, FullName: getFullName(user) };
|
|
||||||
}
|
}
|
||||||
|
const user: User = getUserObj({ username, domainname });
|
||||||
const { user } = await CalculationService.getUser();
|
return user;
|
||||||
localStorage.setItem('user', JSON.stringify(user));
|
|
||||||
return { ...user, FullName: getFullName(user) };
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
export type User = {
|
export type User = {
|
||||||
DomainName?: string;
|
domainname?: string;
|
||||||
UserName?: string;
|
username?: string;
|
||||||
FullName?: string;
|
fullname?: string;
|
||||||
Workstation?: string;
|
|
||||||
Authenticated?: boolean;
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user