Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

1.4 KB
Raw Blame
import { http, Result } from "@fider/services/http"
import { Tag } from "@fider/models"

export const createTag = async (name: string, color: string, isPublic: boolean): Promise<Result<Tag>> => {
  return http.post<Tag>(`/api/v1/tags`, { name, color, isPublic }).then(http.event("tag", "create"))
}

export const updateTag = async (slug: string, name: string, color: string, isPublic: boolean): Promise<Result<Tag>> => {
  return http.put<Tag>(`/api/v1/tags/${slug}`, { name, color, isPublic }).then(http.event("tag", "update"))
}

export const deleteTag = async (slug: string): Promise<Result> => {
  return http.delete(`/api/v1/tags/${slug}`).then(http.event("tag", "delete"))
}

export const assignTag = async (slug: string, postNumber: number): Promise<Result> => {
  return http.post(`/api/v1/posts/${postNumber}/tags/${slug}`).then(http.event("tag", "assign"))
}

export const unassignTag = async (slug: string, postNumber: number): Promise<Result> => {
  return http.delete(`/api/v1/posts/${postNumber}/tags/${slug}`).then(http.event("tag", "unassign"))
}

export interface ImportTagsResult {
  created: number
  skipped: number
  errors: string[]
}

export const importTags = async (tags: Array<{ name: string; color: string; isPublic: boolean }>): Promise<Result<ImportTagsResult>> => {
  return http.post<ImportTagsResult>(`/_api/admin/import/tags`, tags).then(http.event("tag", "import"))
}