feat: add api client for activity controller
This commit is contained in:
@@ -164,6 +164,9 @@ export class NoteController {
|
||||
}
|
||||
|
||||
@Get('like/:id')
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
async likeNote(
|
||||
@Param() param: IntIdOrMongoIdDto,
|
||||
@IpLocation() location: IpRecord,
|
||||
|
||||
@@ -232,6 +232,9 @@ export class PostController {
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@Get('/_thumbs-up')
|
||||
async thumbsUpArticle(
|
||||
@Query() query: MongoIdDto,
|
||||
|
||||
15
packages/api-client/__tests__/contronllers/activity.test.ts
Normal file
15
packages/api-client/__tests__/contronllers/activity.test.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { mockRequestInstance } from '~/__tests__/helpers/instance'
|
||||
import { mockResponse } from '~/__tests__/helpers/response'
|
||||
import { ActivityController } from '~/controllers'
|
||||
|
||||
describe('test activity client', () => {
|
||||
const client = mockRequestInstance(ActivityController)
|
||||
|
||||
test('POST /like', async () => {
|
||||
mockResponse('/activity/like', {}, 'post')
|
||||
|
||||
await expect(
|
||||
client.activity.likeIt('Note', '11111111'),
|
||||
).resolves.not.toThrowError()
|
||||
})
|
||||
})
|
||||
39
packages/api-client/controllers/activity.ts
Normal file
39
packages/api-client/controllers/activity.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import type { IRequestAdapter } from '~/interfaces/adapter'
|
||||
import type { IController } from '~/interfaces/controller'
|
||||
import type { IRequestHandler } from '~/interfaces/request'
|
||||
|
||||
import { autoBind } from '~/utils/auto-bind'
|
||||
|
||||
import { HTTPClient } from '../core'
|
||||
|
||||
declare module '../core/client' {
|
||||
interface HTTPClient<
|
||||
T extends IRequestAdapter = IRequestAdapter,
|
||||
ResponseWrapper = unknown,
|
||||
> {
|
||||
activity: ActivityController<ResponseWrapper>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @support core >= 4.3.0
|
||||
*/
|
||||
export class ActivityController<ResponseWrapper> implements IController {
|
||||
base = 'activity'
|
||||
name = 'activity'
|
||||
|
||||
constructor(private client: HTTPClient) {
|
||||
autoBind(this)
|
||||
}
|
||||
|
||||
public get proxy(): IRequestHandler<ResponseWrapper> {
|
||||
return this.client.proxy(this.base)
|
||||
}
|
||||
|
||||
likeIt(type: 'Post' | 'Note', id: string) {
|
||||
return this.proxy.like.post<never>({
|
||||
type,
|
||||
id,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,12 @@ import type {
|
||||
TimelineData,
|
||||
TimelineType,
|
||||
} from '~/models/aggregate'
|
||||
import type { HTTPClient } from '../core'
|
||||
|
||||
import { sortOrderToNumber } from '~/utils'
|
||||
import { autoBind } from '~/utils/auto-bind'
|
||||
|
||||
import { HTTPClient } from '../core'
|
||||
|
||||
declare module '../core/client' {
|
||||
interface HTTPClient<
|
||||
T extends IRequestAdapter = IRequestAdapter,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ActivityController } from './activity'
|
||||
import { AggregateController } from './aggregate'
|
||||
import { CategoryController } from './category'
|
||||
import { CommentController } from './comment'
|
||||
@@ -20,6 +21,7 @@ import { TopicController } from './topic'
|
||||
import { UserController } from './user'
|
||||
|
||||
export const allControllers = [
|
||||
ActivityController,
|
||||
AggregateController,
|
||||
CategoryController,
|
||||
CommentController,
|
||||
@@ -39,6 +41,7 @@ export const allControllers = [
|
||||
]
|
||||
|
||||
export const allContollerNames = [
|
||||
'activity',
|
||||
'aggregate',
|
||||
'category',
|
||||
'comment',
|
||||
@@ -63,6 +66,7 @@ export const allContollerNames = [
|
||||
] as const
|
||||
|
||||
export {
|
||||
ActivityController,
|
||||
AggregateController,
|
||||
CategoryController,
|
||||
CommentController,
|
||||
|
||||
Reference in New Issue
Block a user