Skip to content

Commit

Permalink
fix: add category manager to client and shortcut methods
Browse files Browse the repository at this point in the history
  • Loading branch information
zaida04 committed Aug 13, 2023
1 parent bb9d6dc commit 72f2ba3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/guilded.js/lib/managers/global/CategoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CacheableStructManager } from "./CacheableStructManager";
/**
* Manager for interacting with Catregories on Guilded.
*/
export class CategoryManager extends CacheableStructManager<number, Category> {
export class GlobalCategoryManager extends CacheableStructManager<number, Category> {
/**
* Create a new category
*
Expand Down
43 changes: 43 additions & 0 deletions packages/guilded.js/lib/structures/Category.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import type { CategoryPayload } from "@guildedjs/api";
import type { GlobalCategoryManager } from "../managers/global/CategoryManager";
import { parseToStamp } from "../util";
import { Base } from "./Base";
import type { Client } from "./Client";

export class Category extends Base<CategoryPayload, number> {
/** The ID of the server this category is in. */
serverId: string;

/** The name of this category. */
name!: string;

/** The timestamp of when this category was created. */
_createdAt: number;

/** The ID of the group this category is in. */
groupId: string;

/** The timestamp of when this category was last updated. */
_updatedAt!: number | null;

constructor(client: Client, data: CategoryPayload) {
Expand All @@ -29,4 +35,41 @@ export class Category extends Base<CategoryPayload, number> {

return this;
}

/**
* Gets the creation date of this category.
*
* @returns The creation date of this category.
*/
get createdAt(): Date {
return new Date(this._createdAt);
}

/**
* Gets the last time this category was updated.
*
* @returns The last time this category was updated.
*/
get updatedAt(): Date | null {
return this._updatedAt ? new Date(this._updatedAt) : null;
}

/**
* Updates this webhook with new options
*
* @param options The new options for this webhook
* @returns A promise that resolves with the updated webhook
*/
update(options: Parameters<GlobalCategoryManager["update"]>[2]): Promise<Category | null> {
return this.client.categories.update(this.serverId, this.id, options);
}

/**
* Delete this category.
*
* @returns A Promise that resolves with the updated category.
*/
async delete(): Promise<void> {
return this.client.categories.delete(this.serverId, this.id);
}
}
6 changes: 6 additions & 0 deletions packages/guilded.js/lib/structures/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type TypedEmitter from "typed-emitter";
import type { CacheStructure } from "../cache";
import { ClientGatewayHandler } from "../gateway/ClientGatewayHandler";
import { GlobalCalendarManager } from "../managers/global/CalendarManager";
import { GlobalCategoryManager } from "../managers/global/CategoryManager";
import { GlobalChannelManager } from "../managers/global/ChannelManager";
import { GlobalDocManager } from "../managers/global/DocManager";
import { GlobalForumTopicManager } from "../managers/global/ForumManager";
Expand Down Expand Up @@ -123,6 +124,11 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
*/
calendars = new GlobalCalendarManager(this);

/**
* A manager for categories, used to manage and interact with categories.
*/
categories = new GlobalCategoryManager(this);

/**
* A manager for server subscriptions, used to manage and interact with server subscriptions.
*/
Expand Down

0 comments on commit 72f2ba3

Please sign in to comment.