get user & domain from cookies
This commit is contained in:
parent
3509bf8007
commit
0b94ad000d
@ -26,6 +26,7 @@
|
||||
"express-ntlm": "^2.5.2",
|
||||
"graphql": "^15.4.0",
|
||||
"helmet": "^4.2.0",
|
||||
"js-cookie": "^2.2.1",
|
||||
"lodash": "^4.17.20",
|
||||
"luxon": "^1.25.0",
|
||||
"mobx": "^6.0.4",
|
||||
|
||||
@ -9,80 +9,75 @@ import systemUserQuery from './queries/systemUserQuery';
|
||||
|
||||
export default () =>
|
||||
new Promise((resolve, reject) => {
|
||||
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 { username: UserName, domainname: DomainName, FullName } = getUser();
|
||||
|
||||
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 => {
|
||||
reject(err);
|
||||
throw err;
|
||||
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(
|
||||
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 => {
|
||||
reject(err);
|
||||
throw err;
|
||||
|
||||
@ -1,26 +1,26 @@
|
||||
import CalculationService from 'client/services/CalculationService';
|
||||
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') {
|
||||
const savedUser = localStorage.getItem('user');
|
||||
if (savedUser) {
|
||||
const user = JSON.parse(savedUser);
|
||||
if (user.UserName) {
|
||||
return { ...user, FullName: getFullName(user) };
|
||||
if (!username || !domainname) {
|
||||
const username = prompt('Enter username');
|
||||
const domainname = prompt('Enter domainname');
|
||||
if (username && domainname) {
|
||||
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 } = await CalculationService.getUser();
|
||||
localStorage.setItem('user', JSON.stringify(user));
|
||||
return { ...user, FullName: getFullName(user) };
|
||||
const user: User = getUserObj({ username, domainname });
|
||||
return user;
|
||||
};
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
export type User = {
|
||||
DomainName?: string;
|
||||
UserName?: string;
|
||||
FullName?: string;
|
||||
Workstation?: string;
|
||||
Authenticated?: boolean;
|
||||
domainname?: string;
|
||||
username?: string;
|
||||
fullname?: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user