Skip to content

Commit

Permalink
Merge pull request #10 from mathewmeconry/feature/issue_bill
Browse files Browse the repository at this point in the history
adds the endpoints to issue a bill
  • Loading branch information
mathewmeconry authored Jul 22, 2019
2 parents 0eb6886 + 2a63a8a commit ede77b5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/resources/BaseCrud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import OAuth2 from "../libs/OAuth2";
import request from "request-promise-native";

export default class BaseCrud<Small, Full, Search, SearchType, Create, Overwrite> {
private bexioAuth: OAuth2;
private apiEndpoint: string;
private showScope: Scopes;
private editScope: Scopes;
protected bexioAuth: OAuth2;
protected apiEndpoint: string;
protected showScope: Scopes;
protected editScope: Scopes;

constructor(
bexioAuth: OAuth2,
Expand Down
39 changes: 38 additions & 1 deletion src/resources/Bills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BillsStatic } from "./../interfaces/BillsStatic";
import BaseCrud from "./BaseCrud";
import OAuth2 from "../libs/OAuth2";
import Scopes from "../constants/Scopes";
import { BaseStatic } from "../interfaces/BaseStatic";

export default class Bills extends BaseCrud<
BillsStatic.Bill,
Expand All @@ -10,8 +11,44 @@ export default class Bills extends BaseCrud<
BillsStatic.SearchParameters,
BillsStatic.BillCreate,
BillsStatic.BillOverwrite
> {
> {
constructor(bexioAuth: OAuth2) {
super(bexioAuth, "/kb_bill", Scopes.KB_BILL_SHOW, Scopes.KB_BILL_EDIT);
}

/**
* issue a bill
*
* @param {number} id
* @returns {Promise<{ success: boolean }>}
* @memberof Bills
*/
public async issue(
id: number
): Promise<{ success: boolean }> {
this.checkScope(this.showScope);
return this.request<{ success: boolean }>(
"POST",
`${this.apiEndpoint}/${id.toString()}/issue`,
{}
);
}

/**
* revert a bill issue
*
* @param {number} id
* @returns {Promise<{ success: boolean }>}
* @memberof Bills
*/
public async revertIssue(
id: number
): Promise<{ success: boolean }> {
this.checkScope(this.showScope);
return this.request<{ success: boolean }>(
"POST",
`${this.apiEndpoint}/${id.toString()}/revert_issue`,
{}
);
}
}
10 changes: 10 additions & 0 deletions src/tests/Bills.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ describe("Bills", function() {
expect(edited.title).to.be.eq(`edit-${bill.title}`);
});

it("issue bill", async () => {
const result = await moduleToTest.issue(bill.id);
expect(result.success).to.be.true;
});

it("revert issue bill", async () => {
const result = await moduleToTest.revertIssue(bill.id);
expect(result.success).to.be.true;
});

it("delete bill", async () => {
const result = await moduleToTest.delete(bill.id);
expect(result).to.be.true;
Expand Down

0 comments on commit ede77b5

Please sign in to comment.