Untitled

mail@pastecode.io avatar
unknown
typescript
23 days ago
1.3 kB
7
Indexable
Never
import { User } from "../models/user";
import { getResourceMeta } from "@server/meta/fd-meta/services/metas";
import { db } from "@server/ks-app/db/db";
import { ODataConfig } from "@server/fd/fd-toolbox/api/odata/odata-config";
import { ODataComparisonType, ODataFilterType } from "@server/fd/fd-toolbox/api/odata/odata-enums";
import { dbSelect, dbSort, dbSkip, dbTake } from "@server/fd/fd-toolbox/api/odata/odata";

export async function getUser(userName: string): Promise<User | undefined> {
    const resourceMeta = getResourceMeta('User');
    
    const oDataConfig: ODataConfig = {
        Filters: [
            {
                Type: ODataFilterType.Default,
                ComparisonType: ODataComparisonType.Equal,
                LeftSide: 'userName',
                RightSide: userName,
                LogicalOperationType: 0
            }
        ],
        Sorts: [],
        Expands: [],
        Selects: {},
        Skip: 0,
        Top: 1
    };

    let query = dbSelect(db, oDataConfig, 'User');
    query = dbSort(db, query, oDataConfig, 'User');
    query = dbSkip(query, oDataConfig.Skip || 0);
    query = dbTake(query, oDataConfig.Top || 1);

    const result = await query;
    return result.length > 0 ? result[0] as User : undefined;
}
Leave a Comment