66 lines
1.4 KiB
TypeScript
66 lines
1.4 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 getVisibility(): string {
|
|
return this.tagData.visibility;
|
|
}
|
|
|
|
public isInternal(): boolean {
|
|
return this.tagData.visibility === 'internal';
|
|
}
|
|
|
|
public isPublic(): boolean {
|
|
return this.tagData.visibility === 'public';
|
|
}
|
|
|
|
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) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
public async delete(): Promise<void> {
|
|
try {
|
|
await this.ghostInstanceRef.adminApi.tags.delete({ id: this.getId() });
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
}
|