Skip to content

Commit

Permalink
fix: ResourceAwardEmojis API wasn't properly filtering based on awardId
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalrymple committed May 25, 2019
1 parent 3f6d409 commit a7b29c1
Showing 1 changed file with 44 additions and 29 deletions.
73 changes: 44 additions & 29 deletions src/templates/ResourceAwardEmojis.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,79 @@
import URLJoin from 'url-join';
import { BaseService, RequestHelper } from '../infrastructure';
import { BaseModelContructorOptions } from '../infrastructure/BaseService';
import { RequestOptions } from '../infrastructure/RequestHelper';

function url(
projectId: ProjectId,
resourceType: ResourceType,
resourceId: ResourceId,
noteId: NoteId,
) {
function url(projectId, resourceType, resourceId, awardId, noteId) {
const [pId, rId] = [projectId, resourceId].map(encodeURIComponent);
let output = `${pId}/${resourceType}/${rId}/`;
const output = [pId, resourceType, rId];

if (noteId) {
output += `notes/${encodeURIComponent(noteId)}/`;
}
if (noteId) output.push('notes', encodeURIComponent(noteId));

output.push(encodeURIComponent('award_emoji'));

output += 'award_emoji';
if (awardId) output.push(encodeURIComponent(awardId));

return output;
return output.join('/');
}

class ResourceAwardsEmojis extends BaseService {
protected resourceType: temporaryAny;
protected resourceType: string;

constructor(resourceType: string, baseParams: BaseModelContructorOptions) {
super(baseParams);
constructor(resourceType: string, options: BaseServiceOptions) {
super({ url: 'projects', ...options });

this.url = URLJoin(this.url, 'projects');
this.resourceType = resourceType;
}

all(projectId: ProjectId, resourceId: ResourceId, options: RequestOptions, noteId: NoteId) {
return RequestHelper.get(this, url(projectId, this.resourceType, resourceId, noteId), options);
all(
projectId: ProjectId,
resourceId: ResourceId,
noteId: NoteId,
options?: PaginatedRequestOptions,
) {
return RequestHelper.get(
this,
url(projectId, this.resourceType, resourceId, null, noteId),
options,
);
}

award(projectId: ProjectId, resourceId: ResourceId, name: string, noteId: NoteId) {
return RequestHelper.post(this, url(projectId, this.resourceType, resourceId, noteId), {
award(
projectId: ProjectId,
resourceId: ResourceId,
name: string,
noteId: NoteId,
options?: Sudo,
) {
return RequestHelper.post(this, url(projectId, this.resourceType, resourceId, null, noteId), {
name,
...options,
});
}

remove(
projectId: ProjectId,
resourceId: ResourceId,
// @ts-ignore 'awardId' is declared but its value is never read
awardId: string | number,
awardId: AwardId,
noteId: NoteId,
options?: Sudo,
) {
return RequestHelper.delete(this, url(projectId, this.resourceType, resourceId, noteId));
return RequestHelper.del(
this,
url(projectId, this.resourceType, resourceId, awardId, noteId),
options,
);
}

show(
projectId: ProjectId,
resourceId: ResourceId,
// @ts-ignore 'awardId' is declared but its value is never read
awardId: string | number,
awardId: AwardId,
noteId: NoteId,
options?: Sudo,
) {
return RequestHelper.get(this, url(projectId, this.resourceType, resourceId, noteId));
return RequestHelper.get(
this,
url(projectId, this.resourceType, resourceId, awardId, noteId),
options,
);
}
}

Expand Down

0 comments on commit a7b29c1

Please sign in to comment.