Files
ghost/ts/classes.tag.ts

56 lines
1.2 KiB
TypeScript

import type { Ghost } from './classes.ghost.js';
import type { ITag } from './classes.post.js';
export class Tag {
public ghostInstanceRef: Ghost;
public tagData: ITag;
constructor(ghostInstanceRefArg: Ghost, tagData: ITag) {
this.ghostInstanceRef = ghostInstanceRefArg;
this.tagData = tagData;
}
public getId(): string {
return this.tagData.id;
}
public getName(): string {
return this.tagData.name;
}
public getSlug(): string {
return this.tagData.slug;
}
public getDescription(): string | undefined {
return this.tagData.description;
}
public toJson(): ITag {
return this.tagData;
}
public async update(tagData: Partial<ITag>): Promise<Tag> {
try {
const updatedTagData = await this.ghostInstanceRef.adminApi.tags.edit({
...tagData,
id: this.getId()
});
this.tagData = updatedTagData;
return this;
} catch (error) {
console.error('Error updating tag:', error);
throw error;
}
}
public async delete(): Promise<void> {
try {
await this.ghostInstanceRef.adminApi.tags.delete({ id: this.getId() });
} catch (error) {
console.error(`Error deleting tag with id ${this.getId()}:`, error);
throw error;
}
}
}