Skip to content

Commit

Permalink
ran linter
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Sep 25, 2024
1 parent 2146a83 commit 55b1a19
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 61 deletions.
44 changes: 21 additions & 23 deletions addon/services/current-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,31 @@ export default class CurrentUserService extends Service.extend(Evented) {
@alias('user.company_uuid') companyId;
@alias('user.company_name') companyName;

@computed('id') get optionsPrefix() {
@computed('id') get optionsPrefix () {
return `${this.id}:`;
}

get latitude() {
get latitude () {
return this.whois('latitude');
}

get longitude() {
get longitude () {
return this.whois('longitude');
}

get currency() {
get currency () {
return this.whois('currency.code');
}

get city() {
get city () {
return this.whois('city');
}

get country() {
get country () {
return this.whois('country_code');
}

async load() {
async load () {
if (this.session.isAuthenticated) {
const user = await this.store.findRecord('user', 'me');
this.set('user', user);
Expand All @@ -75,7 +75,7 @@ export default class CurrentUserService extends Service.extend(Evented) {
return null;
}

async promiseUser(options = {}) {
async promiseUser (options = {}) {
const NoUserAuthenticatedError = new Error('Failed to authenticate user.');
if (!this.session.isAuthenticated) {
throw NoUserAuthenticatedError;
Expand All @@ -88,8 +88,6 @@ export default class CurrentUserService extends Service.extend(Evented) {
this.set('user', user);
this.trigger('user.loaded', user);

console.log(user);

// Set permissions
this.permissions = this.getUserPermissions(user);

Expand Down Expand Up @@ -121,13 +119,13 @@ export default class CurrentUserService extends Service.extend(Evented) {
}
}

async loadPreferences() {
async loadPreferences () {
await this.loadLocale();
await this.loadWhois();
await this.loadOrganizations();
}

async loadLocale() {
async loadLocale () {
try {
const { locale } = await this.fetch.get('users/locale');
this.setLocale(locale);
Expand All @@ -138,7 +136,7 @@ export default class CurrentUserService extends Service.extend(Evented) {
}
}

async loadOrganizations() {
async loadOrganizations () {
try {
const organizations = await this.fetch.get('auth/organizations', {}, { normalizeToEmberData: true, normalizeModelType: 'company' });
this.setOption('organizations', organizations);
Expand All @@ -150,7 +148,7 @@ export default class CurrentUserService extends Service.extend(Evented) {
}
}

async loadWhois() {
async loadWhois () {
this.fetch.shouldResetCache();

try {
Expand All @@ -171,12 +169,12 @@ export default class CurrentUserService extends Service.extend(Evented) {
}
}

getCompany() {
getCompany () {
this.company = this.store.peekRecord('company', this.user.company_uuid);
return this.company;
}

getUserPermissions(user) {
getUserPermissions (user) {
const permissions = [];

// get direct applied permissions
Expand Down Expand Up @@ -213,34 +211,34 @@ export default class CurrentUserService extends Service.extend(Evented) {
return permissions;
}

whois(key) {
whois (key) {
return this.getWhoisProperty(key);
}

setLocale(locale) {
setLocale (locale) {
this.setOption('locale', locale);
this.intl.setLocale(locale);
this.locale = locale;

return this;
}

setOption(key, value) {
setOption (key, value) {
key = `${this.optionsPrefix}${dasherize(key)}`;

this.options.set(key, value);

return this;
}

getOption(key, defaultValue = null) {
getOption (key, defaultValue = null) {
key = `${this.optionsPrefix}${dasherize(key)}`;

const value = this.options.get(key);
return value !== undefined ? value : defaultValue;
}

getWhoisProperty(prop) {
getWhoisProperty (prop) {
const whois = this.getOption('whois');

if (!whois || typeof whois !== 'object') {
Expand All @@ -250,11 +248,11 @@ export default class CurrentUserService extends Service.extend(Evented) {
return get(whois, prop);
}

hasOption(key) {
hasOption (key) {
return this.getOption(key) !== undefined;
}

filledOption(key) {
filledOption (key) {
return !isBlank(this.getOption(key));
}
}
Loading

0 comments on commit 55b1a19

Please sign in to comment.