fix(link): filter pass link in get all api
This commit is contained in:
@@ -93,4 +93,16 @@ export class AppController {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@Get('/clean_redis')
|
||||
@HttpCache.disable
|
||||
@Auth()
|
||||
async cleanAllRedisKey() {
|
||||
const redis = this.cacheService.getClient()
|
||||
const keys: string[] = await redis.keys(getRedisKey('*'))
|
||||
|
||||
await Promise.all(keys.map((key) => redis.del(key)))
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,15 +8,16 @@ import {
|
||||
Post,
|
||||
Query,
|
||||
} from '@nestjs/common'
|
||||
import type mongoose from 'mongoose'
|
||||
import { LinkQueryDto } from './link.dto'
|
||||
import { LinkModel } from './link.model'
|
||||
import { LinkModel, LinkState } from './link.model'
|
||||
import { LinkService } from './link.service'
|
||||
import { Auth } from '~/common/decorator/auth.decorator'
|
||||
import { Paginator } from '~/common/decorator/http.decorator'
|
||||
import { ApiName } from '~/common/decorator/openapi.decorator'
|
||||
import { IsMaster } from '~/common/decorator/role.decorator'
|
||||
import { PagerDto } from '~/shared/dto/pager.dto'
|
||||
import { BaseCrudFactory } from '~/utils/crud.util'
|
||||
import { BaseCrudFactory, BaseCrudModuleType } from '~/utils/crud.util'
|
||||
|
||||
const paths = ['links', 'friends']
|
||||
@Controller(paths)
|
||||
@@ -26,9 +27,13 @@ export class LinkControllerCrud extends BaseCrudFactory({
|
||||
}) {
|
||||
@Get('/')
|
||||
@Paginator
|
||||
async gets(@Query() pager: PagerDto, @IsMaster() isMaster: boolean) {
|
||||
async gets(
|
||||
this: BaseCrudModuleType<LinkModel>,
|
||||
@Query() pager: PagerDto,
|
||||
@IsMaster() isMaster: boolean,
|
||||
) {
|
||||
const { size, page, state } = pager
|
||||
// @ts-ignore
|
||||
|
||||
return await this._model.paginate(state !== undefined ? { state } : {}, {
|
||||
limit: size,
|
||||
page,
|
||||
@@ -36,6 +41,15 @@ export class LinkControllerCrud extends BaseCrudFactory({
|
||||
select: isMaster ? '' : '-email',
|
||||
})
|
||||
}
|
||||
|
||||
@Get('/all')
|
||||
async getAll(this: BaseCrudModuleType<LinkModel>) {
|
||||
// 过滤未通过审核的
|
||||
const condition: mongoose.FilterQuery<LinkModel> = {
|
||||
state: LinkState.Pass,
|
||||
}
|
||||
return await this._model.find(condition).sort({ created: -1 }).lean()
|
||||
}
|
||||
}
|
||||
|
||||
@Controller(paths)
|
||||
|
||||
@@ -21,6 +21,9 @@ import { MongoIdDto } from '~/shared/dto/id.dto'
|
||||
import { PagerDto } from '~/shared/dto/pager.dto'
|
||||
import { BaseModel } from '~/shared/model/base.model'
|
||||
|
||||
export type BaseCrudModuleType<T> = {
|
||||
_model: MongooseModel<T>
|
||||
}
|
||||
export function BaseCrudFactory<
|
||||
T extends AnyParamConstructor<BaseModel & { id?: string }>,
|
||||
>({ model }: { model: T }): Type<any> {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { RedisKeys } from '~/constants/cache.constant'
|
||||
|
||||
export const getRedisKey = (
|
||||
key: RedisKeys,
|
||||
export const getRedisKey = <T extends string = RedisKeys | '*'>(
|
||||
key: T,
|
||||
...concatKeys: string[]
|
||||
): `mx:${RedisKeys}${string | ''}` => {
|
||||
): `mx:${T}${string | ''}` => {
|
||||
return `mx:${key}${
|
||||
concatKeys && concatKeys.length ? `_${concatKeys.join('_')}` : ''
|
||||
}`
|
||||
|
||||
Reference in New Issue
Block a user