UNPKG

@capawesome/cli

Version:

The Capawesome Cloud Command Line Interface (CLI) to manage Live Updates and more.

72 lines (71 loc) 2.6 kB
import httpClient from '../utils/http-client.js'; import authorizationService from '../services/authorization-service.js'; class AppChannelsServiceImpl { httpClient; constructor(httpClient) { this.httpClient = httpClient; } async create(dto) { const response = await this.httpClient.post(`/v1/apps/${dto.appId}/channels`, dto, { headers: { Authorization: `Bearer ${authorizationService.getCurrentAuthorizationToken()}`, }, }); return response.data; } async delete(data) { if (data.id) { await this.httpClient.delete(`/v1/apps/${data.appId}/channels/${data.id}`, { headers: { Authorization: `Bearer ${authorizationService.getCurrentAuthorizationToken()}`, }, }); } else if (data.name) { await this.httpClient.delete(`/v1/apps/${data.appId}/channels`, { headers: { Authorization: `Bearer ${authorizationService.getCurrentAuthorizationToken()}`, }, params: { name: data.name, }, }); } } async findAll(dto) { const queryParams = new URLSearchParams(); if (dto.limit) { queryParams.append('limit', dto.limit.toString()); } if (dto.name) { queryParams.append('name', dto.name); } if (dto.offset) { queryParams.append('offset', dto.offset.toString()); } const response = await this.httpClient.get(`/v1/apps/${dto.appId}/channels?${queryParams}`, { headers: { Authorization: `Bearer ${authorizationService.getCurrentAuthorizationToken()}`, }, }); return response.data; } async findOneById(data) { const response = await this.httpClient.get(`/v1/apps/${data.appId}/channels/${data.id}`, { headers: { Authorization: `Bearer ${authorizationService.getCurrentAuthorizationToken()}`, }, }); return response.data; } async update(dto) { const response = await this.httpClient.patch(`/v1/apps/${dto.appId}/channels/${dto.appChannelId}`, dto, { headers: { Authorization: `Bearer ${authorizationService.getCurrentAuthorizationToken()}`, }, }); return response.data; } } const appChannelsService = new AppChannelsServiceImpl(httpClient); export default appChannelsService;