Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 28 additions & 31 deletions src/backend/src/controllers/organizations.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,6 @@ export default class OrganizationsController {
}
}

static async setImages(req: Request, res: Response, next: NextFunction) {
try {
const { applyInterestImage = [], exploreAsGuestImage = [] } = req.files as {
applyInterestImage?: Express.Multer.File[];
exploreAsGuestImage?: Express.Multer.File[];
};

const applyInterestFile = applyInterestImage[0] || null;
const exploreAsGuestFile = exploreAsGuestImage[0] || null;

const newImages = await OrganizationsService.setImages(
applyInterestFile,
exploreAsGuestFile,
req.currentUser,
req.organization
);

res.status(200).json(newImages);
} catch (error: unknown) {
next(error);
}
}
static async getAllUsefulLinks(req: Request, res: Response, next: NextFunction) {
try {
const links = await OrganizationsService.getAllUsefulLinks(req.organization.organizationId);
Expand Down Expand Up @@ -97,15 +75,6 @@ export default class OrganizationsController {
}
}

static async getOrganizationImages(req: Request, res: Response, next: NextFunction) {
try {
const images = await OrganizationsService.getOrganizationImages(req.organization.organizationId);
res.status(200).json(images);
} catch (error: unknown) {
next(error);
}
}

static async setOrganizationFeaturedProjects(req: Request, res: Response, next: NextFunction) {
try {
const { projectIds } = req.body;
Expand Down Expand Up @@ -142,6 +111,20 @@ export default class OrganizationsController {
}
}

static async setPlatformLogoImage(req: Request, res: Response, next: NextFunction) {
try {
if (!req.file) {
throw new HttpException(400, 'Invalid or undefined image data');
}

const updatedOrg = await OrganizationsService.setPlatformLogoImage(req.file, req.currentUser, req.organization);

res.status(200).json(updatedOrg);
} catch (error: unknown) {
next(error);
}
}

static async setNewMemberImage(req: Request, res: Response, next: NextFunction) {
try {
if (!req.file) {
Expand Down Expand Up @@ -181,6 +164,20 @@ export default class OrganizationsController {
}
}

static async setPlatformDescription(req: Request, res: Response, next: NextFunction) {
try {
const updatedOrg = await OrganizationsService.setPlatformDescription(
req.body.platformDescription,
req.currentUser,
req.organization
);

res.status(200).json(updatedOrg);
} catch (error: unknown) {
next(error);
}
}

static async getOrganizationFeaturedProjects(req: Request, res: Response, next: NextFunction) {
try {
const featuredProjects = await OrganizationsService.getOrganizationFeaturedProjects(req.organization.organizationId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:

- You are about to drop the column `applyInterestImageId` on the `Organization` table. All the data in the column will be lost.
- You are about to drop the column `exploreAsGuestImageId` on the `Organization` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "Organization" DROP COLUMN "applyInterestImageId",
DROP COLUMN "exploreAsGuestImageId",
ADD COLUMN "platformDescription" TEXT NOT NULL DEFAULT '',
ADD COLUMN "platformLogoImageId" TEXT;
18 changes: 9 additions & 9 deletions src/backend/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -1027,12 +1027,12 @@ enum DayOfWeek {
}

model Schedule_Slot {
scheduleSlotId String @id @default(uuid())
startTime DateTime
endTime DateTime
allDay Boolean @default(false)
eventId String
event Event @relation(fields: [eventId], references: [eventId])
scheduleSlotId String @id @default(uuid())
startTime DateTime
endTime DateTime
allDay Boolean @default(false)
eventId String
event Event @relation(fields: [eventId], references: [eventId])

@@index([endTime])
@@index([startTime])
Expand Down Expand Up @@ -1088,7 +1088,7 @@ model Event {
shops Shop[]
machinery Machinery[]
workPackages Work_Package[]
documents Document[]
documents Document[]
status Event_Status
initialDateScheduled DateTime?
questionDocumentLink String?
Expand Down Expand Up @@ -1312,8 +1312,6 @@ model Organization {
advisor User? @relation(name: "advisor", fields: [advisorId], references: [userId])
advisorId String?
description String @default("")
applyInterestImageId String?
exploreAsGuestImageId String?
newMemberImageId String?
logoImageId String?
slackWorkspaceId String?
Expand All @@ -1322,6 +1320,8 @@ model Organization {
partReviewSampleImageId String?
partReviewGuideLink String?
sponsorshipNotificationsSlackChannelId String?
platformDescription String @default("")
platformLogoImageId String?

// Relation references
wbsElements WBS_Element[]
Expand Down
15 changes: 15 additions & 0 deletions src/backend/src/prisma/seed-data/users.seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ const joeBlow: Prisma.UserCreateInput = {
}
};

const guestUser: Prisma.UserCreateInput = {
firstName: 'Guest',
lastName: 'User',
googleAuthId: 'guest-google-id',
email: 'guest@husky.neu.edu',
emailId: 'guest',
userSettings: {
create: {
defaultTheme: Theme.DARK,
slackId: SLACK_ID ? SLACK_ID : 'guest'
}
}
};

const wonderwoman: Prisma.UserCreateInput = {
firstName: 'Diana',
lastName: 'Prince',
Expand Down Expand Up @@ -994,6 +1008,7 @@ export const dbSeedAllUsers = {
thomasEmrax,
joeShmoe,
joeBlow,
guestUser,
wonderwoman,
flash,
aquaman,
Expand Down
20 changes: 8 additions & 12 deletions src/backend/src/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ const performSeed: () => Promise<void> = async () => {
userCreatedId: thomasEmrax.userId,
description:
'Northeastern Electric Racing is a student-run organization at Northeastern University building all-electric formula-style race cars from scratch to compete in Forumla Hybrid + Electric Formula SAE (FSAE).',
applyInterestImageId: '1_iak6ord4JP9TcR1sOYopyEs6EjTKQpw',
exploreAsGuestImageId: '1wRes7V_bMm9W7_3JCIDXYkMUiy6B3wRI',
applicationLink:
'https://docs.google.com/forms/d/e/1FAIpQLSeCvG7GqmZm_gmSZiahbVTW9ZFpEWG0YfGQbkSB_whhHzxXpA/closedform'
'https://docs.google.com/forms/d/e/1FAIpQLSeCvG7GqmZm_gmSZiahbVTW9ZFpEWG0YfGQbkSB_whhHzxXpA/closedform',
platformDescription:
'Finishline is a Project Management Dashboard developed by the Software Team at Northeastern Electric Racing.',
platformLogoImageId: '1auQO3GYydZOo1-vCn0D2iyCfaxaVFssx'
}
});

Expand Down Expand Up @@ -264,6 +265,7 @@ const performSeed: () => Promise<void> = async () => {
const regina = await createUser(dbSeedAllUsers.regina, RoleEnum.MEMBER, organizationId);
const patrick = await createUser(dbSeedAllUsers.patrick, RoleEnum.MEMBER, organizationId);
const spongebob = await createUser(dbSeedAllUsers.spongebob, RoleEnum.MEMBER, organizationId);
await createUser(dbSeedAllUsers.guestUser, RoleEnum.GUEST, organizationId);

await UsersService.updateUserRole(cyborg.userId, thomasEmrax, 'APP_ADMIN', ner);

Expand Down Expand Up @@ -367,21 +369,15 @@ const performSeed: () => Promise<void> = async () => {
const mechanical = await TeamsService.createTeamType(
batman,
'Mechanical',
'YouTubeIcon',
'Construction',
'This is the mechanical team',
ner
);
const software = await TeamsService.createTeamType(
thomasEmrax,
'Software',
'InstagramIcon',
'This is the software team',
ner
);
const software = await TeamsService.createTeamType(thomasEmrax, 'Software', 'Code', 'This is the software team', ner);
const electrical = await TeamsService.createTeamType(
cyborg,
'Electrical',
'SettingsIcon',
'ElectricBolt',
'This is the electrical team',
ner
);
Expand Down
21 changes: 13 additions & 8 deletions src/backend/src/routes/organizations.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ const upload = multer({ limits: { fileSize: MAX_FILE_SIZE }, storage: memoryStor
organizationRouter.get('/current', OrganizationsController.getCurrentOrganization);
organizationRouter.post('/useful-links/set', ...linkValidators, validateInputs, OrganizationsController.setUsefulLinks);
organizationRouter.get('/useful-links', OrganizationsController.getAllUsefulLinks);
organizationRouter.post(
'/images/update',
upload.fields([
{ name: 'applyInterestImage', maxCount: 1 },
{ name: 'exploreAsGuestImage', maxCount: 1 }
]),
OrganizationsController.setImages
);

organizationRouter.post(
'/application-link/update',
Expand Down Expand Up @@ -51,6 +43,13 @@ organizationRouter.post(
);
organizationRouter.post('/logo/update', upload.single('logo'), OrganizationsController.setLogoImage);
organizationRouter.get('/logo', OrganizationsController.getOrganizationLogoImage);

organizationRouter.post(
'/platform-logo/update',
upload.single('platformLogo'),
OrganizationsController.setPlatformLogoImage
);

organizationRouter.post(
'/new-member-image/update',
upload.single('newMemberImage'),
Expand All @@ -63,6 +62,12 @@ organizationRouter.post(
validateInputs,
OrganizationsController.setOrganizationDescription
);
organizationRouter.post(
'/platform-description/set',
nonEmptyString(body('platformDescription')),
validateInputs,
OrganizationsController.setPlatformDescription
);
organizationRouter.get('/featured-projects', OrganizationsController.getOrganizationFeaturedProjects);
organizationRouter.post(
'/workspaceId/set',
Expand Down
95 changes: 44 additions & 51 deletions src/backend/src/services/organizations.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,37 +104,6 @@ export default class OrganizationsService {
return newLinks;
}

/**
* sets an organizations images
* @param submitter the user who is setting the images
* @param organizationId the organization which the images will be set up
* @param images the images which are being set
*/
static async setImages(
applyInterestImage: Express.Multer.File | null,
exploreAsGuestImage: Express.Multer.File | null,
submitter: User,
organization: Organization
) {
if (!(await userHasPermission(submitter.userId, organization.organizationId, isAdmin))) {
throw new AccessDeniedAdminOnlyException('update images');
}

const applyInterestImageData = applyInterestImage ? await uploadFile(applyInterestImage) : null;
const exploreAsGuestImageData = exploreAsGuestImage ? await uploadFile(exploreAsGuestImage) : null;
const updateData = {
...(applyInterestImageData && { applyInterestImageId: applyInterestImageData.id }),
...(exploreAsGuestImageData && { exploreAsGuestImageId: exploreAsGuestImageData.id })
};

const newImages = await prisma.organization.update({
where: { organizationId: organization.organizationId },
data: updateData
});

return newImages;
}

/**
Gets all the useful links for an organization
@param organizationId the organization to get the links for
Expand Down Expand Up @@ -255,26 +224,6 @@ export default class OrganizationsService {
return updatedOrganization;
}

/**
* Gets all organization Images for the given organization Id
* @param organizationId organization Id of the milestone
* @returns all the milestones from the given organization
*/
static async getOrganizationImages(organizationId: string) {
const organization = await prisma.organization.findUnique({
where: { organizationId }
});

if (!organization) {
throw new NotFoundException('Organization', organizationId);
}

return {
applyInterestImage: organization.applyInterestImageId,
exploreAsGuestImage: organization.exploreAsGuestImageId
};
}

/**
* Updates the featured projects of an organization
* @param projectIds project ids of featured projects
Expand Down Expand Up @@ -429,6 +378,23 @@ export default class OrganizationsService {
return updatedOrg;
}

/**
* Sets the platform description of a given organization.
* @param platformDescription the new platform description
* @param submitter the user making the change
* @param organization the organization whose platform description is changing
* @throws if the user is not an admin
*/
static async setPlatformDescription(platformDescription: string, submitter: User, organization: Organization) {
if (!(await userHasPermission(submitter.userId, organization.organizationId, isAdmin))) {
throw new AccessDeniedAdminOnlyException('set platform description');
}
return prisma.organization.update({
where: { organizationId: organization.organizationId },
data: { platformDescription }
});
}

/**
* Gets the featured projects for the given organization Id
* @param organizationId the organization to get the projects for
Expand Down Expand Up @@ -596,4 +562,31 @@ export default class OrganizationsService {

return updatedOrg.financeDelegates.map(userTransformer);
}

/**
* sets an organizations platform image
* @param submitter the user who is setting the images
* @param organizationId the organization which the images will be set up
* @param images the images which are being set
*/
static async setPlatformLogoImage(platformLogoImage: Express.Multer.File, submitter: User, organization: Organization) {
if (!(await userHasPermission(submitter.userId, organization.organizationId, isAdmin))) {
throw new AccessDeniedAdminOnlyException('update platform logo');
}

const platformLogoImageData = await uploadFile(platformLogoImage);

if (!platformLogoImageData?.id || !platformLogoImageData?.name) {
throw new HttpException(500, 'Platform logo upload failed');
}

const newImages = await prisma.organization.update({
where: { organizationId: organization.organizationId },
data: {
platformLogoImageId: platformLogoImageData.id
}
});

return newImages;
}
}
6 changes: 3 additions & 3 deletions src/backend/src/transformers/organizationTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export const organizationTransformer = (organization: Organization): Organizatio
return {
...organization,
applicationLink: organization.applicationLink ?? undefined,
applyInterestImageId: organization.applyInterestImageId ?? undefined,
exploreAsGuestImageId: organization.exploreAsGuestImageId ?? undefined,
newMemberImageId: organization.newMemberImageId ?? undefined
newMemberImageId: organization.newMemberImageId ?? undefined,
platformDescription: organization.platformDescription,
platformLogoImageId: organization.platformLogoImageId ?? undefined
};
};
Loading