From afdb44236d9b4d01462c74b82ae13a98c9d99194 Mon Sep 17 00:00:00 2001 From: jennymar Date: Sun, 6 Oct 2024 11:15:00 -0700 Subject: [PATCH] Styling fixes --- api/controllers/AdminController.ts | 30 ++-- api/controllers/AttendanceController.ts | 24 ++-- api/controllers/EventController.ts | 36 +++-- api/controllers/FeedbackController.ts | 8 +- api/controllers/MerchStoreController.ts | 176 ++++++++++-------------- api/controllers/UserController.ts | 47 +++---- services/AttendanceService.ts | 39 ++---- services/EventService.ts | 36 ++--- services/FeedbackService.ts | 9 +- services/MerchStoreService.ts | 96 +++++-------- services/UserAccountService.ts | 51 +++---- 11 files changed, 215 insertions(+), 337 deletions(-) diff --git a/api/controllers/AdminController.ts b/api/controllers/AdminController.ts index 9ab8522d..a92ff59c 100644 --- a/api/controllers/AdminController.ts +++ b/api/controllers/AdminController.ts @@ -56,8 +56,7 @@ export class AdminController { async getAllNamesAndEmails( @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canSeeAllUserEmails(user)) - throw new ForbiddenError(); + if (!PermissionsService.canSeeAllUserEmails(user)) throw new ForbiddenError(); const namesAndEmails = await this.userAccountService.getAllNamesAndEmails(); return { error: null, namesAndEmails }; } @@ -65,10 +64,9 @@ export class AdminController { @Post('/milestone') async createMilestone( @Body() createMilestoneRequest: CreateMilestoneRequest, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canCreateMilestones(user)) - throw new ForbiddenError(); + if (!PermissionsService.canCreateMilestones(user)) throw new ForbiddenError(); await this.userAccountService.createMilestone( createMilestoneRequest.milestone, ); @@ -78,10 +76,9 @@ export class AdminController { @Post('/bonus') async addBonus( @Body() createBonusRequest: CreateBonusRequest, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canGrantPointBonuses(user)) - throw new ForbiddenError(); + if (!PermissionsService.canGrantPointBonuses(user)) throw new ForbiddenError(); const { bonus } = createBonusRequest; const emails = bonus.users.map((e) => e.toLowerCase()); await this.userAccountService.grantBonusPoints( @@ -97,7 +94,7 @@ export class AdminController { @UploadedFile('image', { options: StorageService.getFileOptions(MediaType.BANNER), }) - file: File, + file: File, ): Promise { const banner = await this.storageService.upload( file, @@ -110,10 +107,9 @@ export class AdminController { @Post('/attendance') async submitAttendanceForUsers( @Body() submitAttendanceForUsersRequest: SubmitAttendanceForUsersRequest, - @AuthenticatedUser() currentUser: UserModel, + @AuthenticatedUser() currentUser: UserModel, ): Promise { - if (!PermissionsService.canSubmitAttendanceForUsers(currentUser)) - throw new ForbiddenError(); + 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( @@ -128,10 +124,9 @@ export class AdminController { @Patch('/access') async updateUserAccessLevel( @Body() modifyUserAccessLevelRequest: ModifyUserAccessLevelRequest, - @AuthenticatedUser() currentUser: UserModel, + @AuthenticatedUser() currentUser: UserModel, ): Promise { - if (!PermissionsService.canModifyUserAccessLevel(currentUser)) - throw new ForbiddenError(); + if (!PermissionsService.canModifyUserAccessLevel(currentUser)) throw new ForbiddenError(); const { accessUpdates } = modifyUserAccessLevelRequest; const emails = accessUpdates.map((e) => e.user.toLowerCase()); const updatedUsers = await this.userAccountService.updateUserAccessLevels( @@ -146,12 +141,11 @@ export class AdminController { async getAllUsersWithAccessLevels( @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canSeeAllUserAccessLevels(user)) - throw new ForbiddenError(); + if (!PermissionsService.canSeeAllUserAccessLevels(user)) throw new ForbiddenError(); const users = await this.userAccountService.getAllFullUserProfiles(); return { error: null, - users: users.map((user) => user.getFullUserProfile()), + users: users.map((u) => u.getFullUserProfile()), }; } } diff --git a/api/controllers/AttendanceController.ts b/api/controllers/AttendanceController.ts index d1e68a1c..6441933b 100644 --- a/api/controllers/AttendanceController.ts +++ b/api/controllers/AttendanceController.ts @@ -42,18 +42,15 @@ export class AttendanceController { @Get('/:uuid') async getAttendancesForEvent( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canSeeEventAttendances(user)) - throw new ForbiddenError(); + if (!PermissionsService.canSeeEventAttendances(user)) throw new ForbiddenError(); const attendances = await this.attendanceService.getAttendancesForEvent( params.uuid, ); return { error: null, - attendances: attendances.map((attendance) => - attendance.getPublicAttendance(), - ), + attendances: attendances.map((attendance) => attendance.getPublicAttendance()), }; } @@ -62,13 +59,10 @@ export class AttendanceController { async getAttendancesForCurrentUser( @AuthenticatedUser() user: UserModel, ): Promise { - const attendances = - await this.attendanceService.getAttendancesForCurrentUser(user); + const attendances = await this.attendanceService.getAttendancesForCurrentUser(user); return { error: null, - attendances: attendances.map((attendance) => - attendance.getPublicAttendance(), - ), + attendances: attendances.map((attendance) => attendance.getPublicAttendance()), }; } @@ -76,7 +70,7 @@ export class AttendanceController { @Get('/user/:uuid') async getAttendancesForUser( @Params() params: UuidParam, - @AuthenticatedUser() currentUser: UserModel, + @AuthenticatedUser() currentUser: UserModel, ): Promise { if (params.uuid === currentUser.uuid) { return this.getAttendancesForCurrentUser(currentUser); @@ -86,9 +80,7 @@ export class AttendanceController { ); return { error: null, - attendances: attendances.map((attendance) => - attendance.getPublicAttendance(), - ), + attendances: attendances.map((attendance) => attendance.getPublicAttendance()), }; } @@ -96,7 +88,7 @@ export class AttendanceController { @Post() async attendEvent( @Body() body: AttendEventRequest, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { const attendance = await this.attendanceService.attendEvent( user, diff --git a/api/controllers/EventController.ts b/api/controllers/EventController.ts index 0c95b07b..d631f085 100644 --- a/api/controllers/EventController.ts +++ b/api/controllers/EventController.ts @@ -63,10 +63,9 @@ export class EventController { @Get('/past') async getPastEvents( @QueryParams() options: EventSearchOptions, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - const canSeeAttendanceCode = - !!user && PermissionsService.canEditEvents(user); + const canSeeAttendanceCode = !!user && PermissionsService.canEditEvents(user); const events = await this.eventService.getPastEvents(options); return { error: null, @@ -78,10 +77,9 @@ export class EventController { @Get('/future') async getFutureEvents( @QueryParams() options: EventSearchOptions, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - const canSeeAttendanceCode = - !!user && PermissionsService.canEditEvents(user); + const canSeeAttendanceCode = !!user && PermissionsService.canEditEvents(user); const events = await this.eventService.getFutureEvents(options); return { error: null, @@ -95,9 +93,9 @@ 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 { if (!PermissionsService.canEditEvents(user)) throw new ForbiddenError(); const cover = await this.storageService.upload( @@ -112,7 +110,7 @@ export class EventController { @UseBefore(UserAuthentication) @Post('/:uuid/feedback') async submitEventFeedback( - @Params() params: UuidParam, + @Params() params: UuidParam, @Body() submitEventFeedbackRequest: SubmitEventFeedbackRequest, @AuthenticatedUser() user: UserModel, ) { @@ -129,10 +127,9 @@ export class EventController { @Get('/:uuid') async getOneEvent( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - const canSeeAttendanceCode = - !!user && PermissionsService.canEditEvents(user); + const canSeeAttendanceCode = !!user && PermissionsService.canEditEvents(user); const event = await this.eventService.findByUuid(params.uuid); return { error: null, event: event.getPublicEvent(canSeeAttendanceCode) }; } @@ -141,8 +138,8 @@ export class EventController { @Patch('/:uuid') async updateEvent( @Params() params: UuidParam, - @Body() patchEventRequest: PatchEventRequest, - @AuthenticatedUser() user: UserModel, + @Body() patchEventRequest: PatchEventRequest, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canEditEvents(user)) throw new ForbiddenError(); const event = await this.eventService.updateByUuid( @@ -156,7 +153,7 @@ export class EventController { @Delete('/:uuid') async deleteEvent( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canEditEvents(user)) throw new ForbiddenError(); await this.eventService.deleteByUuid(params.uuid); @@ -167,10 +164,9 @@ export class EventController { @Get() async getAllEvents( @QueryParams() options: EventSearchOptions, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - const canSeeAttendanceCode = - !!user && PermissionsService.canEditEvents(user); + const canSeeAttendanceCode = !!user && PermissionsService.canEditEvents(user); const events = await this.eventService.getAllEvents(options); return { error: null, @@ -182,7 +178,7 @@ export class EventController { @Post() async createEvent( @Body() createEventRequest: CreateEventRequest, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canEditEvents(user)) throw new ForbiddenError(); const event = await this.eventService.create(createEventRequest.event); diff --git a/api/controllers/FeedbackController.ts b/api/controllers/FeedbackController.ts index a14ec8ac..ab7b162f 100644 --- a/api/controllers/FeedbackController.ts +++ b/api/controllers/FeedbackController.ts @@ -38,7 +38,7 @@ export class FeedbackController { @Get() async getFeedback( @QueryParams() options: FeedbackSearchOptions, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { const canSeeAllFeedback = PermissionsService.canSeeAllFeedback(user); const feedback = await this.feedbackService.getFeedback( @@ -55,7 +55,7 @@ export class FeedbackController { @Post() async submitFeedback( @Body() submitFeedbackRequest: SubmitFeedbackRequest, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canSubmitFeedback(user)) throw new ForbiddenError(); const feedback = await this.feedbackService.submitFeedback( @@ -68,8 +68,8 @@ export class FeedbackController { @Patch('/:uuid') async updateFeedbackStatus( @Params() params: UuidParam, - @Body() updateFeedbackStatusRequest: UpdateFeedbackStatusRequest, - @AuthenticatedUser() user: UserModel, + @Body() updateFeedbackStatusRequest: UpdateFeedbackStatusRequest, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canSeeAllFeedback(user)) throw new ForbiddenError(); const feedback = await this.feedbackService.updateFeedbackStatus( diff --git a/api/controllers/MerchStoreController.ts b/api/controllers/MerchStoreController.ts index 97b267ac..8446171a 100644 --- a/api/controllers/MerchStoreController.ts +++ b/api/controllers/MerchStoreController.ts @@ -97,10 +97,9 @@ export class MerchStoreController { @Get('/collection/:uuid') async getOneMerchCollection( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canAccessMerchStore(user)) - throw new ForbiddenError(); + if (!PermissionsService.canAccessMerchStore(user)) throw new ForbiddenError(); const canSeeHiddenItems = PermissionsService.canEditMerchStore(user); const collection = await this.merchStoreService.findCollectionByUuid( params.uuid, @@ -118,25 +117,21 @@ export class MerchStoreController { async getAllMerchCollections( @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canAccessMerchStore(user)) - throw new ForbiddenError(); - const canSeeInactiveCollections = - PermissionsService.canEditMerchStore(user); + if (!PermissionsService.canAccessMerchStore(user)) throw new ForbiddenError(); + const canSeeInactiveCollections = PermissionsService.canEditMerchStore(user); const collections = await this.merchStoreService.getAllCollections( canSeeInactiveCollections, ); return { error: null, - collections: collections.map((c) => - c.getPublicMerchCollection(canSeeInactiveCollections), - ), + collections: collections.map((c) => c.getPublicMerchCollection(canSeeInactiveCollections)), }; } @Post('/collection') async createMerchCollection( @Body() createCollectionRequest: CreateMerchCollectionRequest, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canEditMerchStore(user)) throw new ForbiddenError(); const collection = await this.merchStoreService.createCollection( @@ -148,8 +143,8 @@ export class MerchStoreController { @Patch('/collection/:uuid') async editMerchCollection( @Params() params: UuidParam, - @Body() editCollectionRequest: EditMerchCollectionRequest, - @AuthenticatedUser() user: UserModel, + @Body() editCollectionRequest: EditMerchCollectionRequest, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canEditMerchStore(user)) throw new ForbiddenError(); const collection = await this.merchStoreService.editCollection( @@ -162,7 +157,7 @@ export class MerchStoreController { @Delete('/collection/:uuid') async deleteMerchCollection( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canEditMerchStore(user)) throw new ForbiddenError(); await this.merchStoreService.deleteCollection(params.uuid); @@ -175,17 +170,16 @@ export class MerchStoreController { @UploadedFile('image', { options: StorageService.getFileOptions(MediaType.MERCH_PHOTO), }) - file: File, - @Params() params: UuidParam, - @Body() createCollectionRequest: CreateCollectionPhotoRequest, - @AuthenticatedUser() user: UserModel, + file: File, + @Params() params: UuidParam, + @Body() createCollectionRequest: CreateCollectionPhotoRequest, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canEditMerchStore(user)) throw new ForbiddenError(); // generate a random string for the uploaded photo url const position = parseInt(createCollectionRequest.position, 10); - if (Number.isNaN(position)) - throw new BadRequestError('Position must be a number'); + if (Number.isNaN(position)) throw new BadRequestError('Position must be a number'); const uniqueFileName = uuid(); const uploadedPhoto = await this.storageService.uploadToFolder( file, @@ -208,11 +202,10 @@ export class MerchStoreController { @Delete('/collection/picture/:uuid') async deleteMerchCollectionPhoto( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canEditMerchStore(user)) throw new ForbiddenError(); - const photoToDelete = - await this.merchStoreService.getCollectionPhotoForDeletion(params.uuid); + const photoToDelete = await this.merchStoreService.getCollectionPhotoForDeletion(params.uuid); await this.storageService.deleteAtUrl(photoToDelete.uploadedPhoto); await this.merchStoreService.deleteCollectionPhoto(photoToDelete); return { error: null }; @@ -221,10 +214,9 @@ export class MerchStoreController { @Get('/item/:uuid') async getOneMerchItem( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canAccessMerchStore(user)) - throw new ForbiddenError(); + if (!PermissionsService.canAccessMerchStore(user)) throw new ForbiddenError(); const item = await this.merchStoreService.findItemByUuid(params.uuid, user); return { error: null, item }; } @@ -232,7 +224,7 @@ export class MerchStoreController { @Post('/item') async createMerchItem( @Body() createItemRequest: CreateMerchItemRequest, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canEditMerchStore(user)) throw new ForbiddenError(); // Default behavior is to have variants disabled if not specified @@ -246,8 +238,8 @@ export class MerchStoreController { @Patch('/item/:uuid') async editMerchItem( @Params() params: UuidParam, - @Body() editItemRequest: EditMerchItemRequest, - @AuthenticatedUser() user: UserModel, + @Body() editItemRequest: EditMerchItemRequest, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canEditMerchStore(user)) throw new ForbiddenError(); const item = await this.merchStoreService.editItem( @@ -260,7 +252,7 @@ export class MerchStoreController { @Delete('/item/:uuid') async deleteMerchItem( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canEditMerchStore(user)) throw new ForbiddenError(); await this.merchStoreService.deleteItem(params.uuid); @@ -273,17 +265,16 @@ export class MerchStoreController { @UploadedFile('image', { options: StorageService.getFileOptions(MediaType.MERCH_PHOTO), }) - file: File, - @Params() params: UuidParam, - @Body() createItemPhotoRequest: CreateMerchItemPhotoRequest, - @AuthenticatedUser() user: UserModel, + file: File, + @Params() params: UuidParam, + @Body() createItemPhotoRequest: CreateMerchItemPhotoRequest, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canEditMerchStore(user)) throw new ForbiddenError(); // generate a random string for the uploaded photo url const position = Number(createItemPhotoRequest.position); - if (Number.isNaN(position)) - throw new BadRequestError('Position is not a number'); + if (Number.isNaN(position)) throw new BadRequestError('Position is not a number'); const uniqueFileName = uuid(); const uploadedPhoto = await this.storageService.uploadToFolder( file, @@ -303,7 +294,7 @@ export class MerchStoreController { @Delete('/item/picture/:uuid') async deleteMerchItemPhoto( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canEditMerchStore(user)) throw new ForbiddenError(); const photoToDelete = await this.merchStoreService.getItemPhotoForDeletion( @@ -317,8 +308,8 @@ export class MerchStoreController { @Post('/option/:uuid') async createMerchItemOption( @Params() params: UuidParam, - @Body() createItemOptionRequest: CreateMerchItemOptionRequest, - @AuthenticatedUser() user: UserModel, + @Body() createItemOptionRequest: CreateMerchItemOptionRequest, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canEditMerchStore(user)) throw new ForbiddenError(); const option = await this.merchStoreService.createItemOption( @@ -331,7 +322,7 @@ export class MerchStoreController { @Delete('/option/:uuid') async deleteMerchItemOption( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { if (!PermissionsService.canEditMerchStore(user)) throw new ForbiddenError(); await this.merchStoreService.deleteItemOption(params.uuid); @@ -341,17 +332,15 @@ export class MerchStoreController { @Get('/order/:uuid') async getOneMerchOrder( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canAccessMerchStore(user)) - throw new ForbiddenError(); + if (!PermissionsService.canAccessMerchStore(user)) throw new ForbiddenError(); // get "public" order bc canSeeMerchOrder need singular merchPhoto field // default order has merchPhotos field, which cause incorrect casting const publicOrder = ( await this.merchOrderService.findOrderByUuid(params.uuid) ).getPublicOrderWithItems(); - if (!PermissionsService.canSeeMerchOrder(user, publicOrder)) - throw new NotFoundError(); + if (!PermissionsService.canSeeMerchOrder(user, publicOrder)) throw new NotFoundError(); return { error: null, order: publicOrder }; } @@ -361,11 +350,10 @@ export class MerchStoreController { ): Promise { if ( !( - PermissionsService.canAccessMerchStore(user) && - PermissionsService.canSeeAllMerchOrders(user) + PermissionsService.canAccessMerchStore(user) + && PermissionsService.canSeeAllMerchOrders(user) ) - ) - throw new ForbiddenError(); + ) throw new ForbiddenError(); const orders = await this.merchOrderService.getAllOrdersForAllUsers(); return { error: null, orders: orders.map((o) => o.getPublicOrder()) }; } @@ -374,8 +362,7 @@ export class MerchStoreController { async getMerchOrdersForCurrentUser( @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canAccessMerchStore(user)) - throw new ForbiddenError(); + if (!PermissionsService.canAccessMerchStore(user)) throw new ForbiddenError(); const orders = await this.merchOrderService.getAllOrdersForUser(user); return { error: null, orders: orders.map((o) => o.getPublicOrder()) }; } @@ -383,10 +370,9 @@ export class MerchStoreController { @Post('/order') async placeMerchOrder( @Body() placeOrderRequest: PlaceMerchOrderRequest, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canAccessMerchStore(user)) - throw new ForbiddenError(); + if (!PermissionsService.canAccessMerchStore(user)) throw new ForbiddenError(); const originalOrder = this.validateMerchOrderRequest( placeOrderRequest.order, ); @@ -401,7 +387,7 @@ export class MerchStoreController { @Post('/order/verification') async verifyMerchOrder( @Body() verifyOrderRequest: VerifyMerchOrderRequest, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { const originalOrder = this.validateMerchOrderRequest( verifyOrderRequest.order, @@ -414,23 +400,20 @@ export class MerchStoreController { orderRequest: MerchItemOptionAndQuantity[], ): MerchItemOptionAndQuantity[] { const originalOrder = orderRequest.filter((oi) => oi.quantity > 0); - const orderIsEmpty = - originalOrder.reduce((x, n) => x + n.quantity, 0) === 0; + const orderIsEmpty = originalOrder.reduce((x, n) => x + n.quantity, 0) === 0; if (orderIsEmpty) throw new UserError('There are no items in this order'); const numUniqueUuids = new Set(originalOrder.map((oi) => oi.option)).size; - if (originalOrder.length !== numUniqueUuids) - throw new BadRequestError('There are duplicate items in this order'); + if (originalOrder.length !== numUniqueUuids) throw new BadRequestError('There are duplicate items in this order'); return originalOrder; } @Post('/order/:uuid/reschedule') async rescheduleOrderPickup( @Params() params: UuidParam, - @Body() rescheduleOrderPickupRequest: RescheduleOrderPickupRequest, - @AuthenticatedUser() user: UserModel, + @Body() rescheduleOrderPickupRequest: RescheduleOrderPickupRequest, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canAccessMerchStore(user)) - throw new ForbiddenError(); + if (!PermissionsService.canAccessMerchStore(user)) throw new ForbiddenError(); await this.merchOrderService.rescheduleOrderPickup( params.uuid, rescheduleOrderPickupRequest.pickupEvent, @@ -442,10 +425,9 @@ export class MerchStoreController { @Post('/order/:uuid/cancel') async cancelMerchOrder( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canAccessMerchStore(user)) - throw new ForbiddenError(); + if (!PermissionsService.canAccessMerchStore(user)) throw new ForbiddenError(); const order = await this.merchOrderService.cancelMerchOrder( params.uuid, user, @@ -456,11 +438,10 @@ export class MerchStoreController { @Post('/order/:uuid/fulfill') async fulfillMerchOrderItems( @Params() params: UuidParam, - @Body() fulfillOrderRequest: FulfillMerchOrderRequest, - @AuthenticatedUser() user: UserModel, + @Body() fulfillOrderRequest: FulfillMerchOrderRequest, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canManageMerchOrders(user)) - throw new ForbiddenError(); + if (!PermissionsService.canManageMerchOrders(user)) throw new ForbiddenError(); const numUniqueUuids = new Set( fulfillOrderRequest.items.map((oi) => oi.uuid), ).size; @@ -479,8 +460,7 @@ export class MerchStoreController { async cancelAllPendingMerchOrders( @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canCancelAllPendingOrders(user)) - throw new ForbiddenError(); + if (!PermissionsService.canCancelAllPendingOrders(user)) throw new ForbiddenError(); await this.merchOrderService.cancelAllPendingOrders(user); return { error: null }; } @@ -490,11 +470,9 @@ export class MerchStoreController { @AuthenticatedUser() user: UserModel, ): Promise { const pickupEvents = await this.merchOrderService.getPastPickupEvents(); - const canSeePickupEventOrders = - PermissionsService.canSeePickupEventOrders(user); + const canSeePickupEventOrders = PermissionsService.canSeePickupEventOrders(user); const publicPickupEvents = pickupEvents.map((pickupEvent) => - pickupEvent.getPublicOrderPickupEvent(canSeePickupEventOrders), - ); + pickupEvent.getPublicOrderPickupEvent(canSeePickupEventOrders)); return { error: null, pickupEvents: publicPickupEvents }; } @@ -503,21 +481,18 @@ export class MerchStoreController { @AuthenticatedUser() user: UserModel, ): Promise { const pickupEvents = await this.merchOrderService.getFuturePickupEvents(); - const canSeePickupEventOrders = - PermissionsService.canSeePickupEventOrders(user); + const canSeePickupEventOrders = PermissionsService.canSeePickupEventOrders(user); const publicPickupEvents = pickupEvents.map((pickupEvent) => - pickupEvent.getPublicOrderPickupEvent(canSeePickupEventOrders), - ); + pickupEvent.getPublicOrderPickupEvent(canSeePickupEventOrders)); return { error: null, pickupEvents: publicPickupEvents }; } @Get('/order/pickup/:uuid') async getOnePickupEvent( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canManagePickupEvents(user)) - throw new ForbiddenError(); + if (!PermissionsService.canManagePickupEvents(user)) throw new ForbiddenError(); const pickupEvent = await this.merchOrderService.getPickupEvent( params.uuid, ); @@ -530,10 +505,9 @@ export class MerchStoreController { @Post('/order/pickup') async createPickupEvent( @Body() createOrderPickupEventRequest: CreateOrderPickupEventRequest, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canManagePickupEvents(user)) - throw new ForbiddenError(); + if (!PermissionsService.canManagePickupEvents(user)) throw new ForbiddenError(); const pickupEvent = await this.merchOrderService.createPickupEvent( createOrderPickupEventRequest.pickupEvent, ); @@ -546,11 +520,10 @@ export class MerchStoreController { @Patch('/order/pickup/:uuid') async editPickupEvent( @Params() params: UuidParam, - @Body() editOrderPickupEventRequest: EditOrderPickupEventRequest, - @AuthenticatedUser() user: UserModel, + @Body() editOrderPickupEventRequest: EditOrderPickupEventRequest, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canManagePickupEvents(user)) - throw new ForbiddenError(); + if (!PermissionsService.canManagePickupEvents(user)) throw new ForbiddenError(); const pickupEvent = await this.merchOrderService.editPickupEvent( params.uuid, editOrderPickupEventRequest.pickupEvent, @@ -564,10 +537,9 @@ export class MerchStoreController { @Delete('/order/pickup/:uuid') async deletePickupEvent( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canManagePickupEvents(user)) - throw new ForbiddenError(); + if (!PermissionsService.canManagePickupEvents(user)) throw new ForbiddenError(); await this.merchOrderService.deletePickupEvent(params.uuid); return { error: null }; } @@ -575,10 +547,9 @@ export class MerchStoreController { @Post('/order/pickup/:uuid/cancel') async cancelPickupEvent( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canManagePickupEvents(user)) - throw new ForbiddenError(); + if (!PermissionsService.canManagePickupEvents(user)) throw new ForbiddenError(); await this.merchOrderService.cancelPickupEvent(params.uuid); return { error: null }; } @@ -586,12 +557,10 @@ export class MerchStoreController { @Post('/order/pickup/:uuid/complete') async completePickupEvent( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canManagePickupEvents(user)) - throw new ForbiddenError(); - const ordersMarkedAsMissed = - await this.merchOrderService.completePickupEvent(params.uuid); + if (!PermissionsService.canManagePickupEvents(user)) throw new ForbiddenError(); + const ordersMarkedAsMissed = await this.merchOrderService.completePickupEvent(params.uuid); return { error: null, orders: ordersMarkedAsMissed.map((order) => order.getPublicOrder()), @@ -601,10 +570,9 @@ export class MerchStoreController { @Get('/cart') async getCartItems( @Body() getCartRequest: GetCartRequest, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - if (!PermissionsService.canAccessMerchStore(user)) - throw new ForbiddenError(); + if (!PermissionsService.canAccessMerchStore(user)) throw new ForbiddenError(); const cartItems = await this.merchStoreService.getCartItems( getCartRequest.items, ); diff --git a/api/controllers/UserController.ts b/api/controllers/UserController.ts index c38bacd0..97eda42d 100644 --- a/api/controllers/UserController.ts +++ b/api/controllers/UserController.ts @@ -56,7 +56,7 @@ export class UserController { @Get('/:uuid/activity/') async getUserActivityStream( @Params() params: UuidParam, - @AuthenticatedUser() currentUser: UserModel, + @AuthenticatedUser() currentUser: UserModel, ): Promise { if (params.uuid === currentUser.uuid) { return this.getCurrentUserActivityStream(currentUser); @@ -74,8 +74,7 @@ export class UserController { async getCurrentUserActivityStream( @AuthenticatedUser() user: UserModel, ): Promise { - const activityStream = - await this.userAccountService.getCurrentUserActivityStream(user.uuid); + const activityStream = await this.userAccountService.getCurrentUserActivityStream(user.uuid); return { error: null, activity: activityStream.map((activity) => activity.getPublicActivity()), @@ -87,8 +86,8 @@ export class UserController { @UploadedFile('image', { options: StorageService.getFileOptions(MediaType.PROFILE_PICTURE), }) - file: File, - @AuthenticatedUser() user: UserModel, + file: File, + @AuthenticatedUser() user: UserModel, ): Promise { const profilePicture = await this.storageService.upload( file, @@ -105,7 +104,7 @@ export class UserController { @Get('/:uuid') async getUser( @Params() params: UuidParam, - @AuthenticatedUser() currentUser: UserModel, + @AuthenticatedUser() currentUser: UserModel, ): Promise { if (params.uuid === currentUser.uuid) { return this.getCurrentUser(currentUser); @@ -118,7 +117,7 @@ export class UserController { @Get('/handle/:handle') async getUserByHandle( @Params() params: UserHandleParam, - @AuthenticatedUser() currentUser: UserModel, + @AuthenticatedUser() currentUser: UserModel, ): Promise { if (params.handle === currentUser.handle) { return this.getCurrentUser(currentUser); @@ -139,7 +138,7 @@ export class UserController { @Patch() async patchCurrentUser( @Body() patchUserRequest: PatchUserRequest, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { const patchedUser = await this.userAccountService.update( user, @@ -151,43 +150,37 @@ export class UserController { @Post('/socialMedia') async insertSocialMediaForUser( @Body() insertSocialMediaRequest: InsertSocialMediaRequest, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - const userSocialMedia = - await this.userSocialMediaService.insertSocialMediaForUser( - user, - insertSocialMediaRequest.socialMedia, - ); + const userSocialMedia = await this.userSocialMediaService.insertSocialMediaForUser( + user, + insertSocialMediaRequest.socialMedia, + ); return { error: null, - userSocialMedia: userSocialMedia.map((socialMedia) => - socialMedia.getPublicSocialMedia(), - ), + userSocialMedia: userSocialMedia.map((socialMedia) => socialMedia.getPublicSocialMedia()), }; } @Patch('/socialMedia') async updateSocialMediaForUser( @Body() updateSocialMediaRequest: UpdateSocialMediaRequest, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { - const userSocialMedia = - await this.userSocialMediaService.updateSocialMediaByUuid( - user, - updateSocialMediaRequest.socialMedia, - ); + const userSocialMedia = await this.userSocialMediaService.updateSocialMediaByUuid( + user, + updateSocialMediaRequest.socialMedia, + ); return { error: null, - userSocialMedia: userSocialMedia.map((socialMedia) => - socialMedia.getPublicSocialMedia(), - ), + userSocialMedia: userSocialMedia.map((socialMedia) => socialMedia.getPublicSocialMedia()), }; } @Delete('/socialMedia/:uuid') async deleteSocialMediaForUser( @Params() params: UuidParam, - @AuthenticatedUser() user: UserModel, + @AuthenticatedUser() user: UserModel, ): Promise { await this.userSocialMediaService.deleteSocialMediaByUuid( user, diff --git a/services/AttendanceService.ts b/services/AttendanceService.ts index ed5606f6..e8089a2f 100644 --- a/services/AttendanceService.ts +++ b/services/AttendanceService.ts @@ -7,12 +7,7 @@ import { } from 'routing-controllers'; import { EntityManager } from 'typeorm'; import * as moment from 'moment'; -import { - ActivityType, - PublicAttendance, - PublicExpressCheckin, - Uuid, -} from '../types'; +import { ActivityType, PublicExpressCheckin, Uuid } from '../types'; import { Config } from '../config'; import { UserModel } from '../models/UserModel'; import { EventModel } from '../models/EventModel'; @@ -31,8 +26,7 @@ export default class AttendanceService { public async getAttendancesForEvent(event: Uuid): Promise { const attendances = await this.transactions.readOnly(async (txn) => - Repositories.attendance(txn).getAttendancesForEvent(event), - ); + Repositories.attendance(txn).getAttendancesForEvent(event)); return attendances; } @@ -40,8 +34,7 @@ export default class AttendanceService { user: UserModel, ): Promise { const attendances = await this.transactions.readOnly(async (txn) => - Repositories.attendance(txn).getAttendancesForUser(user), - ); + Repositories.attendance(txn).getAttendancesForUser(user)); return attendances; } @@ -72,8 +65,7 @@ export default class AttendanceService { const hasAlreadyAttended = await Repositories.attendance( txn, ).hasUserAttendedEvent(user, event); - if (hasAlreadyAttended) - throw new UserError('You have already attended this event'); + if (hasAlreadyAttended) throw new UserError('You have already attended this event'); const attendance = await this.writeEventAttendance( user, @@ -141,13 +133,12 @@ export default class AttendanceService { const isEmailInUse = await Repositories.user(txn).isEmailInUse(email); if (isEmailInUse) { throw new UserError( - 'This email already has an account registered to it. ' + - 'Please login to your account to check-in to this event!', + 'This email already has an account registered to it. ' + + 'Please login to your account to check-in to this event!', ); } - const pastExpressCheckin = - await expressCheckinRepository.getPastExpressCheckin(email); + const pastExpressCheckin = await expressCheckinRepository.getPastExpressCheckin(email); if (pastExpressCheckin) { if (pastExpressCheckin.event.uuid === event.uuid) { throw new UserError( @@ -155,14 +146,13 @@ export default class AttendanceService { ); } else { throw new UserError( - 'You have already done an express check-in before for a previous event. ' + - 'Please complete your account registration to attend this event!', + 'You have already done an express check-in before for a previous event. ' + + 'Please complete your account registration to attend this event!', ); } } - const expressCheckin = - await expressCheckinRepository.createExpressCheckin(email, event); + const expressCheckin = await expressCheckinRepository.createExpressCheckin(email, event); return expressCheckin.getPublicExpressCheckin(); }); } @@ -280,14 +270,16 @@ export default class AttendanceService { user, event, ); - if (!attendance) + if (!attendance) { throw new UserError( 'You must attend this event before submiting feedback', ); - if (attendance.feedback) + } + if (attendance.feedback) { throw new UserError( 'You cannot submit feedback for this event more than once', ); + } const twoDaysPastEventEnd = moment(event.end).add(2, 'days').valueOf(); if (moment.now() > twoDaysPastEventEnd) { @@ -296,8 +288,7 @@ export default class AttendanceService { ); } - const attendanceWithFeedback = - await attendanceRepository.submitEventFeedback(attendance, feedback); + const attendanceWithFeedback = await attendanceRepository.submitEventFeedback(attendance, feedback); const pointsEarned = Config.pointReward.EVENT_FEEDBACK_POINT_REWARD; await Repositories.activity(txn).logActivity({ user, diff --git a/services/EventService.ts b/services/EventService.ts index 4b0e5188..4091905c 100644 --- a/services/EventService.ts +++ b/services/EventService.ts @@ -3,7 +3,7 @@ import { InjectManager } from 'typeorm-typedi-extensions'; import { ForbiddenError, NotFoundError } from 'routing-controllers'; import { EntityManager } from 'typeorm'; import { EventModel } from '../models/EventModel'; -import { Uuid, PublicEvent, Event, EventSearchOptions } from '../types'; +import { Uuid, Event, EventSearchOptions } from '../types'; import Repositories, { TransactionsManager } from '../repositories'; import { UserError } from '../utils/Errors'; @@ -24,12 +24,9 @@ export default class EventService { public async create(event: Event): Promise { const eventCreated = await this.transactions.readWrite(async (txn) => { const eventRepository = Repositories.event(txn); - const isUnusedAttendanceCode = - await eventRepository.isUnusedAttendanceCode(event.attendanceCode); - if (!isUnusedAttendanceCode) - throw new UserError('Attendance code has already been used'); - if (event.start > event.end) - throw new UserError('Start date after end date'); + const isUnusedAttendanceCode = await eventRepository.isUnusedAttendanceCode(event.attendanceCode); + if (!isUnusedAttendanceCode) throw new UserError('Attendance code has already been used'); + if (event.start > event.end) throw new UserError('Start date after end date'); return eventRepository.upsertEvent(EventModel.create(event)); }); return eventCreated; @@ -38,9 +35,7 @@ export default class EventService { public async getAllEvents( options: EventSearchOptions, ): Promise { - const events = await this.transactions.readOnly(async (txn) => - Repositories.event(txn).getAllEvents(options), - ); + const events = await this.transactions.readOnly(async (txn) => Repositories.event(txn).getAllEvents(options)); return events; } @@ -48,25 +43,19 @@ export default class EventService { options: EventSearchOptions, ): Promise { options.reverse ??= true; - const events = await this.transactions.readOnly(async (txn) => - Repositories.event(txn).getPastEvents(options), - ); + const events = await this.transactions.readOnly(async (txn) => Repositories.event(txn).getPastEvents(options)); return events; } public async getFutureEvents( options: EventSearchOptions, ): Promise { - const events = await this.transactions.readOnly(async (txn) => - Repositories.event(txn).getFutureEvents(options), - ); + const events = await this.transactions.readOnly(async (txn) => Repositories.event(txn).getFutureEvents(options)); return events; } public async findByUuid(uuid: Uuid): Promise { - const event = await this.transactions.readOnly(async (txn) => - Repositories.event(txn).findByUuid(uuid), - ); + const event = await this.transactions.readOnly(async (txn) => Repositories.event(txn).findByUuid(uuid)); if (!event) throw new NotFoundError('Event not found'); return event; } @@ -80,10 +69,8 @@ export default class EventService { const currentEvent = await eventRepository.findByUuid(uuid); if (!currentEvent) throw new NotFoundError('Event not found'); if (changes.attendanceCode !== currentEvent.attendanceCode) { - const isUnusedAttendanceCode = - await eventRepository.isUnusedAttendanceCode(changes.attendanceCode); - if (!isUnusedAttendanceCode) - throw new UserError('Attendance code has already been used'); + const isUnusedAttendanceCode = await eventRepository.isUnusedAttendanceCode(changes.attendanceCode); + if (!isUnusedAttendanceCode) throw new UserError('Attendance code has already been used'); } return eventRepository.upsertEvent(currentEvent, changes); }); @@ -98,8 +85,7 @@ export default class EventService { const attendances = await Repositories.attendance( txn, ).getAttendancesForEvent(uuid); - if (attendances.length > 0) - throw new ForbiddenError('Cannot delete event that has attendances'); + if (attendances.length > 0) throw new ForbiddenError('Cannot delete event that has attendances'); await eventRepository.deleteEvent(event); }); } diff --git a/services/FeedbackService.ts b/services/FeedbackService.ts index 58921f16..3d766b53 100644 --- a/services/FeedbackService.ts +++ b/services/FeedbackService.ts @@ -6,7 +6,6 @@ import { FeedbackModel } from '../models/FeedbackModel'; import { UserModel } from '../models/UserModel'; import Repositories, { TransactionsManager } from '../repositories'; import { - PublicFeedback, Feedback, Uuid, ActivityType, @@ -31,7 +30,7 @@ export default class FeedbackService { return this.transactions.readOnly(async (txn) => { const feedbackRepository = Repositories.feedback(txn); if (canSeeAllFeedback) { - return await feedbackRepository.getAllFeedback(options); + return feedbackRepository.getAllFeedback(options); } const userFeedback = await feedbackRepository.getStandardUserFeedback( @@ -52,12 +51,12 @@ export default class FeedbackService { const feedbackRepository = Repositories.feedback(txn); - const hasAlreadySubmittedFeedback = - await feedbackRepository.hasUserSubmittedFeedback(user, event); - if (hasAlreadySubmittedFeedback) + const hasAlreadySubmittedFeedback = await feedbackRepository.hasUserSubmittedFeedback(user, event); + if (hasAlreadySubmittedFeedback) { throw new UserError( 'You have already submitted feedback for this event!', ); + } await Repositories.activity(txn).logActivity({ user, diff --git a/services/MerchStoreService.ts b/services/MerchStoreService.ts index fc75ff62..1b5de7e2 100644 --- a/services/MerchStoreService.ts +++ b/services/MerchStoreService.ts @@ -7,18 +7,14 @@ import * as moment from 'moment-timezone'; import { MerchandiseItemOptionModel } from '../models/MerchandiseItemOptionModel'; import { Uuid, - PublicMerchCollection, MerchCollection, MerchCollectionEdit, MerchItem, MerchItemOption, MerchItemEdit, - PublicMerchItemOption, OrderStatus, PublicMerchItemWithPurchaseLimits, - PublicMerchItemPhoto, MerchItemPhoto, - PublicMerchCollectionPhoto, MerchCollectionPhoto, } from '../types'; import { MerchandiseItemModel } from '../models/MerchandiseItemModel'; @@ -52,8 +48,7 @@ export default class MerchStoreService { // calculate monthly and lifetime remaining purchases for this item const merchOrderItemRepository = Repositories.merchOrderItem(txn); - const lifetimePurchaseHistory = - await merchOrderItemRepository.getPastItemOrdersByUser(user, item); + const lifetimePurchaseHistory = await merchOrderItemRepository.getPastItemOrdersByUser(user, item); const oneMonthAgo = new Date(moment().subtract(1, 'month').unix()); const pastMonthPurchaseHistory = lifetimePurchaseHistory.filter( (oi) => oi.order.orderedAt > oneMonthAgo, @@ -64,10 +59,8 @@ export default class MerchStoreService { const pastMonthCancelledItems = pastMonthPurchaseHistory.filter( (oi) => oi.order.status === OrderStatus.CANCELLED, ); - const lifetimeItemOrderCounts = - lifetimePurchaseHistory.length - lifetimeCancelledItems.length; - const pastMonthItemOrderCounts = - pastMonthPurchaseHistory.length - pastMonthCancelledItems.length; + const lifetimeItemOrderCounts = lifetimePurchaseHistory.length - lifetimeCancelledItems.length; + const pastMonthItemOrderCounts = pastMonthPurchaseHistory.length - pastMonthCancelledItems.length; const monthlyRemaining = item.monthlyLimit - pastMonthItemOrderCounts; const lifetimeRemaining = item.lifetimeLimit - lifetimeItemOrderCounts; @@ -85,11 +78,9 @@ export default class MerchStoreService { canSeeInactiveCollections = false, ): Promise { const collection = await this.transactions.readOnly(async (txn) => - Repositories.merchStoreCollection(txn).findByUuid(uuid), - ); + Repositories.merchStoreCollection(txn).findByUuid(uuid)); if (!collection) throw new NotFoundError('Merch collection not found'); - if (collection.archived && !canSeeInactiveCollections) - throw new ForbiddenError(); + if (collection.archived && !canSeeInactiveCollections) throw new ForbiddenError(); collection.collectionPhotos = collection.collectionPhotos.sort( (a, b) => a.position - b.position, ); @@ -104,8 +95,7 @@ export default class MerchStoreService { if (canSeeInactiveCollections) { return merchCollectionRepository.getAllCollections(); } - const collections = - await merchCollectionRepository.getAllActiveCollections(); + const collections = await merchCollectionRepository.getAllActiveCollections(); return collections; }); } @@ -113,11 +103,9 @@ export default class MerchStoreService { public async createCollection( collection: MerchCollection, ): Promise { - return this.transactions.readWrite(async (txn) => - Repositories.merchStoreCollection(txn).upsertMerchCollection( - MerchandiseCollectionModel.create(collection), - ), - ); + return this.transactions.readWrite(async (txn) => Repositories.merchStoreCollection(txn).upsertMerchCollection( + MerchandiseCollectionModel.create(collection), + )); } public async editCollection( @@ -129,11 +117,9 @@ export default class MerchStoreService { const currentCollection = await merchCollectionRepository.findByUuid( uuid, ); - if (!currentCollection) - throw new NotFoundError('Merch collection not found'); + if (!currentCollection) throw new NotFoundError('Merch collection not found'); - const { discountPercentage, collectionPhotos, ...changes } = - collectionEdit; + const { discountPercentage, collectionPhotos, ...changes } = collectionEdit; if (discountPercentage !== undefined) { await Repositories.merchStoreItemOption( @@ -171,11 +157,10 @@ export default class MerchStoreService { }); } - let updatedCollection = - await merchCollectionRepository.upsertMerchCollection( - currentCollection, - changes, - ); + let updatedCollection = await merchCollectionRepository.upsertMerchCollection( + currentCollection, + changes, + ); if (discountPercentage !== undefined || changes.archived !== undefined) { updatedCollection = await merchCollectionRepository.findByUuid(uuid); @@ -193,10 +178,11 @@ export default class MerchStoreService { const hasBeenOrderedFrom = await Repositories.merchOrderItem( txn, ).hasCollectionBeenOrderedFrom(uuid); - if (hasBeenOrderedFrom) + if (hasBeenOrderedFrom) { throw new UserError( 'This collection has been ordered from and cannot be deleted', ); + } return merchCollectionRepository.deleteMerchCollection(collection); }); } @@ -233,17 +219,15 @@ export default class MerchStoreService { ...properties, merchCollection, }); - const merchStoreCollectionPhotoRepository = - Repositories.merchStoreCollectionPhoto(txn); + const merchStoreCollectionPhotoRepository = Repositories.merchStoreCollectionPhoto(txn); // verify the result photos array merchCollection.collectionPhotos.push(createdPhoto); MerchStoreService.verifyCollectionHasValidPhotos(merchCollection); - const upsertedPhoto = - await merchStoreCollectionPhotoRepository.upsertCollectionPhoto( - createdPhoto, - ); + const upsertedPhoto = await merchStoreCollectionPhotoRepository.upsertCollectionPhoto( + createdPhoto, + ); return upsertedPhoto; }); } @@ -259,13 +243,11 @@ export default class MerchStoreService { uuid: Uuid, ): Promise { return this.transactions.readWrite(async (txn) => { - const merchCollectionPhotoRepository = - Repositories.merchStoreCollectionPhoto(txn); + const merchCollectionPhotoRepository = Repositories.merchStoreCollectionPhoto(txn); const collectionPhoto = await merchCollectionPhotoRepository.findByUuid( uuid, ); - if (!collectionPhoto) - throw new NotFoundError('Merch collection photo not found'); + if (!collectionPhoto) throw new NotFoundError('Merch collection photo not found'); const collection = await Repositories.merchStoreCollection( txn, @@ -288,8 +270,7 @@ export default class MerchStoreService { collectionPhoto: MerchCollectionPhotoModel, ): Promise { return this.transactions.readWrite(async (txn) => { - const merchStoreItemPhotoRepository = - Repositories.merchStoreCollectionPhoto(txn); + const merchStoreItemPhotoRepository = Repositories.merchStoreCollectionPhoto(txn); await merchStoreItemPhotoRepository.deleteCollectionPhoto( collectionPhoto, ); @@ -326,16 +307,16 @@ export default class MerchStoreService { ); } if ( - item.hasVariantsEnabled && - !MerchStoreService.allOptionsHaveValidMetadata(item.options) + item.hasVariantsEnabled + && !MerchStoreService.allOptionsHaveValidMetadata(item.options) ) { throw new UserError( 'Merch options for items with variants enabled must have valid metadata', ); } if ( - item.hasVariantsEnabled && - MerchStoreService.hasMultipleOptionTypes(item.options) + item.hasVariantsEnabled + && MerchStoreService.hasMultipleOptionTypes(item.options) ) { throw new UserError('Merch items cannot have multiple option types'); } @@ -448,8 +429,7 @@ export default class MerchStoreService { const hasBeenOrdered = await Repositories.merchOrderItem( txn, ).hasItemBeenOrdered(uuid); - if (hasBeenOrdered) - throw new UserError('This item has been ordered and cannot be deleted'); + if (hasBeenOrdered) throw new UserError('This item has been ordered and cannot be deleted'); return merchItemRepository.deleteMerchItem(item); }); } @@ -478,8 +458,7 @@ export default class MerchStoreService { merchItem.options.push(createdOption); MerchStoreService.verifyItemHasValidOptions(merchItem); - const upsertedOption = - await merchItemOptionRepository.upsertMerchItemOption(createdOption); + const upsertedOption = await merchItemOptionRepository.upsertMerchItemOption(createdOption); return upsertedOption; }); } @@ -499,10 +478,11 @@ export default class MerchStoreService { const hasBeenOrdered = await Repositories.merchOrderItem( txn, ).hasOptionBeenOrdered(uuid); - if (hasBeenOrdered) + if (hasBeenOrdered) { throw new UserError( 'This item option has been ordered and cannot be deleted', ); + } const item = await Repositories.merchStoreItem(txn).findByUuid( option.item.uuid, @@ -548,15 +528,13 @@ export default class MerchStoreService { ...properties, merchItem, }); - const merchStoreItemPhotoRepository = - Repositories.merchStoreItemPhoto(txn); + const merchStoreItemPhotoRepository = Repositories.merchStoreItemPhoto(txn); // verify the result photos array merchItem.merchPhotos.push(createdPhoto); MerchStoreService.verifyItemHasValidPhotos(merchItem); - const upsertedPhoto = - await merchStoreItemPhotoRepository.upsertMerchItemPhoto(createdPhoto); + const upsertedPhoto = await merchStoreItemPhotoRepository.upsertMerchItemPhoto(createdPhoto); return upsertedPhoto; }); } @@ -572,8 +550,7 @@ export default class MerchStoreService { uuid: Uuid, ): Promise { return this.transactions.readWrite(async (txn) => { - const merchStoreItemPhotoRepository = - Repositories.merchStoreItemPhoto(txn); + const merchStoreItemPhotoRepository = Repositories.merchStoreItemPhoto(txn); const merchPhoto = await merchStoreItemPhotoRepository.findByUuid(uuid); if (!merchPhoto) throw new NotFoundError('Merch item photo not found'); @@ -600,8 +577,7 @@ export default class MerchStoreService { merchPhoto: MerchandiseItemPhotoModel, ): Promise { return this.transactions.readWrite(async (txn) => { - const merchStoreItemPhotoRepository = - Repositories.merchStoreItemPhoto(txn); + const merchStoreItemPhotoRepository = Repositories.merchStoreItemPhoto(txn); await merchStoreItemPhotoRepository.deleteMerchItemPhoto(merchPhoto); return merchPhoto; }); diff --git a/services/UserAccountService.ts b/services/UserAccountService.ts index ac634fb5..6424b564 100644 --- a/services/UserAccountService.ts +++ b/services/UserAccountService.ts @@ -14,12 +14,12 @@ import { englishDataset, englishRecommendedTransformers, } from 'obscenity'; +import { ActivityModel } from 'models/ActivityModel'; import Repositories, { TransactionsManager } from '../repositories'; import { Uuid, PublicProfile, ActivityType, - PublicActivity, Milestone, UserPatches, UserState, @@ -28,7 +28,6 @@ import { } from '../types'; import { UserRepository } from '../repositories/UserRepository'; import { UserModel } from '../models/UserModel'; -import { ActivityModel } from 'models/ActivityModel'; @Service() export default class UserAccountService { @@ -45,20 +44,14 @@ export default class UserAccountService { } public async findByUuid(uuid: Uuid): Promise { - const user = await this.transactions.readOnly(async (txn) => - Repositories.user(txn).findByUuid(uuid), - ); - if (!user) - throw new NotFoundError('No user associated with this handle was found'); + const user = await this.transactions.readOnly(async (txn) => Repositories.user(txn).findByUuid(uuid)); + if (!user) throw new NotFoundError('No user associated with this handle was found'); return user; } public async findByHandle(handle: string): Promise { - const user = await this.transactions.readOnly(async (txn) => - Repositories.user(txn).findByHandle(handle), - ); - if (!user) - throw new NotFoundError('No user associated with this handle was found'); + const user = await this.transactions.readOnly(async (txn) => Repositories.user(txn).findByHandle(handle)); + if (!user) throw new NotFoundError('No user associated with this handle was found'); return user; } @@ -100,14 +93,13 @@ export default class UserAccountService { // where the possible range is from the earliest recorded points to the current day const earliest = await Repositories.activity(txn).getEarliestTimestamp(); // if left bound is after the earliest recorded points, round to the start of the day - if (from) - from = from > earliest ? moment(from).startOf('day').valueOf() : null; + if (from) from = from > earliest ? moment(from).startOf('day').valueOf() : null; // if right bound is before the current day, round to the end of the day - if (to) - to = - to <= moment().startOf('day').valueOf() - ? moment(to).endOf('day').valueOf() - : null; + if (to) { + to = to <= moment().startOf('day').valueOf() + ? moment(to).endOf('day').valueOf() + : null; + } const leaderboardRepository = Repositories.leaderboard(txn); // if unbounded, i.e. all-time @@ -133,8 +125,7 @@ export default class UserAccountService { ): Promise { const changes: Partial = userPatches; if (userPatches.passwordChange) { - const { password: currentPassword, newPassword } = - userPatches.passwordChange; + const { password: currentPassword, newPassword } = userPatches.passwordChange; if (!(await user.verifyPass(currentPassword))) { throw new BadRequestError('Incorrect password'); } @@ -149,8 +140,7 @@ export default class UserAccountService { const isHandleTaken = await userRepository.isHandleTaken( userPatches.handle, ); - if (isHandleTaken) - throw new BadRequestError('This handle is already in use.'); + if (isHandleTaken) throw new BadRequestError('This handle is already in use.'); } const updatedFields = Object.keys(userPatches).join(', '); const activity = { @@ -167,17 +157,14 @@ export default class UserAccountService { user: UserModel, profilePicture: string, ): Promise { - return this.transactions.readWrite(async (txn) => - Repositories.user(txn).upsertUser(user, { profilePicture }), - ); + return this.transactions.readWrite(async (txn) => Repositories.user(txn).upsertUser(user, { profilePicture })); } public async getCurrentUserActivityStream( uuid: Uuid, ): Promise { const stream = await this.transactions.readOnly(async (txn) => - Repositories.activity(txn).getCurrentUserActivityStream(uuid), - ); + Repositories.activity(txn).getCurrentUserActivityStream(uuid)); return stream; } @@ -226,9 +213,7 @@ export default class UserAccountService { } public async getAllNamesAndEmails(): Promise { - return this.transactions.readOnly(async (txn) => - Repositories.user(txn).getAllNamesAndEmails(), - ); + return this.transactions.readOnly(async (txn) => Repositories.user(txn).getAllNamesAndEmails()); } /** @@ -335,9 +320,7 @@ export default class UserAccountService { } public async getAllFullUserProfiles(): Promise { - const users = await this.transactions.readOnly(async (txn) => - Repositories.user(txn).findAll(), - ); + const users = await this.transactions.readOnly(async (txn) => Repositories.user(txn).findAll()); return users; } }