Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up module imports across repo #437

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
16 changes: 16 additions & 0 deletions aliases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { addAliases } from 'module-alias';

addAliases({
'@controllers': `${__dirname}/api/controllers`,
'@decorators': `${__dirname}/api/decorators`,
'@middleware': `${__dirname}/api/middleware`,
'@validators': `${__dirname}/api/validators`,
'@config': `${__dirname}/config`,
'@error': `${__dirname}/error`,
'@models': `${__dirname}/models`,
'@repositories': `${__dirname}/repositories`,
'@services': `${__dirname}/services`,
'@tests': `${__dirname}/tests`,
'@customtypes': `${__dirname}/types`,
'@utils': `${__dirname}/utils`,
});
echang594 marked this conversation as resolved.
Show resolved Hide resolved
25 changes: 11 additions & 14 deletions api/controllers/AdminController.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import { JsonController, Post, Patch, UploadedFile, UseBefore, ForbiddenError, Body, Get } from 'routing-controllers';
import { UserAuthentication } from '../middleware/UserAuthentication';
import {
CreateBonusRequest,
CreateMilestoneRequest,
SubmitAttendanceForUsersRequest,
ModifyUserAccessLevelRequest,
} from '../validators/AdminControllerRequests';
import {
File,
MediaType,
Expand All @@ -16,13 +9,17 @@ import {
SubmitAttendanceForUsersResponse,
ModifyUserAccessLevelResponse,
GetAllUserAccessLevelsResponse,
} from '../../types';
import { AuthenticatedUser } from '../decorators/AuthenticatedUser';
import UserAccountService from '../../services/UserAccountService';
import StorageService from '../../services/StorageService';
import PermissionsService from '../../services/PermissionsService';
import { UserModel } from '../../models/UserModel';
import AttendanceService from '../../services/AttendanceService';
} from '@customtypes';
import { UserAccountService, StorageService, PermissionsService, AttendanceService } from '@services';
import { UserModel } from '@models';
import {
CreateBonusRequest,
CreateMilestoneRequest,
SubmitAttendanceForUsersRequest,
ModifyUserAccessLevelRequest,
} from '@validators';
import { UserAuthentication } from '@middleware';
import { AuthenticatedUser } from '@decorators';

@UseBefore(UserAuthentication)
@JsonController('/admin')
Expand Down
15 changes: 6 additions & 9 deletions api/controllers/AttendanceController.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
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 { UserModel } from '../../models/UserModel';
import AttendanceService from '../../services/AttendanceService';
import PermissionsService from '../../services/PermissionsService';
import { GetAttendancesForEventResponse, GetAttendancesForUserResponse, AttendEventResponse } from '../../types';
import { UuidParam } from '../validators/GenericRequests';
import { GetAttendancesForEventResponse, GetAttendancesForUserResponse, AttendEventResponse } from '@customtypes';
import { EmailService, AttendanceService, PermissionsService } from '@services';
import { UserModel } from '@models';
import { UserAuthentication } from '@middleware';
import { AttendEventRequest, AttendViaExpressCheckinRequest, UuidParam } from '@validators';
import { AuthenticatedUser } from '@decorators';

@JsonController('/attendance')
export class AttendanceController {
Expand Down
21 changes: 9 additions & 12 deletions api/controllers/AuthController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@ import {
VerifyEmailResponse,
ResendEmailVerificationResponse,
EmailModificationResponse,
} from '../../types';
import UserAccountService from '../../services/UserAccountService';
import UserAuthService from '../../services/UserAuthService';
import { logger as log } from '../../utils/Logger';
import { RequestTrace } from '../decorators/RequestTrace';
import EmailService from '../../services/EmailService';
} from '@customtypes';
import { UserAccountService, UserAuthService, EmailService } from '@services';
import { UserModel } from '@models';
import {
LoginRequest,
RegistrationRequest,
PasswordResetRequest,
EmailModificationRequest,
} from '../validators/AuthControllerRequests';
import { authActionMetadata } from '../../utils/AuthActionMetadata';
import { OptionalUserAuthentication, UserAuthentication } from '../middleware/UserAuthentication';
import { AuthenticatedUser } from '../decorators/AuthenticatedUser';
import { UserModel } from '../../models/UserModel';
import { EmailParam, AccessCodeParam } from '../validators/GenericRequests';
EmailParam,
AccessCodeParam,
} from '@validators';
import { OptionalUserAuthentication, UserAuthentication } from '@middleware';
import { RequestTrace, AuthenticatedUser } from '@decorators';
import { logger as log, authActionMetadata } from '@utils';

@JsonController('/auth')
export class AuthController {
Expand Down
15 changes: 6 additions & 9 deletions api/controllers/EventController.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import {
JsonController, Get, Patch, Delete, Post, UseBefore, Params, ForbiddenError, QueryParams, UploadedFile, Body,
} from 'routing-controllers';
import EventService from '../../services/EventService';
import { UserAuthentication, OptionalUserAuthentication } from '../middleware/UserAuthentication';
import { AuthenticatedUser } from '../decorators/AuthenticatedUser';
import { UserModel } from '../../models/UserModel';
import PermissionsService from '../../services/PermissionsService';
import StorageService from '../../services/StorageService';
import AttendanceService from '../../services/AttendanceService';
import {
MediaType,
File,
Expand All @@ -19,8 +12,12 @@ import {
GetFutureEventsResponse,
GetAllEventsResponse,
GetPastEventsResponse,
} from '../../types';
import { UuidParam } from '../validators/GenericRequests';
} from '@customtypes';
import { EventService, PermissionsService, StorageService, AttendanceService } from '@services';
import { UserModel } from '@models';
import { UuidParam } from '@validators';
import { UserAuthentication, OptionalUserAuthentication } from '@middleware';
import { AuthenticatedUser } from '@decorators';
import {
EventSearchOptions,
PatchEventRequest,
Expand Down
26 changes: 17 additions & 9 deletions api/controllers/FeedbackController.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { Body, ForbiddenError, Get, JsonController, Params,
Patch, Post, UseBefore, QueryParams } from 'routing-controllers';
import { AuthenticatedUser } from '../decorators/AuthenticatedUser';
import { UserModel } from '../../models/UserModel';
import PermissionsService from '../../services/PermissionsService';
import FeedbackService from '../../services/FeedbackService';
import { GetFeedbackResponse, SubmitFeedbackResponse, UpdateFeedbackStatusResponse } from '../../types';
import { UuidParam } from '../validators/GenericRequests';
import { UserAuthentication } from '../middleware/UserAuthentication';
import {
Body,
ForbiddenError,
Get,
JsonController,
Params,
Patch,
Post,
UseBefore,
QueryParams,
} from 'routing-controllers';
import { GetFeedbackResponse, SubmitFeedbackResponse, UpdateFeedbackStatusResponse } from '@customtypes';
import { PermissionsService, FeedbackService } from '@services';
import { UserModel } from '@models';
import { UuidParam } from '@validators';
import { UserAuthentication } from '@middleware';
import { AuthenticatedUser } from '@decorators';
import {
SubmitFeedbackRequest,
UpdateFeedbackStatusRequest,
Expand Down
8 changes: 4 additions & 4 deletions api/controllers/LeaderboardController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { UseBefore, JsonController, Get, QueryParams } from 'routing-controllers';
import { GetLeaderboardResponse } from '../../types';
import { UserAuthentication } from '../middleware/UserAuthentication';
import UserAccountService from '../../services/UserAccountService';
import { SlidingLeaderboardQueryParams } from '../validators/LeaderboardControllerRequests';
import { GetLeaderboardResponse } from '@customtypes';
import { UserAccountService } from '@services';
import { SlidingLeaderboardQueryParams } from '@validators';
import { UserAuthentication } from '@middleware';

@UseBefore(UserAuthentication)
@JsonController('/leaderboard')
Expand Down
18 changes: 8 additions & 10 deletions api/controllers/MerchStoreController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {
UploadedFile,
} from 'routing-controllers';
import { v4 as uuid } from 'uuid';
import PermissionsService from '../../services/PermissionsService';
import { UserAuthentication } from '../middleware/UserAuthentication';
import {
GetOneMerchCollectionResponse,
GetAllMerchCollectionsResponse,
Expand Down Expand Up @@ -50,12 +48,11 @@ import {
GetOrderPickupEventResponse,
CancelOrderPickupEventResponse,
CancelMerchOrderResponse,
} from '../../types';
import { UuidParam } from '../validators/GenericRequests';
import { AuthenticatedUser } from '../decorators/AuthenticatedUser';
import { UserModel } from '../../models/UserModel';
import MerchStoreService from '../../services/MerchStoreService';
} from '@customtypes';
import { PermissionsService, MerchStoreService, StorageService } from '@services';
import { UserModel } from '@models';
import {
UuidParam,
CreateMerchCollectionRequest,
EditMerchCollectionRequest,
CreateCollectionPhotoRequest,
Expand All @@ -70,9 +67,10 @@ import {
CreateOrderPickupEventRequest,
EditOrderPickupEventRequest,
GetCartRequest,
} from '../validators/MerchStoreRequests';
import { UserError } from '../../utils/Errors';
import StorageService from '../../services/StorageService';
} from '@validators';
import { UserAuthentication } from '@middleware';
import { AuthenticatedUser } from '@decorators';
import { UserError } from '@utils';

@UseBefore(UserAuthentication)
@JsonController('/merch')
Expand Down
23 changes: 13 additions & 10 deletions api/controllers/ResumeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ import {
Delete,
} from 'routing-controllers';
import * as path from 'path';
import PermissionsService from '../../services/PermissionsService';
import StorageService from '../../services/StorageService';
import { UserAuthentication } from '../middleware/UserAuthentication';
import ResumeService from '../../services/ResumeService';
import { UserModel } from '../../models/UserModel';
import { AuthenticatedUser } from '../decorators/AuthenticatedUser';
import { File, MediaType, GetVisibleResumesResponse,
PatchResumeResponse, UpdateResumeResponse, DeleteResumeResponse } from '../../types';
import { PatchResumeRequest, UploadResumeRequest } from '../validators/ResumeControllerRequests';
import { UuidParam } from '../validators/GenericRequests';
import {
File,
MediaType,
GetVisibleResumesResponse,
PatchResumeResponse,
UpdateResumeResponse,
DeleteResumeResponse,
} from '@customtypes';
import { PermissionsService, StorageService, ResumeService } from '@services';
import { UserModel } from '@models';
import { UserAuthentication } from '@middleware';
import { PatchResumeRequest, UploadResumeRequest, UuidParam } from '@validators';
import { AuthenticatedUser } from '@decorators';

@UseBefore(UserAuthentication)
@JsonController('/resume')
Expand Down
19 changes: 9 additions & 10 deletions api/controllers/UserController.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import {
JsonController, Params, Get, Post, Patch, UseBefore, UploadedFile, Body, Delete,
} from 'routing-controllers';
import { UserModel } from '../../models/UserModel';
import UserAccountService from '../../services/UserAccountService';
import UserSocialMediaService from '../../services/UserSocialMediaService';
import StorageService from '../../services/StorageService';
import { UserAuthentication } from '../middleware/UserAuthentication';
import { AuthenticatedUser } from '../decorators/AuthenticatedUser';
import {
MediaType,
File,
Expand All @@ -18,13 +12,18 @@ import {
InsertSocialMediaResponse,
UpdateSocialMediaResponse,
DeleteSocialMediaResponse,
} from '../../types';
import { UserHandleParam, UuidParam } from '../validators/GenericRequests';
import { PatchUserRequest } from '../validators/UserControllerRequests';
} from '@customtypes';
import { UserAccountService, UserSocialMediaService, StorageService } from '@services';
import { UserModel } from '@models';
import {
UserHandleParam,
UuidParam,
PatchUserRequest,
InsertSocialMediaRequest,
UpdateSocialMediaRequest,
} from '../validators/UserSocialMediaControllerRequests';
} from '@validators';
import { UserAuthentication } from '@middleware';
import { AuthenticatedUser } from '@decorators';

@UseBefore(UserAuthentication)
@JsonController('/user')
Expand Down
15 changes: 13 additions & 2 deletions api/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { UserModel } from '../../models/UserModel';
import { UserModel } from '@models';
import { UserController } from './UserController';
import { AuthController } from './AuthController';
import { EventController } from './EventController';
Expand All @@ -13,7 +13,6 @@ import { ResumeController } from './ResumeController';
export const controllers = [
AuthController,
UserController,
ResumeController,
EventController,
AttendanceController,
LeaderboardController,
Expand All @@ -23,6 +22,18 @@ export const controllers = [
ResumeController,
];

export {
UserController,
AuthController,
EventController,
AttendanceController,
AdminController,
MerchStoreController,
LeaderboardController,
FeedbackController,
ResumeController,
};

// this merges our custom properties into Express's Request type
declare global {
namespace Express {
Expand Down
2 changes: 1 addition & 1 deletion api/decorators/Validators.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
ValidatorConstraintInterface, registerDecorator, ValidationOptions, ValidatorConstraint,
} from 'class-validator';
import { PasswordChange, FeedbackType, FeedbackStatus, OrderStatus, SocialMediaType } from '../../types';
import { PasswordChange, FeedbackType, FeedbackStatus, OrderStatus, SocialMediaType } from '@customtypes';

function templatedValidationDecorator(
validator: ValidatorConstraintInterface | Function, validationOptions?: ValidationOptions,
Expand Down
3 changes: 3 additions & 0 deletions api/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './AuthenticatedUser';
export * from './RequestTrace';
export * from './Validators';
2 changes: 1 addition & 1 deletion api/middleware/ErrorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as express from 'express';
import { ExpressErrorMiddlewareInterface, Middleware } from 'routing-controllers';
import { handleError } from '../../error';
import { handleError } from '@error';

@Middleware({ type: 'after' })
export class ErrorHandler implements ExpressErrorMiddlewareInterface {
Expand Down
2 changes: 1 addition & 1 deletion api/middleware/NotFoundHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ExpressMiddlewareInterface, NotFoundError, Middleware } from 'routing-controllers';
import * as express from 'express';
import { handleError } from '../../error';
import { handleError } from '@error';

@Middleware({ type: 'after' })
export class NotFoundHandler implements ExpressMiddlewareInterface {
Expand Down
5 changes: 2 additions & 3 deletions api/middleware/UserAuthentication.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ExpressMiddlewareInterface, ForbiddenError } from 'routing-controllers';
import * as express from 'express';
import { Inject } from 'typedi';
import UserAuthService from '../../services/UserAuthService';
import { authActionMetadata } from '../../utils/AuthActionMetadata';
import { logger as log } from '../../utils/Logger';
import { UserAuthService } from '@services';
import { authActionMetadata, logger as log } from '@utils';

export class UserAuthentication implements ExpressMiddlewareInterface {
@Inject()
Expand Down
3 changes: 3 additions & 0 deletions api/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { ErrorHandler } from './ErrorHandler';
import { NotFoundHandler } from './NotFoundHandler';
import { MetricsRecorder } from './MetricsRecorder';

export * from './UserAuthentication';

// not including UserAuthentication middlewares as part of global middlewares because it depends on the route
export const middlewares = [
ErrorHandler,
NotFoundHandler,
Expand Down
2 changes: 1 addition & 1 deletion api/validators/AdminControllerRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Bonus as IBonus,
UserAccessUpdates as IUserAccessUpdates,
UserAccessType,
} from '../../types';
} from '@customtypes';

const validUserAccessTypes = Object.values(UserAccessType);

Expand Down
2 changes: 1 addition & 1 deletion api/validators/AttendanceControllerRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IsDefined, IsNotEmpty, Allow, IsEmail } from 'class-validator';
import {
AttendEventRequest as IAttendEventRequest,
AttendViaExpressCheckinRequest as IAttendViaExpressCheckinRequest,
} from '../../types';
} from '@customtypes';

export class AttendEventRequest implements IAttendEventRequest {
@IsDefined()
Expand Down
Loading
Loading