Skip to content

Commit

Permalink
sdk-request: 添加扩充 SDK 和 SDKFetch 对象的机制
Browse files Browse the repository at this point in the history
  • Loading branch information
chuan6 committed Aug 15, 2017
1 parent 736a822 commit 518a8f7
Show file tree
Hide file tree
Showing 20 changed files with 298 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/teambition-sdk-request/src/event/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export function getEventFetch(
return this.get<EventSchema[]>(`events/${eventId}`, query)
}

SDKFetch.prototype.getEvent = getEventFetch

declare module 'teambition-sdk-core/dist/cjs/SDKFetch' {
interface SDKFetch {
getEvent: typeof getEventFetch
}
}

export function getEvent(
this: SDK,
eventId: EventId,
Expand All @@ -32,3 +40,11 @@ export function getEvent(

return token.map(e$ => e$.map(events => events.map(e => new EventGenerator(e))))
}

SDK.prototype.getEvent = getEvent

declare module 'teambition-sdk-core/dist/cjs/SDK' {
interface SDK {
getEvent: typeof getEvent
}
}
16 changes: 16 additions & 0 deletions packages/teambition-sdk-request/src/file/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ export function getFileFetch(
return this.get<FileSchema>(`works/${fileId}`, query)
}

SDKFetch.prototype.getFile = getFileFetch

declare module 'teambition-sdk-core/dist/cjs/SDKFetch' {
interface SDKFetch {
getFile: typeof getFileFetch
}
}

export function getFile (
this: SDK,
fileId: FileId,
Expand All @@ -30,3 +38,11 @@ export function getFile (
excludeFields: ['class']
})
}

SDK.prototype.getFile = getFile

declare module 'teambition-sdk-core/dist/cjs/SDK' {
interface SDK {
getFile: typeof getFile
}
}
16 changes: 16 additions & 0 deletions packages/teambition-sdk-request/src/like/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ export function getLikeFetch (
.map(r => ({ ...r, _id: `${objectId}:like` }))
}

SDKFetch.prototype.getLike = getLikeFetch

declare module 'teambition-sdk-core/dist/cjs/SDKFetch' {
interface SDKFetch {
getLike: typeof getLikeFetch
}
}

export function getLike (
this: SDK,
objectType: DetailObjectType,
Expand All @@ -27,3 +35,11 @@ export function getLike (
}
})
}

SDK.prototype.getLike = getLike

declare module 'teambition-sdk-core/dist/cjs/SDK' {
interface SDK {
getLike: typeof getLike
}
}
16 changes: 16 additions & 0 deletions packages/teambition-sdk-request/src/like/toggleLike.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export function toggleLikeFetch (
})
}

SDKFetch.prototype.toggleLike = toggleLikeFetch

declare module 'teambition-sdk-core/dist/cjs/SDKFetch' {
interface SDKFetch {
toggleLike: typeof toggleLikeFetch
}
}

export function toggleLike (
this: SDK,
objectType: DetailObjectType,
Expand All @@ -30,3 +38,11 @@ export function toggleLike (
clause: { _id: `${objectId}:like` }
})
}

SDK.prototype.toggleLike = toggleLike

declare module 'teambition-sdk-core/dist/cjs/SDK' {
interface SDK {
toggleLike: typeof toggleLike
}
}
16 changes: 16 additions & 0 deletions packages/teambition-sdk-request/src/my/count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,24 @@ export function getMyCountFetch(
return this.get<MyCountData>(`users/me/count`)
}

SDKFetch.prototype.getMyCount = getMyCountFetch

declare module 'teambition-sdk-core/dist/cjs/SDKFetch' {
interface SDKFetch {
getMyCount: typeof getMyCountFetch
}
}

export function getMyCount(
this: SDK
): Observable<MyCountData> {
return this.fetch.getMyCount()
}

SDK.prototype.getMyCount = getMyCount

declare module 'teambition-sdk-core/dist/cjs/SDK' {
interface SDK {
getMyCount: typeof getMyCount
}
}
16 changes: 16 additions & 0 deletions packages/teambition-sdk-request/src/my/recent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export function getMyRecentFetch(
return this.get<RecentData[]>(`users/recent`, query)
}

SDKFetch.prototype.getMyRecent = getMyRecentFetch

declare module 'teambition-sdk-core/dist/cjs/SDKFetch' {
interface SDKFetch {
getMyRecent: typeof getMyRecentFetch
}
}

export type RecentResult = EventGenerator | RecentSubtaskData | RecentTaskData

export function getMyRecent(
Expand Down Expand Up @@ -155,3 +163,11 @@ export function getMyRecent(

return <any>taskToken.combine(eventToken, subtaskToken)
}

SDK.prototype.getMyRecent = getMyRecent

declare module 'teambition-sdk-core/dist/cjs/SDK' {
interface SDK {
getMyRecent: typeof getMyRecent
}
}
18 changes: 18 additions & 0 deletions packages/teambition-sdk-request/src/organization/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,21 @@ export function getUngroupedOrganizationProjects(
): Observable<ProjectSchema> {
return this.get<ProjectSchema>(`organizations/${orgId}/projects/ungrouped`)
}

SDKFetch.prototype.getAllOrganizationProjects = getAllOrganizationProjects
SDKFetch.prototype.getJoinedOrganizationProjects = getJoinedOrganizationProjects
SDKFetch.prototype.getPublicOrganizationProjects = getPublicOrganizationProjects
SDKFetch.prototype.getStarredOrganizationProjects = getStarredOrganizationProjects
SDKFetch.prototype.getOrganizationProjectsByTagId = getOrganizationProjectsByTagId
SDKFetch.prototype.getUngroupedOrganizationProjects = getUngroupedOrganizationProjects

declare module 'teambition-sdk-core/dist/cjs/SDKFetch' {
interface SDKFetch {
getAllOrganizationProjects: typeof getAllOrganizationProjects,
getJoinedOrganizationProjects: typeof getJoinedOrganizationProjects,
getPublicOrganizationProjects: typeof getPublicOrganizationProjects,
getStarredOrganizationProjects: typeof getStarredOrganizationProjects,
getOrganizationProjectsByTagId: typeof getOrganizationProjectsByTagId,
getUngroupedOrganizationProjects: typeof getUngroupedOrganizationProjects
}
}
16 changes: 16 additions & 0 deletions packages/teambition-sdk-request/src/post/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,26 @@ export function createPostFetch(this: SDKFetch, options: CreatePostOptions): Obs
return this.post<PostSchema>('posts', options)
}

SDKFetch.prototype.createPost = createPostFetch

declare module 'teambition-sdk-core/dist/cjs/SDKFetch' {
export interface SDKFetch {
createPost: typeof createPostFetch
}
}

export function createPost (this: SDK, options: CreatePostOptions): Observable<PostSchema> {
return this.lift({
request: this.fetch.createPost(options),
tableName: 'Post',
method: 'create'
})
}

SDK.prototype.createPost = createPost

declare module 'teambition-sdk-core/dist/cjs/SDK' {
export interface SDK {
createPost: typeof createPost
}
}
16 changes: 16 additions & 0 deletions packages/teambition-sdk-request/src/post/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ export function deletePostFetch (
return this.delete<void>(`posts/delete/${_postId}`)
}

SDKFetch.prototype.deletePost = deletePostFetch

declare module 'teambition-sdk-core/dist/cjs/SDKFetch' {
interface SDKFetch {
deletePost: typeof deletePostFetch
}
}

export function deletePost(
this: SDK,
postId: PostId
Expand All @@ -20,3 +28,11 @@ export function deletePost(
clause: { _id: postId }
})
}

SDK.prototype.deletePost = deletePost

declare module 'teambition-sdk-core/dist/cjs/SDK' {
interface SDK {
deletePost: typeof deletePost
}
}
16 changes: 16 additions & 0 deletions packages/teambition-sdk-request/src/post/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ export function getPostFetch(
return this.get<PostSchema>(`posts/${postId}`, query)
}

SDKFetch.prototype.getPost = getPostFetch

declare module 'teambition-sdk-core/dist/cjs/SDKFetch' {
interface SDKFetch {
getPost: typeof getPostFetch
}
}

export function getPost (
this: SDK,
postId: PostId,
Expand All @@ -29,3 +37,11 @@ export function getPost (
}
})
}

SDK.prototype.getPost = getPost

declare module 'teambition-sdk-core/dist/cjs/SDK' {
interface SDK {
getPost: typeof getPost
}
}
16 changes: 16 additions & 0 deletions packages/teambition-sdk-request/src/post/getByTagId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ export function getByTagIdFetch(
return this.get<PostSchema[]>(`tags/${tagId}/posts`, query)
}

SDKFetch.prototype.getPostsByTagId = getByTagIdFetch

declare module 'teambition-sdk-core/dist/cjs/SDKFetch' {
interface SDKFetch {
getPostsByTagId: typeof getByTagIdFetch
}
}

export function getByTagId (
this: SDK,
tagId: TagId,
Expand Down Expand Up @@ -56,3 +64,11 @@ export function getByTagId (
excludeFields: [ 'isFavorite', 'lastCommentedAt', 'objectlinksCount', 'likesCount', 'shareStatus' ]
})
}

SDK.prototype.getPostsByTagId = getByTagId

declare module 'teambition-sdk-core/dist/cjs/SDK' {
export interface SDK {
getPostsByTagId: typeof getByTagId
}
}
8 changes: 8 additions & 0 deletions packages/teambition-sdk-request/src/post/getMyProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ export function getMyProjectPosts (
}
})
}

SDK.prototype.getMyProjectPosts = getMyProjectPosts

declare module 'teambition-sdk-core/dist/cjs/SDK' {
export interface SDK {
getMyProjectPosts: typeof getMyProjectPosts
}
}
16 changes: 16 additions & 0 deletions packages/teambition-sdk-request/src/post/getProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export function getPostsFetch<T extends ProjectPostType>(
return this.get<PostSchema[]>(`projects/${_projectId}/posts`, query)
}

SDKFetch.prototype.getPosts = getPostsFetch

declare module 'teambition-sdk-core/dist/cjs/SDKFetch' {
interface SDKFetch {
getPosts: typeof getPostsFetch
}
}

export function getAllProjectPosts (
this: SDK,
_projectId: ProjectId,
Expand Down Expand Up @@ -58,3 +66,11 @@ export function getAllProjectPosts (
}
})
}

SDK.prototype.getAllProjectPosts = getAllProjectPosts

declare module 'teambition-sdk-core/dist/cjs/SDK' {
export interface SDK {
getAllProjectPosts: typeof getAllProjectPosts
}
}
16 changes: 16 additions & 0 deletions packages/teambition-sdk-request/src/post/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ export function updatePostFetch(
return this.put<typeof options>(`posts/${_id}`, options)
}

SDKFetch.prototype.updatePost = updatePostFetch

declare module 'teambition-sdk-core/dist/cjs/SDKFetch' {
interface SDKFetch {
updatePost: typeof updatePostFetch
}
}

export function updatePost(
this: SDK,
_id: PostId,
Expand All @@ -31,3 +39,11 @@ export function updatePost(
clause: { _id }
})
}

SDK.prototype.updatePost = updatePost

declare module 'teambition-sdk-core/dist/cjs/SDK' {
interface SDK {
updatePost: typeof updatePost
}
}
8 changes: 8 additions & 0 deletions packages/teambition-sdk-request/src/project/personal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ export function getPersonalProjects(
): Observable<ProjectSchema[]> {
return this.get<ProjectSchema[]>('projects/personal', query)
}

SDKFetch.prototype.getPersonalProjects = getPersonalProjects

declare module 'teambition-sdk-core/dist/cjs/SDKFetch' {
interface SDKFetch {
getPersonalProjects: typeof getPersonalProjects
}
}
16 changes: 16 additions & 0 deletions packages/teambition-sdk-request/src/search/members.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,19 @@ export function searchMembersInGroup(this: SDKFetch, groupId: GroupId, searchStr
export function searchMembers(this: SDKFetch, searchString: string): Observable<MembersSearchResponse> {
return fetch.call(this, {}, searchString)
}

SDKFetch.prototype.searchMembersInTeam = searchMembersInTeam
SDKFetch.prototype.searchMembersInProject = searchMembersInProject
SDKFetch.prototype.searchMembersInOrganization = searchMembersInOrganization
SDKFetch.prototype.searchMembersInGroup = searchMembersInGroup
SDKFetch.prototype.searchMembers = searchMembers

declare module 'teambition-sdk-core/dist/cjs/SDKFetch' {
interface SDKFetch {
searchMembersInTeam: typeof searchMembersInTeam,
searchMembersInProject: typeof searchMembersInProject,
searchMembersInOrganization: typeof searchMembersInOrganization,
searchMembersInGroup: typeof searchMembersInGroup,
searchMembers: typeof searchMembers
}
}
Loading

0 comments on commit 518a8f7

Please sign in to comment.