diff --git a/src/api/db/models/Image.js b/src/api/db/models/Image.js index 2515c66f..25c256a0 100644 --- a/src/api/db/models/Image.js +++ b/src/api/db/models/Image.js @@ -369,27 +369,16 @@ export class ImageModel { } static async createComment(input, context) { - const operation = async (input) => { - return await retry(async (bail, attempt) => { - if (attempt > 1) console.log(`Retrying createComment operation! Try #: ${attempt}`); - - // find images, add comment, and bulk write - return await Image.bulkWrite([{ - updateOne: { - filter: { _id: input.imageId }, - update: { $push: { comments: { - author: context.user['cognito:username'], - comment: input.comment - } } } - } - }]); - }, { retries: 2 }); - }; - try { - await operation(input); const image = await ImageModel.queryById(input.imageId, context); + if (!image.comments) image.comments = []; + image.comments.push({ + author: context.user['cognito:username'], + comment: input.comment + }); + await image.save(); + return { comments: image.comments }; } catch (err) { // if error is uncontrolled, throw new ApolloError diff --git a/src/api/db/schemas/Image.js b/src/api/db/schemas/Image.js index ebef0c74..1e045c86 100644 --- a/src/api/db/schemas/Image.js +++ b/src/api/db/schemas/Image.js @@ -14,7 +14,7 @@ const Schema = mongoose.Schema; */ const ImageCommentSchema = new Schema({ - _id: { type: String, required: true, default: Schema.Types.ObjectId, }, + _id: { type: String, required: true, default: Schema.Types.ObjectId }, author: { type: String, required: true }, created: { type: Date, default: Date.now, required: true }, comment: { type: String, required: true }