From a2a16725cea28f90b55f35f60162f7b00ebe8a06 Mon Sep 17 00:00:00 2001 From: jue-henry Date: Tue, 3 Dec 2024 10:34:59 -0800 Subject: [PATCH] styling and test fixes --- src/api/db/models/Image.ts | 23 ++++++++++++----------- test/image#deleteImages.test.js | 5 +++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/api/db/models/Image.ts b/src/api/db/models/Image.ts index 7e57d6c2..c1383524 100644 --- a/src/api/db/models/Image.ts +++ b/src/api/db/models/Image.ts @@ -565,9 +565,7 @@ export class ImageModel { const tag = image.tags?.filter((t) => idMatch(t, input.tagId))[0]; if (!tag) throw new NotFoundError('Tag not found on image'); - image.tags = image.tags.filter( - (t) => !idMatch(t, input.tagId), - ) as mongoose.Types.ObjectId[]; + image.tags = image.tags.filter((t) => !idMatch(t, input.tagId)) as mongoose.Types.ObjectId[]; await image.save(); @@ -581,12 +579,12 @@ export class ImageModel { static async countProjectTag( input: { tagId: string }, context: Pick, - ): Promise { + ): Promise { try { const projectId = context.user['curr_project']!; const count = await Image.countDocuments({ projectId: projectId, - tags: new ObjectId(input.tagId) + tags: new ObjectId(input.tagId), }); return count; @@ -599,14 +597,17 @@ export class ImageModel { static async deleteProjectTag( input: { tagId: string }, context: Pick, - ): Promise { + ): Promise { try { const projectId = context.user['curr_project']!; - const res = await Image.updateMany({ - projectId: projectId - }, { - $pull: { tags: new mongoose.Types.ObjectId(input.tagId) } - }); + const res = await Image.updateMany( + { + projectId: projectId, + }, + { + $pull: { tags: new mongoose.Types.ObjectId(input.tagId) }, + }, + ); return res; } catch (err) { if (err instanceof GraphQLError) throw err; diff --git a/test/image#deleteImages.test.js b/test/image#deleteImages.test.js index 3c68bb47..cd5a1fe3 100644 --- a/test/image#deleteImages.test.js +++ b/test/image#deleteImages.test.js @@ -66,6 +66,7 @@ tape('Image: DeleteImages', async (t) => { } else { t.fail(); } + return { Deleted: [], Errors: [] }; }); const imageModel = new ImageModel({ curr_project_roles: ['project_manager'] }); @@ -110,8 +111,8 @@ tape('Image: DeleteImages - error', async (t) => { MockConfig(t); Sinon.stub(S3.S3Client.prototype, 'send').callsFake((command) => { - if (command instanceof S3.DeleteObjectCommand) { - mocks.push(`S3::DeleteObjectCommand::${command.input.Bucket}/${command.input.Key}`); + if (command instanceof S3.DeleteObjectsCommand) { + mocks.push(`S3::DeleteObjectsCommand::${command.input.Bucket}/${command.input.Key}`); } else { t.fail(); }