33 lines
1.4 KiB
TypeScript
33 lines
1.4 KiB
TypeScript
import { CrudClient } from "../infra/crud-client"
|
|
import { type ApiClientOptions } from "../infra/client"
|
|
import type { ApiPath, ApiRequestBody } from "../infra/types"
|
|
|
|
export const SERVICE_GROUP_ROUTES = {
|
|
INDEX: "/api/service-groups",
|
|
BY_ID: "/api/service-groups/{id}",
|
|
TOGGLE_STATUS: "/api/service-groups/{id}/toggle-status",
|
|
ADD_LABEL: "/api/service-groups/{id}/add-label",
|
|
DELETE_LABEL: "/api/service-groups/{id}/delete-label",
|
|
} as const satisfies Record<string, ApiPath>
|
|
|
|
export class ServiceGroupsClient extends CrudClient<
|
|
typeof SERVICE_GROUP_ROUTES.INDEX,
|
|
typeof SERVICE_GROUP_ROUTES.BY_ID
|
|
> {
|
|
constructor(baseUrl?: string, defaultOptions?: ApiClientOptions) {
|
|
super(baseUrl, defaultOptions, SERVICE_GROUP_ROUTES.INDEX, SERVICE_GROUP_ROUTES.BY_ID)
|
|
}
|
|
|
|
async toggleStatus(id: string) {
|
|
return this.post(SERVICE_GROUP_ROUTES.TOGGLE_STATUS, {} as never, { params: { id } } as never)
|
|
}
|
|
|
|
async addLabel(id: string, payload: ApiRequestBody<typeof SERVICE_GROUP_ROUTES.ADD_LABEL, "post">) {
|
|
return this.post(SERVICE_GROUP_ROUTES.ADD_LABEL, payload, { params: { id } } as never)
|
|
}
|
|
|
|
async deleteLabel(id: string, payload: ApiRequestBody<typeof SERVICE_GROUP_ROUTES.DELETE_LABEL, "delete">) {
|
|
return this.delete(SERVICE_GROUP_ROUTES.DELETE_LABEL, { params: { id }, body: payload } as never)
|
|
}
|
|
}
|