diff --git a/packages/common/src/discussions/api/index.ts b/packages/common/src/discussions/api/index.ts index b4b9a287a06..05352f05747 100644 --- a/packages/common/src/discussions/api/index.ts +++ b/packages/common/src/discussions/api/index.ts @@ -1,2 +1,3 @@ export * from "./channels"; +export * from "./settings"; export * from "./types"; diff --git a/packages/common/src/discussions/api/settings/index.ts b/packages/common/src/discussions/api/settings/index.ts new file mode 100644 index 00000000000..dcf101b0c62 --- /dev/null +++ b/packages/common/src/discussions/api/settings/index.ts @@ -0,0 +1 @@ +export * from "./settings"; diff --git a/packages/common/src/discussions/api/settings/settings.ts b/packages/common/src/discussions/api/settings/settings.ts new file mode 100644 index 00000000000..17e9e2962ba --- /dev/null +++ b/packages/common/src/discussions/api/settings/settings.ts @@ -0,0 +1,65 @@ +import { request } from "../request"; +import { + ICreateSettingParams, + IEntitySetting, + IFetchSettingParams, + IRemoveSettingParams, + IRemoveSettingResponse, + IUpdateSettingParams, +} from "../types"; + +/** + * create setting + * + * @export + * @param {ICreateSettingParams} options + * @return {*} {Promise} + */ +export function createSetting( + options: ICreateSettingParams +): Promise { + options.httpMethod = "POST"; + return request(`/settings`, options); +} + +/** + * fetch setting + * + * @export + * @param {IFetchSettingParams} options + * @return {*} {Promise} + */ +export function fetchSetting( + options: IFetchSettingParams +): Promise { + options.httpMethod = "GET"; + return request(`/settings/${options.id}`, options); +} + +/** + * update setting + * + * @export + * @param {IUpdateSettingParams} options + * @return {*} {Promise} + */ +export function updateSetting( + options: IUpdateSettingParams +): Promise { + options.httpMethod = "PATCH"; + return request(`/settings/${options.id}`, options); +} + +/** + * remove setting + * + * @export + * @param {IRemoveSettingParams} options + * @return {*} {Promise} + */ +export function removeSetting( + options: IRemoveSettingParams +): Promise { + options.httpMethod = "DELETE"; + return request(`/settings/${options.id}`, options); +} diff --git a/packages/common/src/discussions/api/types.ts b/packages/common/src/discussions/api/types.ts index 5a3ac1623b6..83a2ddb9a78 100644 --- a/packages/common/src/discussions/api/types.ts +++ b/packages/common/src/discussions/api/types.ts @@ -1022,33 +1022,36 @@ export interface IRemoveChannelActivityParams } /** - * representation of a setting record from the service + * representation of an entity setting record from the service * * @export - * @interface ISetting + * @interface IEntitySetting * @extends {IWithAuthor} * @extends {IWithEditor} * @extends {IWithTimestamps} */ -export interface ISetting extends IWithAuthor, IWithEditor, IWithTimestamps { +export interface IEntitySetting + extends IWithAuthor, + IWithEditor, + IWithTimestamps { id: string; - type: SettingType; - settings: IContentSettings; + type: EntitySettingType; + settings: IEntityContentSettings; } /** * @export * @enum {string} */ -export enum SettingType { +export enum EntitySettingType { CONTENT = "content", } /** * @export - * @interface IContentSettings + * @interface IEntityContentSettings */ -export interface IContentSettings { +export interface IEntityContentSettings { discussions?: IDiscussionsSettings; } @@ -1076,8 +1079,8 @@ export interface IRemoveSettingResponse { */ export interface ICreateSetting { id: string; - type: SettingType; - settings: IContentSettings; + type: EntitySettingType; + settings: IEntityContentSettings; } /** @@ -1085,7 +1088,7 @@ export interface ICreateSetting { * @interface IUpdateSetting */ export interface IUpdateSetting { - settings: Partial; + settings: Partial; } /** diff --git a/packages/discussions/test/settings.test.ts b/packages/common/test/discussions/api/settings.test.ts similarity index 92% rename from packages/discussions/test/settings.test.ts rename to packages/common/test/discussions/api/settings.test.ts index 6b1b8062fe1..5eaeb399c69 100644 --- a/packages/discussions/test/settings.test.ts +++ b/packages/common/test/discussions/api/settings.test.ts @@ -1,12 +1,12 @@ -import * as req from "../src/request"; +import * as req from "../../../src/discussions/api/request"; import { createSetting, fetchSetting, removeSetting, updateSetting, -} from "../src/settings"; +} from "../../../src/discussions/api/settings"; import { - SettingType, + EntitySettingType, ICreateSetting, ICreateSettingParams, IDiscussionsRequestOptions, @@ -14,7 +14,7 @@ import { IUpdateSetting, IUpdateSettingParams, IFetchSettingParams, -} from "../src/types"; +} from "../../../src/discussions/api/types"; describe("settings", () => { let requestSpy: any; @@ -33,7 +33,7 @@ describe("settings", () => { it("createSetting", async () => { const body: ICreateSetting = { id: "uuidv4", - type: SettingType.CONTENT, + type: EntitySettingType.CONTENT, settings: { discussions: { allowedChannelIds: ["aaa"], diff --git a/packages/discussions/src/settings/settings.ts b/packages/discussions/src/settings/settings.ts index 1196277a9a2..2af55d72e9c 100644 --- a/packages/discussions/src/settings/settings.ts +++ b/packages/discussions/src/settings/settings.ts @@ -1,63 +1,6 @@ -import { request } from "../request"; -import { - ICreateSettingParams, - ISetting, - IFetchSettingParams, - IRemoveSettingParams, - IRemoveSettingResponse, - IUpdateSettingParams, -} from "../types"; - -/** - * create setting - * - * @export - * @param {ICreateSettingParams} options - * @return {*} {Promise} - */ -export function createSetting( - options: ICreateSettingParams -): Promise { - options.httpMethod = "POST"; - return request(`/settings`, options); -} - -/** - * fetch setting - * - * @export - * @param {IFetchSettingParams} options - * @return {*} {Promise} - */ -export function fetchSetting(options: IFetchSettingParams): Promise { - options.httpMethod = "GET"; - return request(`/settings/${options.id}`, options); -} - -/** - * update setting - * - * @export - * @param {IUpdateSettingParams} options - * @return {*} {Promise} - */ -export function updateSetting( - options: IUpdateSettingParams -): Promise { - options.httpMethod = "PATCH"; - return request(`/settings/${options.id}`, options); -} - -/** - * remove setting - * - * @export - * @param {IRemoveSettingParams} options - * @return {*} {Promise} - */ -export function removeSetting( - options: IRemoveSettingParams -): Promise { - options.httpMethod = "DELETE"; - return request(`/settings/${options.id}`, options); -} +export { + createSetting, + fetchSetting, + updateSetting, + removeSetting, +} from "@esri/hub-common"; diff --git a/packages/discussions/src/types.ts b/packages/discussions/src/types.ts index 865ec71ff2c..e1f709ebf3f 100644 --- a/packages/discussions/src/types.ts +++ b/packages/discussions/src/types.ts @@ -74,9 +74,9 @@ export { ICreateChannelNotificationOptOutParams, IRemoveChannelNotificationOptOutParams, IRemoveChannelActivityParams, - ISetting, - SettingType, - IContentSettings, + IEntitySetting, + EntitySettingType, + IEntityContentSettings, IDiscussionsSettings, IRemoveSettingResponse, ICreateSetting,