Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions ValueFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { AsyncSeriesEventEmitter } = require('@themost/events');
const { round } = require('@themost/query');
const MD5 = require('crypto-js/md5');
const { DataAttributeResolver } = require('./data-attribute-resolver');
const { firstValueFrom } = require('rxjs');

const testFieldRegex = /^\$\w+(\.\w+)*$/g;

Expand Down Expand Up @@ -166,15 +167,14 @@ class ValueDialect {
* @param {string=} property
* @returns Promise<any>
*/
$user(property) {
async $user(property) {
const selectAttribute = property || 'id';
let name = this.context.user && this.context.user.name;
if (Object.prototype.hasOwnProperty.call(this.context, 'interactiveUser') === true) {
name = this.context.interactiveUser && this.context.interactiveUser.name;
const source$ = this.context.interactiveUser ? this.context.interactiveUser$ : this.context.user$;
const user = await firstValueFrom(source$);
if (user == null) {
return null;
}
return this.context.model('User').asQueryable().where((x, username) => {
return x.name === username && x.name != null && x.name != 'anonymous';
}, name).select(selectAttribute).value();
return getProperty(user, selectAttribute);
}
/**
* A shorthand for $user method
Expand Down
9 changes: 8 additions & 1 deletion data-context.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
// MOST Web Framework 2.0 Codename Blueshift BSD-3-Clause license Copyright (c) 2017-2022, THEMOST LP All rights reserved
import { DataModel } from "data-model";
import {DataAdapter, DataContext} from "./types";
import { DataAdapterBase } from '@themost/common';
import { ConfigurationBase, DataAdapterBase } from '@themost/common';

export declare class DefaultDataContext extends DataContext {
model(name: any): DataModel;
getConfiguration(): ConfigurationBase;
finalize(callback?: (err?: Error) => void): void;
constructor();
readonly name: string;
getDb(): DataAdapterBase;
setDb(db: DataAdapterBase): void;
}

export declare class NamedDataContext extends DataContext {
model(name: any): DataModel;
getConfiguration(): ConfigurationBase;
finalize(callback?: (err?: Error) => void): void;
constructor(name: string);
readonly name: string;
getName(): string
Expand Down
Loading