feat(api-client): add attitude method

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2022-12-23 15:20:55 +08:00
parent 4c603dcba1
commit b44bb411f0
4 changed files with 70 additions and 8 deletions

View File

@@ -43,6 +43,15 @@ describe('test recently client, /recently', () => {
expect(data).toEqual(mocked)
})
test('GET /attitude', async () => {
const id = `1212121`
const mocked = mockResponse(`/recently/attitude/${id}?attitude=1`, {
code: 1,
})
const data = await client.recently.attitude(id, 1)
expect(data).toEqual(mocked)
})
it('should `recently` == `shorthand`', () => {
expect(client.recently).toEqual(client.shorthand)
})

View File

@@ -16,6 +16,16 @@ declare module '../core/client' {
}
}
export enum RecentlyAttitudeResultEnum {
Inc = 1,
Dec = -1,
}
export enum RecentlyAttitudeEnum {
Up,
Down,
}
export class RecentlyController<ResponseWrapper> implements IController {
base = 'recently'
name = ['recently', 'shorthand']
@@ -31,11 +41,13 @@ export class RecentlyController<ResponseWrapper> implements IController {
* 获取最新一条
*/
getLatestOne() {
return this.proxy.latest.get<RecentlyModel>()
return this.proxy.latest.get<RecentlyModel & { comments: number }>()
}
getAll() {
return this.proxy.all.get<{ data: RecentlyModel[] }>()
return this.proxy.all.get<{
data: RecentlyModel[] & { comments: number }
}>()
}
getList(
@@ -43,7 +55,7 @@ export class RecentlyController<ResponseWrapper> implements IController {
after?: string | undefined,
size?: number | number,
) {
return this.proxy.get<{ data: RecentlyModel[] }>({
return this.proxy.get<{ data: RecentlyModel[] & { comments: number } }>({
params: {
before,
after,
@@ -51,4 +63,13 @@ export class RecentlyController<ResponseWrapper> implements IController {
},
})
}
/** 表态:点赞,点踩 */
attitude(id: string, attitude: RecentlyAttitudeEnum) {
return this.proxy.attitude(id).get<{ code: RecentlyAttitudeResultEnum }>({
params: {
attitude,
},
})
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@mx-space/api-client",
"version": "1.0.1",
"version": "1.0.2",
"type": "module",
"description": "A api client for mx-space server@next",
"author": "Innei",
@@ -79,13 +79,13 @@
},
"scripts": {
"prebuild": "rm -rf lib && rm -rf esm",
"build": "tsc --build tsconfig.build.json && tsc --build tsconfig.cjs.json",
"postbuild": "tsc-alias -p tsconfig.build.json && tsc-alias -p tsconfig.cjs.json && npm run types",
"build": "concurrently \"tsc --build tsconfig.build.json\" \"tsc --build tsconfig.cjs.json\"",
"postbuild": "concurrently \"tsc-alias -p tsconfig.build.json\" \"tsc-alias -p tsconfig.cjs.json\" \"npm run types\"",
"types": "rm -rf types && tsc --build tsconfig.types.json && tsc-alias -p tsconfig.types.json",
"package": "NODE_ENV=production npm run build && rollup -c",
"package": "NODE_ENV=production concurrently \"npm run build\" \"rollup -c\"",
"prepackage": "rm -rf dist",
"test": "vitest",
"dev": "vite"
"dev": "vitest"
},
"devDependencies": {
"@rollup/plugin-commonjs": "22.0.2",
@@ -97,6 +97,7 @@
"abort-controller": "3.0.0",
"axios": "*",
"camelcase-keys": "*",
"concurrently": "7.6.0",
"cors": "2.8.5",
"dts-bundle-generator": "7.0.0",
"express": "4.18.2",