Skip to content

Commit

Permalink
Attempt at fixing linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jennymar committed Oct 10, 2024
1 parent a7ebcbc commit 9c42e85
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 772 deletions.
48 changes: 8 additions & 40 deletions api/controllers/AdminController.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import {
JsonController,
Post,
Patch,
UploadedFile,
UseBefore,
ForbiddenError,
Body,
Get,
} from 'routing-controllers';
import { JsonController, Post, Patch, UploadedFile, UseBefore, ForbiddenError, Body, Get } from 'routing-controllers';
import { UserAuthentication } from '../middleware/UserAuthentication';
import {
CreateBonusRequest,
Expand Down Expand Up @@ -53,9 +44,7 @@ export class AdminController {
}

@Get('/email')
async getAllNamesAndEmails(
@AuthenticatedUser() user: UserModel,
): Promise<GetAllNamesAndEmailsResponse> {
async getAllNamesAndEmails(@AuthenticatedUser() user: UserModel): Promise<GetAllNamesAndEmailsResponse> {
if (!PermissionsService.canSeeAllUserEmails(user)) throw new ForbiddenError();
const namesAndEmails = await this.userAccountService.getAllNamesAndEmails();
return { error: null, namesAndEmails };
Expand All @@ -67,9 +56,7 @@ export class AdminController {
@AuthenticatedUser() user: UserModel,
): Promise<CreateMilestoneResponse> {
if (!PermissionsService.canCreateMilestones(user)) throw new ForbiddenError();
await this.userAccountService.createMilestone(
createMilestoneRequest.milestone,
);
await this.userAccountService.createMilestone(createMilestoneRequest.milestone);
return { error: null };
}

Expand All @@ -81,11 +68,7 @@ export class AdminController {
if (!PermissionsService.canGrantPointBonuses(user)) throw new ForbiddenError();
const { bonus } = createBonusRequest;
const emails = bonus.users.map((e) => e.toLowerCase());
await this.userAccountService.grantBonusPoints(
emails,
bonus.description,
bonus.points,
);
await this.userAccountService.grantBonusPoints(emails, bonus.description, bonus.points);
return { error: null, emails };
}

Expand All @@ -96,11 +79,7 @@ export class AdminController {
})
file: File,
): Promise<UploadBannerResponse> {
const banner = await this.storageService.upload(
file,
MediaType.BANNER,
'banner',
);
const banner = await this.storageService.upload(file, MediaType.BANNER, 'banner');
return { error: null, banner };
}

Expand All @@ -112,12 +91,7 @@ export class AdminController {
if (!PermissionsService.canSubmitAttendanceForUsers(currentUser)) throw new ForbiddenError();
const { users, event, asStaff } = submitAttendanceForUsersRequest;
const emails = users.map((e) => e.toLowerCase());
const attendances = await this.attendanceService.submitAttendanceForUsers(
emails,
event,
asStaff,
currentUser,
);
const attendances = await this.attendanceService.submitAttendanceForUsers(emails, event, asStaff, currentUser);
return { error: null, attendances };
}

Expand All @@ -129,18 +103,12 @@ export class AdminController {
if (!PermissionsService.canModifyUserAccessLevel(currentUser)) throw new ForbiddenError();
const { accessUpdates } = modifyUserAccessLevelRequest;
const emails = accessUpdates.map((e) => e.user.toLowerCase());
const updatedUsers = await this.userAccountService.updateUserAccessLevels(
accessUpdates,
emails,
currentUser,
);
const updatedUsers = await this.userAccountService.updateUserAccessLevels(accessUpdates, emails, currentUser);
return { error: null, updatedUsers };
}

@Get('/access')
async getAllUsersWithAccessLevels(
@AuthenticatedUser() user: UserModel,
): Promise<GetAllUserAccessLevelsResponse> {
async getAllUsersWithAccessLevels(@AuthenticatedUser() user: UserModel): Promise<GetAllUserAccessLevelsResponse> {
if (!PermissionsService.canSeeAllUserAccessLevels(user)) throw new ForbiddenError();
const users = await this.userAccountService.getAllFullUserProfiles();
return {
Expand Down
59 changes: 11 additions & 48 deletions api/controllers/AttendanceController.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
import {
JsonController,
Get,
Post,
UseBefore,
Params,
ForbiddenError,
Body,
} from 'routing-controllers';
import { JsonController, Get, Post, UseBefore, Params, ForbiddenError, Body } from 'routing-controllers';
import EmailService from '../../services/EmailService';
import { UserAuthentication } from '../middleware/UserAuthentication';
import { AuthenticatedUser } from '../decorators/AuthenticatedUser';
import {
AttendEventRequest,
AttendViaExpressCheckinRequest,
} from '../validators/AttendanceControllerRequests';
import { AttendEventRequest, AttendViaExpressCheckinRequest } from '../validators/AttendanceControllerRequests';
import { UserModel } from '../../models/UserModel';
import AttendanceService from '../../services/AttendanceService';
import PermissionsService from '../../services/PermissionsService';
import {
GetAttendancesForEventResponse,
GetAttendancesForUserResponse,
AttendEventResponse,
} from '../../types';
import { GetAttendancesForEventResponse, GetAttendancesForUserResponse, AttendEventResponse } from '../../types';
import { UuidParam } from '../validators/GenericRequests';

@JsonController('/attendance')
Expand All @@ -30,10 +15,7 @@ export class AttendanceController {

private emailService: EmailService;

constructor(
attendanceService: AttendanceService,
emailService: EmailService,
) {
constructor(attendanceService: AttendanceService, emailService: EmailService) {
this.attendanceService = attendanceService;
this.emailService = emailService;
}
Expand All @@ -45,9 +27,7 @@ export class AttendanceController {
@AuthenticatedUser() user: UserModel,
): Promise<GetAttendancesForEventResponse> {
if (!PermissionsService.canSeeEventAttendances(user)) throw new ForbiddenError();
const attendances = await this.attendanceService.getAttendancesForEvent(
params.uuid,
);
const attendances = await this.attendanceService.getAttendancesForEvent(params.uuid);
return {
error: null,
attendances: attendances.map((attendance) => attendance.getPublicAttendance()),
Expand All @@ -56,9 +36,7 @@ export class AttendanceController {

@UseBefore(UserAuthentication)
@Get()
async getAttendancesForCurrentUser(
@AuthenticatedUser() user: UserModel,
): Promise<GetAttendancesForUserResponse> {
async getAttendancesForCurrentUser(@AuthenticatedUser() user: UserModel): Promise<GetAttendancesForUserResponse> {
const attendances = await this.attendanceService.getAttendancesForCurrentUser(user);
return {
error: null,
Expand All @@ -75,9 +53,7 @@ export class AttendanceController {
if (params.uuid === currentUser.uuid) {
return this.getAttendancesForCurrentUser(currentUser);
}
const attendances = await this.attendanceService.getAttendancesForUser(
params.uuid,
);
const attendances = await this.attendanceService.getAttendancesForUser(params.uuid);
return {
error: null,
attendances: attendances.map((attendance) => attendance.getPublicAttendance()),
Expand All @@ -90,30 +66,17 @@ export class AttendanceController {
@Body() body: AttendEventRequest,
@AuthenticatedUser() user: UserModel,
): Promise<AttendEventResponse> {
const attendance = await this.attendanceService.attendEvent(
user,
body.attendanceCode,
body.asStaff,
);
const attendance = await this.attendanceService.attendEvent(user, body.attendanceCode, body.asStaff);
const { event } = attendance.getPublicAttendance();
return { error: null, event };
}

@Post('/expressCheckin')
async attendViaExpressCheckin(
@Body() body: AttendViaExpressCheckinRequest,
): Promise<AttendEventResponse> {
async attendViaExpressCheckin(@Body() body: AttendViaExpressCheckinRequest): Promise<AttendEventResponse> {
body.email = body.email.toLowerCase();
const { email, attendanceCode } = body;
const { event } = await this.attendanceService.attendViaExpressCheckin(
attendanceCode,
email,
);
await this.emailService.sendExpressCheckinConfirmation(
email,
event.title,
event.pointValue,
);
const { event } = await this.attendanceService.attendViaExpressCheckin(attendanceCode, email);
await this.emailService.sendExpressCheckinConfirmation(email, event.title, event.pointValue);
return { error: null, event };
}
}
58 changes: 17 additions & 41 deletions api/controllers/EventController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import {
Body,
} from 'routing-controllers';
import EventService from '../../services/EventService';
import {
UserAuthentication,
OptionalUserAuthentication,
} from '../middleware/UserAuthentication';
import { UserAuthentication, OptionalUserAuthentication } from '../middleware/UserAuthentication';
import { AuthenticatedUser } from '../decorators/AuthenticatedUser';
import { UserModel } from '../../models/UserModel';
import PermissionsService from '../../services/PermissionsService';
Expand Down Expand Up @@ -49,11 +46,7 @@ export class EventController {

private attendanceService: AttendanceService;

constructor(
eventService: EventService,
storageService: StorageService,
attendanceService: AttendanceService,
) {
constructor(eventService: EventService, storageService: StorageService, attendanceService: AttendanceService) {
this.eventService = eventService;
this.storageService = storageService;
this.attendanceService = attendanceService;
Expand All @@ -63,7 +56,7 @@ export class EventController {
@Get('/past')
async getPastEvents(
@QueryParams() options: EventSearchOptions,
@AuthenticatedUser() user: UserModel,
@AuthenticatedUser() user: UserModel,
): Promise<GetPastEventsResponse> {
const canSeeAttendanceCode = !!user && PermissionsService.canEditEvents(user);
const events = await this.eventService.getPastEvents(options);
Expand All @@ -77,7 +70,7 @@ export class EventController {
@Get('/future')
async getFutureEvents(
@QueryParams() options: EventSearchOptions,
@AuthenticatedUser() user: UserModel,
@AuthenticatedUser() user: UserModel,
): Promise<GetFutureEventsResponse> {
const canSeeAttendanceCode = !!user && PermissionsService.canEditEvents(user);
const events = await this.eventService.getFutureEvents(options);
Expand All @@ -93,42 +86,31 @@ export class EventController {
@UploadedFile('image', {
options: StorageService.getFileOptions(MediaType.EVENT_COVER),
})
file: File,
@Params() params: UuidParam,
@AuthenticatedUser() user: UserModel,
file: File,
@Params() params: UuidParam,
@AuthenticatedUser() user: UserModel,
): Promise<UpdateEventCoverResponse> {
if (!PermissionsService.canEditEvents(user)) throw new ForbiddenError();
const cover = await this.storageService.upload(
file,
MediaType.EVENT_COVER,
params.uuid,
);
const cover = await this.storageService.upload(file, MediaType.EVENT_COVER, params.uuid);
const event = await this.eventService.updateByUuid(params.uuid, { cover });
return { error: null, event: event.getPublicEvent(true) };
}

@UseBefore(UserAuthentication)
@Post('/:uuid/feedback')
async submitEventFeedback(
@Params() params: UuidParam,
@Params() params: UuidParam,
@Body() submitEventFeedbackRequest: SubmitEventFeedbackRequest,
@AuthenticatedUser() user: UserModel,
) {
if (!PermissionsService.canSubmitFeedback(user)) throw new ForbiddenError();
await this.attendanceService.submitEventFeedback(
submitEventFeedbackRequest.feedback,
params.uuid,
user,
);
await this.attendanceService.submitEventFeedback(submitEventFeedbackRequest.feedback, params.uuid, user);
return { error: null };
}

@UseBefore(OptionalUserAuthentication)
@Get('/:uuid')
async getOneEvent(
@Params() params: UuidParam,
@AuthenticatedUser() user: UserModel,
): Promise<GetOneEventResponse> {
async getOneEvent(@Params() params: UuidParam, @AuthenticatedUser() user: UserModel): Promise<GetOneEventResponse> {
const canSeeAttendanceCode = !!user && PermissionsService.canEditEvents(user);
const event = await this.eventService.findByUuid(params.uuid);
return { error: null, event: event.getPublicEvent(canSeeAttendanceCode) };
Expand All @@ -138,23 +120,17 @@ export class EventController {
@Patch('/:uuid')
async updateEvent(
@Params() params: UuidParam,
@Body() patchEventRequest: PatchEventRequest,
@AuthenticatedUser() user: UserModel,
@Body() patchEventRequest: PatchEventRequest,
@AuthenticatedUser() user: UserModel,
): Promise<PatchEventResponse> {
if (!PermissionsService.canEditEvents(user)) throw new ForbiddenError();
const event = await this.eventService.updateByUuid(
params.uuid,
patchEventRequest.event,
);
const event = await this.eventService.updateByUuid(params.uuid, patchEventRequest.event);
return { error: null, event: event.getPublicEvent(true) };
}

@UseBefore(UserAuthentication)
@Delete('/:uuid')
async deleteEvent(
@Params() params: UuidParam,
@AuthenticatedUser() user: UserModel,
): Promise<DeleteEventResponse> {
async deleteEvent(@Params() params: UuidParam, @AuthenticatedUser() user: UserModel): Promise<DeleteEventResponse> {
if (!PermissionsService.canEditEvents(user)) throw new ForbiddenError();
await this.eventService.deleteByUuid(params.uuid);
return { error: null };
Expand All @@ -164,7 +140,7 @@ export class EventController {
@Get()
async getAllEvents(
@QueryParams() options: EventSearchOptions,
@AuthenticatedUser() user: UserModel,
@AuthenticatedUser() user: UserModel,
): Promise<GetAllEventsResponse> {
const canSeeAttendanceCode = !!user && PermissionsService.canEditEvents(user);
const events = await this.eventService.getAllEvents(options);
Expand All @@ -178,7 +154,7 @@ export class EventController {
@Post()
async createEvent(
@Body() createEventRequest: CreateEventRequest,
@AuthenticatedUser() user: UserModel,
@AuthenticatedUser() user: UserModel,
): Promise<CreateEventResponse> {
if (!PermissionsService.canEditEvents(user)) throw new ForbiddenError();
const event = await this.eventService.create(createEventRequest.event);
Expand Down
Loading

0 comments on commit 9c42e85

Please sign in to comment.