diff --git a/apps/core/src/modules/note/note.controller.ts b/apps/core/src/modules/note/note.controller.ts index 2eff6ca3..ab635cf7 100644 --- a/apps/core/src/modules/note/note.controller.ts +++ b/apps/core/src/modules/note/note.controller.ts @@ -164,6 +164,9 @@ export class NoteController { } @Get('like/:id') + /** + * @deprecated + */ async likeNote( @Param() param: IntIdOrMongoIdDto, @IpLocation() location: IpRecord, diff --git a/apps/core/src/modules/post/post.controller.ts b/apps/core/src/modules/post/post.controller.ts index 077c4e99..75691755 100644 --- a/apps/core/src/modules/post/post.controller.ts +++ b/apps/core/src/modules/post/post.controller.ts @@ -232,6 +232,9 @@ export class PostController { return } + /** + * @deprecated + */ @Get('/_thumbs-up') async thumbsUpArticle( @Query() query: MongoIdDto, diff --git a/packages/api-client/__tests__/contronllers/activity.test.ts b/packages/api-client/__tests__/contronllers/activity.test.ts new file mode 100644 index 00000000..060c19d6 --- /dev/null +++ b/packages/api-client/__tests__/contronllers/activity.test.ts @@ -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() + }) +}) diff --git a/packages/api-client/controllers/activity.ts b/packages/api-client/controllers/activity.ts new file mode 100644 index 00000000..691d150c --- /dev/null +++ b/packages/api-client/controllers/activity.ts @@ -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 + } +} + +/** + * @support core >= 4.3.0 + */ +export class ActivityController implements IController { + base = 'activity' + name = 'activity' + + constructor(private client: HTTPClient) { + autoBind(this) + } + + public get proxy(): IRequestHandler { + return this.client.proxy(this.base) + } + + likeIt(type: 'Post' | 'Note', id: string) { + return this.proxy.like.post({ + type, + id, + }) + } +} diff --git a/packages/api-client/controllers/aggregate.ts b/packages/api-client/controllers/aggregate.ts index 9fa8693b..eeda95b4 100644 --- a/packages/api-client/controllers/aggregate.ts +++ b/packages/api-client/controllers/aggregate.ts @@ -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, diff --git a/packages/api-client/controllers/index.ts b/packages/api-client/controllers/index.ts index 30e89151..4cd13d43 100644 --- a/packages/api-client/controllers/index.ts +++ b/packages/api-client/controllers/index.ts @@ -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,