return author name only
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm'
|
||||
import { User } from './user'
|
||||
|
||||
@ -37,9 +39,9 @@ export class Post {
|
||||
@Column('text', { nullable: true })
|
||||
thought?: string | null
|
||||
|
||||
@Column('timestamptz')
|
||||
@CreateDateColumn({ type: 'timestamptz' })
|
||||
createdAt!: Date
|
||||
|
||||
@Column('timestamptz')
|
||||
@UpdateDateColumn({ type: 'timestamptz' })
|
||||
updatedAt!: Date
|
||||
}
|
||||
|
||||
@ -515,6 +515,7 @@ export type CreatePostError = {
|
||||
};
|
||||
|
||||
export enum CreatePostErrorCode {
|
||||
BadRequest = 'BAD_REQUEST',
|
||||
Unauthorized = 'UNAUTHORIZED'
|
||||
}
|
||||
|
||||
@ -2408,12 +2409,12 @@ export type ParseResult = {
|
||||
|
||||
export type Post = {
|
||||
__typename?: 'Post';
|
||||
author: User;
|
||||
author: Scalars['String'];
|
||||
content: Scalars['String'];
|
||||
createdAt: Scalars['Date'];
|
||||
highlights?: Maybe<Array<Highlight>>;
|
||||
id: Scalars['ID'];
|
||||
libraryItems: Array<Article>;
|
||||
libraryItems?: Maybe<Array<Article>>;
|
||||
ownedByViewer: Scalars['Boolean'];
|
||||
thought?: Maybe<Scalars['String']>;
|
||||
thumbnail?: Maybe<Scalars['String']>;
|
||||
@ -7059,12 +7060,12 @@ export type PageInfoResolvers<ContextType = ResolverContext, ParentType extends
|
||||
};
|
||||
|
||||
export type PostResolvers<ContextType = ResolverContext, ParentType extends ResolversParentTypes['Post'] = ResolversParentTypes['Post']> = {
|
||||
author?: Resolver<ResolversTypes['User'], ParentType, ContextType>;
|
||||
author?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
|
||||
content?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
|
||||
createdAt?: Resolver<ResolversTypes['Date'], ParentType, ContextType>;
|
||||
highlights?: Resolver<Maybe<Array<ResolversTypes['Highlight']>>, ParentType, ContextType>;
|
||||
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
|
||||
libraryItems?: Resolver<Array<ResolversTypes['Article']>, ParentType, ContextType>;
|
||||
libraryItems?: Resolver<Maybe<Array<ResolversTypes['Article']>>, ParentType, ContextType>;
|
||||
ownedByViewer?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType>;
|
||||
thought?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
|
||||
thumbnail?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
|
||||
|
||||
@ -460,6 +460,7 @@ type CreatePostError {
|
||||
}
|
||||
|
||||
enum CreatePostErrorCode {
|
||||
BAD_REQUEST
|
||||
UNAUTHORIZED
|
||||
}
|
||||
|
||||
@ -1842,12 +1843,12 @@ input ParseResult {
|
||||
}
|
||||
|
||||
type Post {
|
||||
author: User!
|
||||
author: String!
|
||||
content: String!
|
||||
createdAt: Date!
|
||||
highlights: [Highlight!]
|
||||
id: ID!
|
||||
libraryItems: [Article!]!
|
||||
libraryItems: [Article!]
|
||||
ownedByViewer: Boolean!
|
||||
thought: String
|
||||
thumbnail: String
|
||||
|
||||
@ -791,26 +791,32 @@ export const functionResolvers = {
|
||||
recommendedAt: (recommendation: Recommendation) => recommendation.createdAt,
|
||||
},
|
||||
Post: {
|
||||
author(post: Post, _: never, ctx: ResolverContext) {
|
||||
return ctx.dataLoaders.users.load(post.userId)
|
||||
async author(post: Post, _: never, ctx: ResolverContext) {
|
||||
const author = await ctx.dataLoaders.users.load(post.userId)
|
||||
return author?.name
|
||||
},
|
||||
ownedByViewer(post: Post, _: never, ctx: ResolverContext) {
|
||||
console.log('ownedByViewer: ctx.claims?.uid', ctx.claims?.uid)
|
||||
return post.userId === ctx.claims?.uid
|
||||
},
|
||||
libraryItems(
|
||||
async libraryItems(
|
||||
post: { libraryItemIds: string[] },
|
||||
_: never,
|
||||
ctx: ResolverContext
|
||||
) {
|
||||
return ctx.dataLoaders.libraryItems.loadMany(post.libraryItemIds)
|
||||
const items = await ctx.dataLoaders.libraryItems.loadMany(
|
||||
post.libraryItemIds
|
||||
)
|
||||
return items.filter((item) => !!item)
|
||||
},
|
||||
highlights(
|
||||
async highlights(
|
||||
post: { highlightIds: string[] },
|
||||
_: never,
|
||||
ctx: ResolverContext
|
||||
) {
|
||||
return ctx.dataLoaders.highlights.loadMany(post.highlightIds)
|
||||
const highlights = await ctx.dataLoaders.highlights.loadMany(
|
||||
post.highlightIds
|
||||
)
|
||||
return highlights.filter((highlight) => !!highlight)
|
||||
},
|
||||
},
|
||||
...resultResolveTypeResolver('Login'),
|
||||
|
||||
@ -121,6 +121,14 @@ export const createPostResolver = authorized<
|
||||
const { title, content, highlightIds, libraryItemIds, thought, thumbnail } =
|
||||
input
|
||||
|
||||
if (libraryItemIds.length === 0) {
|
||||
log.error('Invalid args', { libraryItemIds })
|
||||
|
||||
return {
|
||||
errorCodes: [CreatePostErrorCode.BadRequest],
|
||||
}
|
||||
}
|
||||
|
||||
const postToCreate = {
|
||||
userId: uid,
|
||||
title,
|
||||
|
||||
@ -3343,11 +3343,11 @@ const schema = gql`
|
||||
id: ID!
|
||||
title: String!
|
||||
content: String!
|
||||
author: User!
|
||||
author: String!
|
||||
ownedByViewer: Boolean!
|
||||
thumbnail: String
|
||||
thought: String
|
||||
libraryItems: [Article!]!
|
||||
libraryItems: [Article!]
|
||||
highlights: [Highlight!]
|
||||
createdAt: Date!
|
||||
updatedAt: Date!
|
||||
@ -3374,6 +3374,7 @@ const schema = gql`
|
||||
|
||||
enum CreatePostErrorCode {
|
||||
UNAUTHORIZED
|
||||
BAD_REQUEST
|
||||
}
|
||||
|
||||
input UpdatePostInput {
|
||||
|
||||
Reference in New Issue
Block a user