feat(ghost): Implement Tag, Author and Page models; add advanced filtering, search, bulk operations, image upload, related-posts, update tests and bump dependencies
This commit is contained in:
55
ts/classes.tag.ts
Normal file
55
ts/classes.tag.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user