Skip to content

Commit 5a89199

Browse files
committed
#3873 changes from review
1 parent bedf35d commit 5a89199

8 files changed

Lines changed: 12 additions & 79 deletions

File tree

src/backend/src/controllers/organizations.controllers.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,6 @@ export default class OrganizationsController {
125125
}
126126
}
127127

128-
static async getPlatformLogoImage(req: Request, res: Response, next: NextFunction) {
129-
try {
130-
const platformLogoImageId = await OrganizationsService.getPlatformLogoImage(req.organization.organizationId);
131-
res.status(200).json(platformLogoImageId);
132-
} catch (error: unknown) {
133-
next(error);
134-
}
135-
}
136-
137128
static async setNewMemberImage(req: Request, res: Response, next: NextFunction) {
138129
try {
139130
if (!req.file) {

src/backend/src/routes/organizations.routes.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ organizationRouter.post(
4949
upload.single('platformLogo'),
5050
OrganizationsController.setPlatformLogoImage
5151
);
52-
organizationRouter.get('/platform-logo', OrganizationsController.getPlatformLogoImage);
5352

5453
organizationRouter.post(
5554
'/new-member-image/update',
@@ -65,7 +64,7 @@ organizationRouter.post(
6564
);
6665
organizationRouter.post(
6766
'/platform-description/set',
68-
body('platformDescription').isString(),
67+
nonEmptyString(body('platformDescription')),
6968
validateInputs,
7069
OrganizationsController.setPlatformDescription
7170
);

src/backend/src/services/organizations.services.ts

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -569,43 +569,24 @@ export default class OrganizationsService {
569569
* @param organizationId the organization which the images will be set up
570570
* @param images the images which are being set
571571
*/
572-
static async setPlatformLogoImage(
573-
platformLogoImageId: Express.Multer.File | null,
574-
submitter: User,
575-
organization: Organization
576-
) {
572+
static async setPlatformLogoImage(platformLogoImage: Express.Multer.File, submitter: User, organization: Organization) {
577573
if (!(await userHasPermission(submitter.userId, organization.organizationId, isAdmin))) {
578574
throw new AccessDeniedAdminOnlyException('update platform logo');
579575
}
580576

581-
const platformLogoImageData = platformLogoImageId ? await uploadFile(platformLogoImageId) : null;
577+
const platformLogoImageData = await uploadFile(platformLogoImage);
582578

583-
const updateData = {
584-
...(platformLogoImageData && { platformLogoImageId: platformLogoImageData.id })
585-
};
579+
if (!platformLogoImageData?.id || !platformLogoImageData?.name) {
580+
throw new HttpException(500, 'Platform logo upload failed');
581+
}
586582

587583
const newImages = await prisma.organization.update({
588584
where: { organizationId: organization.organizationId },
589-
data: updateData
585+
data: {
586+
platformLogoImageId: platformLogoImageData.id
587+
}
590588
});
591589

592590
return newImages;
593591
}
594-
595-
/**
596-
* Gets platform logo image for the given organization
597-
* @param organizationId organization Id of the milestone
598-
* @returns all the milestones from the given organization
599-
*/
600-
static async getPlatformLogoImage(organizationId: string) {
601-
const organization = await prisma.organization.findUnique({
602-
where: { organizationId }
603-
});
604-
605-
if (!organization) {
606-
throw new NotFoundException('Organization', organizationId);
607-
}
608-
609-
return organization.platformLogoImageId;
610-
}
611592
}

src/backend/src/transformers/organizationTransformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const organizationTransformer = (organization: Organization): Organizatio
66
...organization,
77
applicationLink: organization.applicationLink ?? undefined,
88
newMemberImageId: organization.newMemberImageId ?? undefined,
9-
platformDescription: organization.platformDescription ?? '',
9+
platformDescription: organization.platformDescription,
1010
platformLogoImageId: organization.platformLogoImageId ?? undefined
1111
};
1212
};

src/backend/tests/unit/organization.test.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -334,25 +334,4 @@ describe('Organization Tests', () => {
334334
expect(updatedOrganization?.platformLogoImageId).toBe('uploaded-image3.png');
335335
});
336336
});
337-
338-
describe('Get Organization Platform Logo', () => {
339-
it('Fails if an organization does not exist', async () => {
340-
await expect(async () => await OrganizationsService.getPlatformLogoImage('1')).rejects.toThrow(
341-
new NotFoundException('Organization', '1')
342-
);
343-
});
344-
345-
it('Succeeds and gets the image', async () => {
346-
const testBatman = await createTestUser(batmanAppAdmin, orgId);
347-
await OrganizationsService.setPlatformLogoImage(
348-
{ originalname: 'image1.png' } as Express.Multer.File,
349-
testBatman,
350-
organization
351-
);
352-
const image = await OrganizationsService.getPlatformLogoImage(orgId);
353-
354-
expect(image).not.toBeNull();
355-
expect(image).toBe('uploaded-image1.png');
356-
});
357-
});
358337
});

src/frontend/src/apis/organizations.api.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ export const setOrganizationPlatformLogoImage = async (file: File) => {
7878
return axios.post<Organization>(apiUrls.organizationsSetPlatformLogoImage(), formData);
7979
};
8080

81-
export const getOrganizationPlatformLogoImage = async () => {
82-
return axios.get<string>(apiUrls.organizationsPlatformLogoImage(), {
83-
transformResponse: (data) => JSON.parse(data)
84-
});
85-
};
86-
8781
export const setOrganizationFeaturedProjects = async (featuredProjectIds: string[]) => {
8882
return axios.post<Organization>(apiUrls.organizationsSetFeaturedProjects(), {
8983
projectIds: featuredProjectIds

src/frontend/src/hooks/organizations.hooks.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import {
2121
setFinanceDelegates,
2222
setOrganizationNewMemberImage,
2323
getOrganizationNewMemberImage,
24-
setOrganizationPlatformLogoImage,
25-
getOrganizationPlatformLogoImage
24+
setOrganizationPlatformLogoImage
2625
} from '../apis/organizations.api';
2726
import { downloadGoogleImage } from '../apis/organizations.api';
2827

@@ -246,16 +245,6 @@ export const useSetOrganizationPlatformLogoImage = () => {
246245
});
247246
};
248247

249-
export const useOrganizationPlatformLogoImage = () => {
250-
return useQuery<Blob | undefined, Error>(['organizations', 'platform-logo'], async () => {
251-
const { data: fileId } = await getOrganizationPlatformLogoImage();
252-
if (!fileId) {
253-
return;
254-
}
255-
return await downloadGoogleImage(fileId);
256-
});
257-
};
258-
259248
/*
260249
* Custom React Hook to fetch confluence guide for current
261250
* organization in backend

src/frontend/src/pages/HomePage/HomePage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const HomePage = () => {
3232
<AdminHomePage user={user} />
3333
) : (
3434
<GuestHomePage user={user} />
35-
)}
35+
)}o
3636
</>
3737
);
3838
};

0 commit comments

Comments
 (0)