From 937d191d810325d1289484e5a81776fc2f8af263 Mon Sep 17 00:00:00 2001 From: ingalls Date: Tue, 19 Dec 2023 11:04:09 -0700 Subject: [PATCH] Setup ImageComments --- src/api/db/models/Image.js | 6 +++--- src/api/type-defs/payloads/ImageCommentPayload.js | 4 ---- src/api/type-defs/payloads/ImageCommentsPayload.js | 4 ++++ src/api/type-defs/root/Mutation.js | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) delete mode 100644 src/api/type-defs/payloads/ImageCommentPayload.js create mode 100644 src/api/type-defs/payloads/ImageCommentsPayload.js diff --git a/src/api/db/models/Image.js b/src/api/db/models/Image.js index efb5ea03..2515c66f 100644 --- a/src/api/db/models/Image.js +++ b/src/api/db/models/Image.js @@ -337,7 +337,7 @@ export class ImageModel { await image.save(); - return { message: 'Images Deleted' }; + return { comments: image.comments }; } catch (err) { // if error is uncontrolled, throw new ApolloError if (err instanceof ApolloError) throw err; @@ -360,7 +360,7 @@ export class ImageModel { await image.save(); - return comment; + return { comments: image.comments }; } catch (err) { // if error is uncontrolled, throw new ApolloError if (err instanceof ApolloError) throw err; @@ -390,7 +390,7 @@ export class ImageModel { await operation(input); const image = await ImageModel.queryById(input.imageId, context); - return image.comments.pop(); + return { comments: image.comments }; } catch (err) { // if error is uncontrolled, throw new ApolloError if (err instanceof ApolloError) throw err; diff --git a/src/api/type-defs/payloads/ImageCommentPayload.js b/src/api/type-defs/payloads/ImageCommentPayload.js deleted file mode 100644 index b4ae3783..00000000 --- a/src/api/type-defs/payloads/ImageCommentPayload.js +++ /dev/null @@ -1,4 +0,0 @@ -export default ` - type ImageCommentPayload { - comment: ImageComment - }`; diff --git a/src/api/type-defs/payloads/ImageCommentsPayload.js b/src/api/type-defs/payloads/ImageCommentsPayload.js new file mode 100644 index 00000000..58fbb60a --- /dev/null +++ b/src/api/type-defs/payloads/ImageCommentsPayload.js @@ -0,0 +1,4 @@ +export default ` + type ImageCommentsPayload { + comments: [ImageComment] + }`; diff --git a/src/api/type-defs/root/Mutation.js b/src/api/type-defs/root/Mutation.js index e48776a2..759a70de 100644 --- a/src/api/type-defs/root/Mutation.js +++ b/src/api/type-defs/root/Mutation.js @@ -3,9 +3,9 @@ export default ` createImage(input: CreateImageInput!): CreateImagePayload deleteImages(input: DeleteImagesInput!): StandardErrorPayload - createImageComment(input: CreateImageCommentInput!): ImageCommentPayload - updateImageComment(input: UpdateImageCommentInput!): ImageCommentPayload - deleteImageComment(input: DeleteImageCommentInput!): StandardPayload + createImageComment(input: CreateImageCommentInput!): ImageCommentsPayload + updateImageComment(input: UpdateImageCommentInput!): ImageCommentsPayload + deleteImageComment(input: DeleteImageCommentInput!): ImageCommentsPayload createUser(input: CreateUserInput!): StandardPayload updateUser(input: UpdateUserInput!): StandardPayload