// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import type ClientBase from './base'; export interface ClientPropertiesMix { getPropertyValues: (groupName: string, objectType: string, targetId: string, groupLabel?: RequestGroupLabel) => Promise>>; getPropertyFields: (groupName: string, objectType: string, targetType: string, targetId?: string, groupLabel?: RequestGroupLabel) => Promise; getSystemPropertyValues: (groupName: string, groupLabel?: RequestGroupLabel) => Promise>>; } const ClientProperties = >(superclass: TBase) => class extends superclass { getPropertyValues = async (groupName: string, objectType: string, targetId: string, groupLabel?: RequestGroupLabel) => { const url = `${this.urlVersion}/properties/groups/${groupName}/${objectType}/values/${targetId}`; return this.doFetch( url, {method: 'get', groupLabel}, ) as unknown as Promise>>; }; getPropertyFields = async (groupName: string, objectType: string, targetType: string, targetId?: string, groupLabel?: RequestGroupLabel) => { let url = `${this.urlVersion}/properties/groups/${groupName}/${objectType}/fields?target_type=${targetType}`; if (targetId !== undefined) { url += `&target_id=${encodeURIComponent(targetId)}`; } return this.doFetch( url, {method: 'get', groupLabel}, ) as unknown as Promise; }; getSystemPropertyValues = async (groupName: string, groupLabel?: RequestGroupLabel) => { const url = `${this.urlVersion}/properties/groups/${groupName}/system/values`; return this.doFetch( url, {method: 'get', groupLabel}, ) as unknown as Promise>>; }; }; export default ClientProperties;