Skip to content

Commit

Permalink
fix(hub-common): add CRUD functions for entity settings (#1275)
Browse files Browse the repository at this point in the history
* fix(hub-common): add CRUD functions for entity settings

affects: @esri/hub-common

* fix(hub-common): rename setting interfaces

affects: @esri/hub-common, @esri/hub-discussions

* fix(hub-discussions): export updated setting interfaces from hub-common

affects: @esri/hub-discussions
  • Loading branch information
velveetachef authored Oct 12, 2023
1 parent 6969758 commit 8eabc30
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 82 deletions.
1 change: 1 addition & 0 deletions packages/common/src/discussions/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./channels";
export * from "./settings";
export * from "./types";
1 change: 1 addition & 0 deletions packages/common/src/discussions/api/settings/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./settings";
65 changes: 65 additions & 0 deletions packages/common/src/discussions/api/settings/settings.ts
Original file line number Diff line number Diff line change
@@ -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<IEntitySetting>}
*/
export function createSetting(
options: ICreateSettingParams
): Promise<IEntitySetting> {
options.httpMethod = "POST";
return request(`/settings`, options);
}

/**
* fetch setting
*
* @export
* @param {IFetchSettingParams} options
* @return {*} {Promise<IEntitySetting>}
*/
export function fetchSetting(
options: IFetchSettingParams
): Promise<IEntitySetting> {
options.httpMethod = "GET";
return request(`/settings/${options.id}`, options);
}

/**
* update setting
*
* @export
* @param {IUpdateSettingParams} options
* @return {*} {Promise<IEntitySetting>}
*/
export function updateSetting(
options: IUpdateSettingParams
): Promise<IEntitySetting> {
options.httpMethod = "PATCH";
return request(`/settings/${options.id}`, options);
}

/**
* remove setting
*
* @export
* @param {IRemoveSettingParams} options
* @return {*} {Promise<IRemoveSettingResponse>}
*/
export function removeSetting(
options: IRemoveSettingParams
): Promise<IRemoveSettingResponse> {
options.httpMethod = "DELETE";
return request(`/settings/${options.id}`, options);
}
25 changes: 14 additions & 11 deletions packages/common/src/discussions/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -1076,16 +1079,16 @@ export interface IRemoveSettingResponse {
*/
export interface ICreateSetting {
id: string;
type: SettingType;
settings: IContentSettings;
type: EntitySettingType;
settings: IEntityContentSettings;
}

/**
* @export
* @interface IUpdateSetting
*/
export interface IUpdateSetting {
settings: Partial<IContentSettings>;
settings: Partial<IEntityContentSettings>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
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,
IRemoveSettingParams,
IUpdateSetting,
IUpdateSettingParams,
IFetchSettingParams,
} from "../src/types";
} from "../../../src/discussions/api/types";

describe("settings", () => {
let requestSpy: any;
Expand All @@ -33,7 +33,7 @@ describe("settings", () => {
it("createSetting", async () => {
const body: ICreateSetting = {
id: "uuidv4",
type: SettingType.CONTENT,
type: EntitySettingType.CONTENT,
settings: {
discussions: {
allowedChannelIds: ["aaa"],
Expand Down
69 changes: 6 additions & 63 deletions packages/discussions/src/settings/settings.ts
Original file line number Diff line number Diff line change
@@ -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<ISetting>}
*/
export function createSetting(
options: ICreateSettingParams
): Promise<ISetting> {
options.httpMethod = "POST";
return request(`/settings`, options);
}

/**
* fetch setting
*
* @export
* @param {IFetchSettingParams} options
* @return {*} {Promise<ISetting>}
*/
export function fetchSetting(options: IFetchSettingParams): Promise<ISetting> {
options.httpMethod = "GET";
return request(`/settings/${options.id}`, options);
}

/**
* update setting
*
* @export
* @param {IUpdateSettingParams} options
* @return {*} {Promise<ISetting>}
*/
export function updateSetting(
options: IUpdateSettingParams
): Promise<ISetting> {
options.httpMethod = "PATCH";
return request(`/settings/${options.id}`, options);
}

/**
* remove setting
*
* @export
* @param {IRemoveSettingParams} options
* @return {*} {Promise<IRemoveSettingResponse>}
*/
export function removeSetting(
options: IRemoveSettingParams
): Promise<IRemoveSettingResponse> {
options.httpMethod = "DELETE";
return request(`/settings/${options.id}`, options);
}
export {
createSetting,
fetchSetting,
updateSetting,
removeSetting,
} from "@esri/hub-common";
6 changes: 3 additions & 3 deletions packages/discussions/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export {
ICreateChannelNotificationOptOutParams,
IRemoveChannelNotificationOptOutParams,
IRemoveChannelActivityParams,
ISetting,
SettingType,
IContentSettings,
IEntitySetting,
EntitySettingType,
IEntityContentSettings,
IDiscussionsSettings,
IRemoveSettingResponse,
ICreateSetting,
Expand Down

0 comments on commit 8eabc30

Please sign in to comment.