Skip to content

Commit

Permalink
extra methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ committed Dec 24, 2024
1 parent 8f17409 commit d6338e0
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/reports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,63 @@ export class Reports extends CrowdinApi {
return this.get(url, this.defaultConfig());
}

/**
* @param options optional parameters for the request
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/Reports/operation/api.reports.settings-templates.getMany
*/
listOrganizationReportSettingsTemplates(
options?: ReportsModel.ListOrganizationReportSettingsParams,
): Promise<ResponseList<ReportsModel.OrganizationReportSettings>> {
let url = `${this.url}/reports/settings-templates`;
url = this.addQueryParam(url, 'projectId', options?.projectId);
url = this.addQueryParam(url, 'groupId', options?.groupId);
return this.getList(url, options?.limit, options?.offset);
}

/**
* @param request request body
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/Reports/operation/api.reports.settings-templates.post
*/
addOrganizationReportSettingsTemplate(
request: ReportsModel.AddOrganizationReportSettingsRequest,
): Promise<ResponseObject<ReportsModel.OrganizationReportSettings>> {
const url = `${this.url}/reports/settings-templates`;
return this.post(url, request, this.defaultConfig());
}

/**
* @param reportSettingsTemplateId report settings template identifier
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/Reports/operation/api.reports.settings-templates.get
*/
getOrganizationReportSettingsTemplate(
reportSettingsTemplateId: number,
): Promise<ResponseObject<ReportsModel.OrganizationReportSettings>> {
const url = `${this.url}/reports/settings-templates/${reportSettingsTemplateId}`;
return this.get(url, this.defaultConfig());
}

/**
* @param reportSettingsTemplateId report settings template identifier
* @param request request body
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/Reports/operation/api.reports.settings-templates.patch
*/
editOrganizationReportSettingsTemplate(
reportSettingsTemplateId: number,
request: PatchRequest[],
): Promise<ResponseObject<ReportsModel.OrganizationReportSettings>> {
const url = `${this.url}/reports/settings-templates/${reportSettingsTemplateId}`;
return this.patch(url, request, this.defaultConfig());
}

/**
* @param reportSettingsTemplateId report settings template identifier
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/Reports/operation/api.reports.settings-templates.delete
*/
deleteOrganizationReportSettingsTemplate(reportSettingsTemplateId: number): Promise<void> {
const url = `${this.url}/reports/settings-templates/${reportSettingsTemplateId}`;
return this.delete(url, this.defaultConfig());
}

/**
* @param request request body
* @see https://support.crowdin.com/enterprise/api/#operation/api.reports.post
Expand Down Expand Up @@ -687,6 +744,11 @@ export namespace ReportsModel {
dateTo?: string;
}

export interface ListOrganizationReportSettingsParams extends PaginationOptions {
projectId?: number;
groupId?: number;
}

export interface ReportSettings {
id: number;
name: string;
Expand All @@ -711,6 +773,15 @@ export namespace ReportsModel {
export type UserReportSettings = Omit<ReportSettings, 'isPublic' | 'isGlobal'>;
export type AddUserReportSettingsRequest = Omit<AddReportSettingsRequest, 'isPublic' | 'isGlobal'>;

export type OrganizationReportSettings = Omit<ReportSettings, 'isGlobal'> & {
projectId: number;
groupId: number;
};
export type AddOrganizationReportSettingsRequest = Omit<AddReportSettingsRequest, 'isGlobal'> & {
projectId?: number;
groupId?: number;
};

export interface ReportSettinsConfig {
baseRates: BaseRate;
netRateSchemes: NetRateSchemas[];
Expand Down
110 changes: 110 additions & 0 deletions tests/reports/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,79 @@ describe('Reports API', () => {
url: downloadLink,
},
})
.get('/reports/settings-templates', undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: [
{
data: {
id: reportSettingsTemplateId,
},
},
],
pagination: {
offset: 0,
limit: 1,
},
})
.post(
'/reports/settings-templates',
{
name: reportName,
currency,
unit,
config,
},
{
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
},
)
.reply(200, {
data: {
id: reportSettingsTemplateId,
},
})
.get(`/reports/settings-templates/${reportSettingsTemplateId}`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: {
id: reportSettingsTemplateId,
},
})
.patch(
`/reports/settings-templates/${reportSettingsTemplateId}`,
[
{
value: reportName,
op: 'replace',
path: '/name',
},
],
{
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
},
)
.reply(200, {
data: {
id: reportSettingsTemplateId,
},
})
.delete(`/reports/settings-templates/${reportSettingsTemplateId}`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200)
.post(
'/reports',
{
Expand Down Expand Up @@ -517,6 +590,43 @@ describe('Reports API', () => {
expect(downloadUrl.data.url).toBe(downloadLink);
});

it('List Organization Report Settings Templates', async () => {
const templates = await api.listOrganizationReportSettingsTemplates();
expect(templates.data.length).toBe(1);
expect(templates.data[0].data.id).toBe(reportSettingsTemplateId);
expect(templates.pagination.limit).toBe(1);
});

it('Add Organization Report Settings Template', async () => {
const template = await api.addOrganizationReportSettingsTemplate({
config,
currency,
name: reportName,
unit,
});
expect(template.data.id).toBe(reportSettingsTemplateId);
});

it('Get Organization Report Settings Template', async () => {
const template = await api.getOrganizationReportSettingsTemplate(reportSettingsTemplateId);
expect(template.data.id).toBe(reportSettingsTemplateId);
});

it('Edit Organization Report Settings Template', async () => {
const template = await api.editOrganizationReportSettingsTemplate(reportSettingsTemplateId, [
{
op: 'replace',
path: '/name',
value: reportName,
},
]);
expect(template.data.id).toBe(reportSettingsTemplateId);
});

it('Delete Organization Report Settings Template', async () => {
await api.deleteOrganizationReportSettingsTemplate(reportSettingsTemplateId);
});

it('Generate Organization Report', async () => {
const report = await api.generateOrganizationReport({
name: reportName,
Expand Down

0 comments on commit d6338e0

Please sign in to comment.