Skip to content

Commit

Permalink
styling and test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jue-henry committed Dec 3, 2024
1 parent adcdb5c commit a2a1672
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
23 changes: 12 additions & 11 deletions src/api/db/models/Image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -581,12 +579,12 @@ export class ImageModel {
static async countProjectTag(
input: { tagId: string },
context: Pick<Context, 'user'>,
): Promise<number> {
): Promise<number> {
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;
Expand All @@ -599,14 +597,17 @@ export class ImageModel {
static async deleteProjectTag(
input: { tagId: string },
context: Pick<Context, 'user'>,
): Promise<UpdateWriteOpResult> {
): Promise<UpdateWriteOpResult> {
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;
Expand Down
5 changes: 3 additions & 2 deletions test/image#deleteImages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ tape('Image: DeleteImages', async (t) => {
} else {
t.fail();
}
return { Deleted: [], Errors: [] };
});

const imageModel = new ImageModel({ curr_project_roles: ['project_manager'] });
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit a2a1672

Please sign in to comment.