Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Commit

Permalink
feat: update getAllTags
Browse files Browse the repository at this point in the history
  • Loading branch information
YanceyOfficial committed Apr 15, 2020
1 parent fcfe69f commit 28e31dd
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 43 deletions.
6 changes: 6 additions & 0 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ type Query {
getPosts(input: PaginationInput!): PostModel!
getPostById(id: ID!): PostItemModel!
getTopPVPosts(limit: Int!): [PostItemModel!]!
getTopLikePosts(limit: Int!): [PostItemModel!]!
getAllTags: TagsModel!
getMottos: [MottoModel!]!
getMottoById(id: ID!): MottoModel!
getCovers: [CoverModel!]!
Expand Down Expand Up @@ -457,6 +459,10 @@ type ServiceInfoModel {
veid: Float!
}

type TagsModel {
tags: [String!]!
}

type TOTPModel {
qrcode: String!
key: String!
Expand Down
40 changes: 40 additions & 0 deletions src/posts/models/post.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Field, ID, ObjectType } from '@nestjs/graphql'

@ObjectType()
export class PostItemModel {
@Field(() => ID)
public readonly _id: string

@Field()
public readonly posterUrl: string

@Field()
public readonly title: string

@Field()
public readonly summary: string

@Field()
public readonly content: string

@Field(() => [String])
public readonly tags: string[]

@Field()
public readonly lastModifiedDate: Date

@Field()
public readonly like: number

@Field()
public readonly pv: number

@Field()
public readonly isPublic: boolean

@Field()
public readonly createdAt: Date

@Field()
public readonly updatedAt: Date
}
43 changes: 2 additions & 41 deletions src/posts/models/posts.model.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,5 @@
/* eslint-disable max-classes-per-file */
import { Field, ID, ObjectType } from '@nestjs/graphql'

@ObjectType()
export class PostItemModel {
@Field(() => ID)
public readonly _id: string

@Field()
public readonly posterUrl: string

@Field()
public readonly title: string

@Field()
public readonly summary: string

@Field()
public readonly content: string

@Field(() => [String])
public readonly tags: string[]

@Field()
public readonly lastModifiedDate: Date

@Field()
public readonly like: number

@Field()
public readonly pv: number

@Field()
public readonly isPublic: boolean

@Field()
public readonly createdAt: Date

@Field()
public readonly updatedAt: Date
}
import { Field, ObjectType } from '@nestjs/graphql'
import { PostItemModel } from './post.model'

@ObjectType()
export class PostModel {
Expand Down
8 changes: 8 additions & 0 deletions src/posts/models/tags.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Field, ObjectType } from '@nestjs/graphql'
import { PostItemModel } from './post.model'

@ObjectType()
export class TagsModel {
@Field(() => [String])
public readonly tags: string[]
}
14 changes: 13 additions & 1 deletion src/posts/posts.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { UseGuards } from '@nestjs/common'
import { Args, Query, Resolver, Mutation, ID, Int } from '@nestjs/graphql'
import { PostsService } from './posts.service'
import { PostModel, PostItemModel } from './models/posts.model'
import { PostModel } from './models/posts.model'
import { PostItemModel } from './models/post.model'
import { TagsModel } from './models/tags.model'
import { BatchDeleteModel } from '../database/models/batch-delete.model'
import { CreatePostInput } from './dtos/create-post.input'
import { UpdatePostInput } from './dtos/update-post.input'
Expand Down Expand Up @@ -64,4 +66,14 @@ export class PostsResolver {
public async getTopPVPosts(@Args({ name: 'limit', type: () => Int }) limit: number) {
return this.postsService.getTopPVPosts(limit)
}

@Query(() => [PostItemModel])
public async getTopLikePosts(@Args({ name: 'limit', type: () => Int }) limit: number) {
return this.postsService.getTopLikePosts(limit)
}

@Query(() => TagsModel)
public async getAllTags() {
return this.postsService.getAllTags()
}
}
19 changes: 18 additions & 1 deletion src/posts/posts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { Model } from 'mongoose'
import { CreatePostInput } from './dtos/create-post.input'
import { UpdatePostInput } from './dtos/update-post.input'
import { PaginationInput } from './dtos/pagination.input'
import { PostModel, PostItemModel } from './models/posts.model'
import { PostModel } from './models/posts.model'
import { PostItemModel } from './models/post.model'
import { TagsModel } from './models/tags.model'
import { Post } from './interfaces/posts.interface'
import { BatchDeleteModel } from '../database/models/batch-delete.model'

Expand Down Expand Up @@ -83,4 +85,19 @@ export class PostsService {
.sort({ pv: -1, _id: -1 })
.limit(limit)
}

public async getTopLikePosts(limit: number): Promise<PostItemModel[]> {
return this.postModel
.find({ isPublic: { $ne: false } })
.sort({ like: -1, _id: -1 })
.limit(limit)
}

public async getAllTags(): Promise<TagsModel> {
const posts = await this.postModel.find({}, { isPublic: { $ne: false }, tags: 1 })

return {
tags: [],
}
}
}

0 comments on commit 28e31dd

Please sign in to comment.