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",

31
pnpm-lock.yaml generated
View File

@@ -269,6 +269,7 @@ importers:
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
@@ -291,6 +292,7 @@ importers:
abort-controller: 3.0.0
axios: 1.2.1
camelcase-keys: 8.0.2
concurrently: 7.6.0
cors: 2.8.5
dts-bundle-generator: 7.0.0
express: 4.18.2
@@ -3797,6 +3799,22 @@ packages:
/concat-map/0.0.1:
resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==}
/concurrently/7.6.0:
resolution: {integrity: sha512-BKtRgvcJGeZ4XttiDiNcFiRlxoAeZOseqUvyYRUp/Vtd+9p1ULmeoSqGsDA+2ivdeDFpqrJvGvmI+StKfKl5hw==}
engines: {node: ^12.20.0 || ^14.13.0 || >=16.0.0}
hasBin: true
dependencies:
chalk: 4.1.2
date-fns: 2.29.3
lodash: 4.17.21
rxjs: 7.6.0
shell-quote: 1.7.4
spawn-command: 0.0.2-1
supports-color: 8.1.1
tree-kill: 1.2.2
yargs: 17.6.2
dev: true
/consola/2.15.3:
resolution: {integrity: sha512-9vAdYbHj6x2fLKC4+oPH0kFzY/orMZyG2Aj+kNylHxKGJ/Ed4dpNyAQYwJOdqO4zdM7XpVHmyejQDcQHrnuXbw==}
@@ -3940,6 +3958,11 @@ packages:
engines: {node: '>= 12'}
dev: true
/date-fns/2.29.3:
resolution: {integrity: sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA==}
engines: {node: '>=0.11'}
dev: true
/dayjs/1.11.7:
resolution: {integrity: sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ==}
dev: false
@@ -7543,6 +7566,10 @@ packages:
resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==}
engines: {node: '>=8'}
/shell-quote/1.7.4:
resolution: {integrity: sha512-8o/QEhSSRb1a5i7TFR0iM4G16Z0vYB2OQVs4G3aAFXjn3T6yEx8AZxy1PgDF7I00LZHYA3WxaSYIf5e5sAX8Rw==}
dev: true
/shelljs/0.8.5:
resolution: {integrity: sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==}
engines: {node: '>=4'}
@@ -7728,6 +7755,10 @@ packages:
memory-pager: 1.5.0
optional: true
/spawn-command/0.0.2-1:
resolution: {integrity: sha512-n98l9E2RMSJ9ON1AKisHzz7V42VDiBQGY6PB1BwRglz99wpVsSuGzQ+jOi6lFXBGVTCrRpltvjm+/XA+tpeJrg==}
dev: true
/split/0.3.3:
resolution: {integrity: sha512-wD2AeVmxXRBoX44wAycgjVpMhvbwdI2aZjCkvfNcH1YqHQvJVa1duWc73OyVGJUc05fhFaTZeQ/PYsrmyH0JVA==}
dependencies: