make libraryItemIds not null
This commit is contained in:
@ -19,8 +19,8 @@ export class Post {
|
||||
@JoinColumn({ name: 'user_id' })
|
||||
user!: User
|
||||
|
||||
@Column('uuid', { array: true, nullable: true })
|
||||
libraryItemIds?: string[] | null
|
||||
@Column('uuid', { array: true })
|
||||
libraryItemIds!: string[]
|
||||
|
||||
@Column('uuid', { array: true, nullable: true })
|
||||
highlightIds?: string[] | null
|
||||
|
||||
@ -521,7 +521,7 @@ export enum CreatePostErrorCode {
|
||||
export type CreatePostInput = {
|
||||
content: Scalars['String'];
|
||||
highlightIds?: InputMaybe<Array<Scalars['ID']>>;
|
||||
libraryItemIds?: InputMaybe<Array<Scalars['ID']>>;
|
||||
libraryItemIds: Array<Scalars['ID']>;
|
||||
thought?: InputMaybe<Scalars['String']>;
|
||||
thumbnail?: InputMaybe<Scalars['String']>;
|
||||
title: Scalars['String'];
|
||||
@ -2413,7 +2413,7 @@ export type Post = {
|
||||
createdAt: Scalars['Date'];
|
||||
highlights?: Maybe<Array<Highlight>>;
|
||||
id: Scalars['ID'];
|
||||
libraryItems?: Maybe<Array<Article>>;
|
||||
libraryItems: Array<Article>;
|
||||
ownedByViewer: Scalars['Boolean'];
|
||||
thought?: Maybe<Scalars['String']>;
|
||||
thumbnail?: Maybe<Scalars['String']>;
|
||||
@ -7064,7 +7064,7 @@ export type PostResolvers<ContextType = ResolverContext, ParentType extends Reso
|
||||
createdAt?: Resolver<ResolversTypes['Date'], ParentType, ContextType>;
|
||||
highlights?: Resolver<Maybe<Array<ResolversTypes['Highlight']>>, ParentType, ContextType>;
|
||||
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
|
||||
libraryItems?: Resolver<Maybe<Array<ResolversTypes['Article']>>, ParentType, ContextType>;
|
||||
libraryItems?: Resolver<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>;
|
||||
|
||||
@ -466,7 +466,7 @@ enum CreatePostErrorCode {
|
||||
input CreatePostInput {
|
||||
content: String!
|
||||
highlightIds: [ID!]
|
||||
libraryItemIds: [ID!]
|
||||
libraryItemIds: [ID!]!
|
||||
thought: String
|
||||
thumbnail: String
|
||||
title: String!
|
||||
@ -1847,7 +1847,7 @@ type Post {
|
||||
createdAt: Date!
|
||||
highlights: [Highlight!]
|
||||
id: ID!
|
||||
libraryItems: [Article!]
|
||||
libraryItems: [Article!]!
|
||||
ownedByViewer: Boolean!
|
||||
thought: String
|
||||
thumbnail: String
|
||||
|
||||
@ -125,8 +125,8 @@ export const createPostResolver = authorized<
|
||||
userId: uid,
|
||||
title,
|
||||
content,
|
||||
libraryItemIds,
|
||||
highlightIds: highlightIds || undefined,
|
||||
libraryItemIds: libraryItemIds || undefined,
|
||||
thought: thought || undefined,
|
||||
thumbnail: thumbnail || undefined,
|
||||
}
|
||||
@ -160,7 +160,7 @@ export const updatePostResolver = authorized<
|
||||
thumbnail,
|
||||
} = input
|
||||
|
||||
if (!id || title === null || content === null) {
|
||||
if (!id || title === null || content === null || libraryItemIds === null) {
|
||||
log.error('Invalid args', { id })
|
||||
|
||||
return {
|
||||
|
||||
@ -3347,7 +3347,7 @@ const schema = gql`
|
||||
ownedByViewer: Boolean!
|
||||
thumbnail: String
|
||||
thought: String
|
||||
libraryItems: [Article!]
|
||||
libraryItems: [Article!]!
|
||||
highlights: [Highlight!]
|
||||
createdAt: Date!
|
||||
updatedAt: Date!
|
||||
@ -3357,7 +3357,7 @@ const schema = gql`
|
||||
title: String! @sanitize(minLength: 1, maxLength: 255)
|
||||
content: String! @sanitize(minLength: 1)
|
||||
thumbnail: String
|
||||
libraryItemIds: [ID!]
|
||||
libraryItemIds: [ID!]!
|
||||
highlightIds: [ID!]
|
||||
thought: String
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import { expect } from 'chai'
|
||||
import { LibraryItem } from '../../src/entity/library_item'
|
||||
import { User } from '../../src/entity/user'
|
||||
import { deleteLibraryItemById } from '../../src/services/library_item'
|
||||
import {
|
||||
createPosts,
|
||||
deletePosts,
|
||||
@ -7,7 +9,7 @@ import {
|
||||
} from '../../src/services/post'
|
||||
import { findProfile, updateProfile } from '../../src/services/profile'
|
||||
import { deleteUser } from '../../src/services/user'
|
||||
import { createTestUser } from '../db'
|
||||
import { createTestLibraryItem, createTestUser } from '../db'
|
||||
import { generateFakeUuid, graphqlRequest, loginAndGetAuthToken } from '../util'
|
||||
|
||||
describe('Post Resolvers', () => {
|
||||
@ -53,20 +55,27 @@ describe('Post Resolvers', () => {
|
||||
`
|
||||
|
||||
let postIds: Array<string> = []
|
||||
let libraryItem: LibraryItem
|
||||
let libraryItem1: LibraryItem
|
||||
|
||||
before(async () => {
|
||||
libraryItem = await createTestLibraryItem(loginUser.id)
|
||||
libraryItem1 = await createTestLibraryItem(loginUser.id)
|
||||
|
||||
const posts = [
|
||||
{
|
||||
title: 'Post 1',
|
||||
content: 'Content 1',
|
||||
user: loginUser,
|
||||
createdAt: new Date('2021-01-01'),
|
||||
libraryItemIds: [libraryItem.id],
|
||||
},
|
||||
{
|
||||
title: 'Post 2',
|
||||
content: 'Content 2',
|
||||
user: loginUser,
|
||||
createdAt: new Date('2021-01-02'),
|
||||
libraryItemIds: [libraryItem1.id],
|
||||
},
|
||||
]
|
||||
const newPosts = await createPosts(loginUser.id, posts)
|
||||
@ -76,6 +85,9 @@ describe('Post Resolvers', () => {
|
||||
|
||||
after(async () => {
|
||||
await deletePosts(loginUser.id, postIds)
|
||||
|
||||
await deleteLibraryItemById(libraryItem.id, loginUser.id)
|
||||
await deleteLibraryItemById(libraryItem1.id, loginUser.id)
|
||||
})
|
||||
|
||||
it('should return an error if the args are invalid', async () => {
|
||||
@ -164,12 +176,16 @@ describe('Post Resolvers', () => {
|
||||
`
|
||||
|
||||
let postId: string
|
||||
let libraryItem: LibraryItem
|
||||
|
||||
before(async () => {
|
||||
libraryItem = await createTestLibraryItem(loginUser.id)
|
||||
|
||||
const post = {
|
||||
title: 'Post',
|
||||
content: 'Content',
|
||||
user: loginUser,
|
||||
libraryItemIds: [libraryItem.id],
|
||||
}
|
||||
const newPost = await createPosts(loginUser.id, [post])
|
||||
|
||||
@ -178,6 +194,7 @@ describe('Post Resolvers', () => {
|
||||
|
||||
after(async () => {
|
||||
await deletePosts(loginUser.id, [postId])
|
||||
await deleteLibraryItemById(libraryItem.id, loginUser.id)
|
||||
})
|
||||
|
||||
it('should return an error if the args are invalid', async () => {
|
||||
@ -266,10 +283,13 @@ describe('Post Resolvers', () => {
|
||||
`
|
||||
|
||||
it('should create a post', async () => {
|
||||
const libraryItem = await createTestLibraryItem(loginUser.id)
|
||||
|
||||
const response = await graphqlRequest(mutation, authToken, {
|
||||
input: {
|
||||
title: 'Post',
|
||||
content: 'Content',
|
||||
libraryItemIds: [libraryItem.id],
|
||||
},
|
||||
})
|
||||
|
||||
@ -286,6 +306,7 @@ describe('Post Resolvers', () => {
|
||||
expect(profile?.private).to.be.false
|
||||
|
||||
await deletePosts(loginUser.id, [postId])
|
||||
await deleteLibraryItemById(libraryItem.id, loginUser.id)
|
||||
})
|
||||
})
|
||||
|
||||
@ -308,12 +329,16 @@ describe('Post Resolvers', () => {
|
||||
`
|
||||
|
||||
let postId: string
|
||||
let libraryItem: LibraryItem
|
||||
|
||||
before(async () => {
|
||||
libraryItem = await createTestLibraryItem(loginUser.id)
|
||||
|
||||
const post = {
|
||||
title: 'Post',
|
||||
content: 'Content',
|
||||
user: loginUser,
|
||||
libraryItemIds: [libraryItem.id],
|
||||
}
|
||||
const newPost = await createPosts(loginUser.id, [post])
|
||||
|
||||
@ -322,6 +347,7 @@ describe('Post Resolvers', () => {
|
||||
|
||||
after(async () => {
|
||||
await deletePosts(loginUser.id, [postId])
|
||||
await deleteLibraryItemById(libraryItem.id, loginUser.id)
|
||||
})
|
||||
|
||||
it('should return an error if the args are invalid', async () => {
|
||||
@ -399,18 +425,27 @@ describe('Post Resolvers', () => {
|
||||
`
|
||||
|
||||
let postId: string
|
||||
let libraryItem: LibraryItem
|
||||
|
||||
before(async () => {
|
||||
libraryItem = await createTestLibraryItem(loginUser.id)
|
||||
|
||||
const post = {
|
||||
title: 'Post',
|
||||
content: 'Content',
|
||||
user: loginUser,
|
||||
libraryItemIds: [libraryItem.id],
|
||||
}
|
||||
const newPost = await createPosts(loginUser.id, [post])
|
||||
|
||||
postId = newPost[0].id
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
await deletePosts(loginUser.id, [postId])
|
||||
await deleteLibraryItemById(libraryItem.id, loginUser.id)
|
||||
})
|
||||
|
||||
it('should return an error if the args are invalid', async () => {
|
||||
const response = await graphqlRequest(mutation, authToken, {
|
||||
id: '',
|
||||
|
||||
@ -7,7 +7,7 @@ BEGIN;
|
||||
CREATE TABLE omnivore.post (
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v1mc(),
|
||||
user_id UUID NOT NULL REFERENCES omnivore.user(id) ON DELETE CASCADE,
|
||||
library_item_ids UUID[],
|
||||
library_item_ids UUID[] NOT NULL,
|
||||
highlight_ids UUID[],
|
||||
title TEXT NOT NULL,
|
||||
content TEXT NOT NULL, -- generated from template
|
||||
|
||||
Reference in New Issue
Block a user