From be1ee988dc482fe41d33c49ed8a3686811562cbf Mon Sep 17 00:00:00 2001 From: Eric Chang <55172722+echang594@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:44:45 -0700 Subject: [PATCH 1/5] Added barrel files --- api/controllers/AdminController.ts | 13 +++--- api/controllers/AttendanceController.ts | 13 +++--- api/controllers/AuthController.ts | 19 ++++----- api/controllers/EventController.ts | 13 +++--- api/controllers/FeedbackController.ts | 24 +++++++---- api/controllers/LeaderboardController.ts | 6 +-- api/controllers/MerchStoreController.ts | 16 ++++--- api/controllers/ResumeController.ts | 23 +++++----- api/controllers/UserController.ts | 17 ++++---- api/controllers/index.ts | 16 ++++++- api/decorators/index.ts | 3 ++ api/middleware/UserAuthentication.ts | 5 +-- api/middleware/index.ts | 3 ++ api/validators/AuthControllerRequests.ts | 2 +- api/validators/EventControllerRequests.ts | 2 +- api/validators/FeedbackControllerRequests.ts | 2 +- api/validators/GenericRequests.ts | 2 +- api/validators/UserControllerRequests.ts | 2 +- .../UserSocialMediaControllerRequests.ts | 2 +- api/validators/index.ts | 12 ++++++ config/index.ts | 2 + error/index.ts | 2 +- index.ts | 3 +- models/index.ts | 20 +++++++++ ormconfig.ts | 3 +- repositories/ActivityRepository.ts | 3 +- repositories/AttendanceRepository.ts | 5 +-- repositories/EventRepository.ts | 2 +- repositories/FeedbackRepository.ts | 4 +- repositories/LeaderboardRepository.ts | 3 +- repositories/MerchOrderRepository.ts | 6 +-- repositories/MerchStoreRepository.ts | 12 +++--- repositories/ResumeRepository.ts | 3 +- repositories/UserRepository.ts | 2 +- repositories/UserSocialMediaRepository.ts | 3 +- repositories/index.ts | 24 ++++++++++- services/AttendanceService.ts | 10 ++--- services/EmailService.ts | 4 +- services/EventService.ts | 8 ++-- services/FeedbackService.ts | 9 ++-- services/MerchStoreService.ts | 28 +++++++------ services/PermissionsService.ts | 4 +- services/ResumeService.ts | 7 ++-- services/StorageService.ts | 2 +- services/UserAccountService.ts | 9 ++-- services/UserAuthService.ts | 9 ++-- services/UserSocialMediaService.ts | 9 ++-- services/index.ts | 11 +++++ tests/Seeds.ts | 13 ++++-- tests/admin.test.ts | 2 +- tests/auth.test.ts | 18 ++++---- tests/controllers/ControllerFactory.ts | 42 ++++++++++--------- .../MerchStoreControllerWrapper.ts | 7 ++-- tests/controllers/index.ts | 1 + tests/data/EventFactory.ts | 4 +- tests/data/FactoryUtils.ts | 2 +- tests/data/FeedbackFactory.ts | 6 +-- tests/data/MerchFactory.ts | 16 +++---- tests/data/PortalState.ts | 32 +++++++------- tests/data/ResumeFactory.ts | 6 +-- tests/data/UserFactory.ts | 6 +-- tests/data/UserRegistrationFactory.ts | 4 +- tests/data/UserSocialMediaFactory.ts | 6 +-- tests/data/index.ts | 9 +++- tests/event.test.ts | 2 +- tests/expressCheckin.test.ts | 4 +- tests/feedback.test.ts | 3 +- tests/merchOrder.test.ts | 9 ++-- tests/merchStore.test.ts | 10 ++--- tests/mocks/MockFactory.ts | 4 +- tests/mocks/index.ts | 1 + tests/resume.test.ts | 9 ++-- tests/sample.test.ts | 19 +++++---- tests/user.handles.test.ts | 2 +- tests/userSocialMedia.test.ts | 7 ++-- types/ApiRequests.ts | 3 +- types/ApiResponses.ts | 16 ++++--- types/internal/index.ts | 6 +-- utils/AuthActionMetadata.ts | 2 +- utils/index.ts | 4 ++ 80 files changed, 379 insertions(+), 298 deletions(-) create mode 100644 api/decorators/index.ts create mode 100644 api/validators/index.ts create mode 100644 services/index.ts create mode 100644 tests/mocks/index.ts create mode 100644 utils/index.ts diff --git a/api/controllers/AdminController.ts b/api/controllers/AdminController.ts index 6ab761084..de9a3b897 100644 --- a/api/controllers/AdminController.ts +++ b/api/controllers/AdminController.ts @@ -1,11 +1,11 @@ import { JsonController, Post, Patch, UploadedFile, UseBefore, ForbiddenError, Body, Get } from 'routing-controllers'; -import { UserAuthentication } from '../middleware/UserAuthentication'; +import { UserAuthentication } from '../middleware'; import { CreateBonusRequest, CreateMilestoneRequest, SubmitAttendanceForUsersRequest, ModifyUserAccessLevelRequest, -} from '../validators/AdminControllerRequests'; +} from '../validators'; import { File, MediaType, @@ -17,12 +17,9 @@ import { 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'; +import { AuthenticatedUser } from '../decorators'; +import { UserAccountService, StorageService, PermissionsService, AttendanceService } from '../../services'; +import { UserModel } from '../../models'; @UseBefore(UserAuthentication) @JsonController('/admin') diff --git a/api/controllers/AttendanceController.ts b/api/controllers/AttendanceController.ts index ffc3c6c69..07c956fb0 100644 --- a/api/controllers/AttendanceController.ts +++ b/api/controllers/AttendanceController.ts @@ -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 { EmailService, AttendanceService, PermissionsService } from '../../services'; +import { UserAuthentication } from '../middleware'; +import { AuthenticatedUser } from '../decorators'; +import { AttendEventRequest, AttendViaExpressCheckinRequest, UuidParam } from '../validators'; +import { UserModel } from '../../models'; import { GetAttendancesForEventResponse, GetAttendancesForUserResponse, AttendEventResponse } from '../../types'; -import { UuidParam } from '../validators/GenericRequests'; @JsonController('/attendance') export class AttendanceController { diff --git a/api/controllers/AuthController.ts b/api/controllers/AuthController.ts index 61bef85c3..2d44b28bb 100644 --- a/api/controllers/AuthController.ts +++ b/api/controllers/AuthController.ts @@ -9,22 +9,19 @@ import { 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'; +import { UserAccountService, UserAuthService, EmailService } from '../../services'; +import { logger as log, authActionMetadata } from '../../utils'; +import { RequestTrace, AuthenticatedUser } from '../decorators'; 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 { UserModel } from '../../models'; @JsonController('/auth') export class AuthController { diff --git a/api/controllers/EventController.ts b/api/controllers/EventController.ts index ca9e2d2dd..9226cf7d3 100644 --- a/api/controllers/EventController.ts +++ b/api/controllers/EventController.ts @@ -1,13 +1,10 @@ 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 { EventService, PermissionsService, StorageService, AttendanceService } from '../../services'; +import { UserAuthentication, OptionalUserAuthentication } from '../middleware'; +import { AuthenticatedUser } from '../decorators'; +import { UserModel } from '../../models'; import { MediaType, File, @@ -20,7 +17,7 @@ import { GetAllEventsResponse, GetPastEventsResponse, } from '../../types'; -import { UuidParam } from '../validators/GenericRequests'; +import { UuidParam } from '../validators'; import { EventSearchOptions, PatchEventRequest, diff --git a/api/controllers/FeedbackController.ts b/api/controllers/FeedbackController.ts index 91db29213..18bd728f5 100644 --- a/api/controllers/FeedbackController.ts +++ b/api/controllers/FeedbackController.ts @@ -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 { + Body, + ForbiddenError, + Get, + JsonController, + Params, + Patch, + Post, + UseBefore, + QueryParams, +} from 'routing-controllers'; +import { AuthenticatedUser } from '../decorators'; +import { UserModel } from '../../models'; +import { PermissionsService, FeedbackService } from '../../services'; import { GetFeedbackResponse, SubmitFeedbackResponse, UpdateFeedbackStatusResponse } from '../../types'; -import { UuidParam } from '../validators/GenericRequests'; -import { UserAuthentication } from '../middleware/UserAuthentication'; +import { UuidParam } from '../validators'; +import { UserAuthentication } from '../middleware'; import { SubmitFeedbackRequest, UpdateFeedbackStatusRequest, diff --git a/api/controllers/LeaderboardController.ts b/api/controllers/LeaderboardController.ts index a4c598db5..3ef17f272 100644 --- a/api/controllers/LeaderboardController.ts +++ b/api/controllers/LeaderboardController.ts @@ -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 { UserAuthentication } from '../middleware'; +import { UserAccountService } from '../../services'; +import { SlidingLeaderboardQueryParams } from '../validators'; @UseBefore(UserAuthentication) @JsonController('/leaderboard') diff --git a/api/controllers/MerchStoreController.ts b/api/controllers/MerchStoreController.ts index 628d62e53..de81c926d 100644 --- a/api/controllers/MerchStoreController.ts +++ b/api/controllers/MerchStoreController.ts @@ -13,8 +13,8 @@ import { UploadedFile, } from 'routing-controllers'; import { v4 as uuid } from 'uuid'; -import PermissionsService from '../../services/PermissionsService'; -import { UserAuthentication } from '../middleware/UserAuthentication'; +import { PermissionsService, MerchStoreService, StorageService } from '../../services'; +import { UserAuthentication } from '../middleware'; import { GetOneMerchCollectionResponse, GetAllMerchCollectionsResponse, @@ -51,11 +51,8 @@ import { CancelOrderPickupEventResponse, CancelMerchOrderResponse, } from '../../types'; -import { UuidParam } from '../validators/GenericRequests'; -import { AuthenticatedUser } from '../decorators/AuthenticatedUser'; -import { UserModel } from '../../models/UserModel'; -import MerchStoreService from '../../services/MerchStoreService'; import { + UuidParam, CreateMerchCollectionRequest, EditMerchCollectionRequest, CreateCollectionPhotoRequest, @@ -70,9 +67,10 @@ import { CreateOrderPickupEventRequest, EditOrderPickupEventRequest, GetCartRequest, -} from '../validators/MerchStoreRequests'; -import { UserError } from '../../utils/Errors'; -import StorageService from '../../services/StorageService'; +} from '../validators'; +import { AuthenticatedUser } from '../decorators'; +import { UserModel } from '../../models'; +import { UserError } from '../../utils'; @UseBefore(UserAuthentication) @JsonController('/merch') diff --git a/api/controllers/ResumeController.ts b/api/controllers/ResumeController.ts index 58fbd37c7..cf7266af7 100644 --- a/api/controllers/ResumeController.ts +++ b/api/controllers/ResumeController.ts @@ -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 { PermissionsService, StorageService, ResumeService } from '../../services'; +import { UserAuthentication } from '../middleware'; +import { UserModel } from '../../models'; +import { AuthenticatedUser } from '../decorators'; +import { + File, + MediaType, + GetVisibleResumesResponse, + PatchResumeResponse, + UpdateResumeResponse, + DeleteResumeResponse, +} from '../../types'; +import { PatchResumeRequest, UploadResumeRequest, UuidParam } from '../validators'; @UseBefore(UserAuthentication) @JsonController('/resume') diff --git a/api/controllers/UserController.ts b/api/controllers/UserController.ts index 1ecb88e5f..b1e16c1b4 100644 --- a/api/controllers/UserController.ts +++ b/api/controllers/UserController.ts @@ -1,12 +1,10 @@ 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 { UserModel } from '../../models'; +import { UserAccountService, UserSocialMediaService, StorageService } from '../../services'; +import { UserAuthentication } from '../middleware'; +import { AuthenticatedUser } from '../decorators'; import { MediaType, File, @@ -19,12 +17,13 @@ import { UpdateSocialMediaResponse, DeleteSocialMediaResponse, } from '../../types'; -import { UserHandleParam, UuidParam } from '../validators/GenericRequests'; -import { PatchUserRequest } from '../validators/UserControllerRequests'; import { + UserHandleParam, + UuidParam, + PatchUserRequest, InsertSocialMediaRequest, UpdateSocialMediaRequest, -} from '../validators/UserSocialMediaControllerRequests'; +} from '../validators'; @UseBefore(UserAuthentication) @JsonController('/user') diff --git a/api/controllers/index.ts b/api/controllers/index.ts index 7f57e4e1d..0505a16be 100644 --- a/api/controllers/index.ts +++ b/api/controllers/index.ts @@ -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'; @@ -13,7 +13,6 @@ import { ResumeController } from './ResumeController'; export const controllers = [ AuthController, UserController, - ResumeController, EventController, AttendanceController, LeaderboardController, @@ -23,6 +22,19 @@ export const controllers = [ ResumeController, ]; +// can't export imports in the same line if imports are used in the file so must export separately +export { + UserController, + AuthController, + EventController, + AttendanceController, + AdminController, + MerchStoreController, + LeaderboardController, + FeedbackController, + ResumeController, +}; + // this merges our custom properties into Express's Request type declare global { namespace Express { diff --git a/api/decorators/index.ts b/api/decorators/index.ts new file mode 100644 index 000000000..607e39025 --- /dev/null +++ b/api/decorators/index.ts @@ -0,0 +1,3 @@ +export * from './AuthenticatedUser'; +export * from './RequestTrace'; +export * from './Validators'; diff --git a/api/middleware/UserAuthentication.ts b/api/middleware/UserAuthentication.ts index 245a3cc92..57e35a854 100644 --- a/api/middleware/UserAuthentication.ts +++ b/api/middleware/UserAuthentication.ts @@ -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() diff --git a/api/middleware/index.ts b/api/middleware/index.ts index 8907e8f08..d2ae9e23f 100644 --- a/api/middleware/index.ts +++ b/api/middleware/index.ts @@ -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, diff --git a/api/validators/AuthControllerRequests.ts b/api/validators/AuthControllerRequests.ts index c0053476a..1fa5a24e1 100644 --- a/api/validators/AuthControllerRequests.ts +++ b/api/validators/AuthControllerRequests.ts @@ -2,7 +2,7 @@ import { IsEmail, IsDefined, ValidateNested, Length } from 'class-validator'; import { Type } from 'class-transformer'; import { IsValidPassword, IsValidName, IsValidGraduationYear, IsValidMajor, HasMatchingPasswords, IsValidHandle, -} from '../decorators/Validators'; +} from '../decorators'; import { LoginRequest as ILoginRequest, RegistrationRequest as IRegistrationRequest, diff --git a/api/validators/EventControllerRequests.ts b/api/validators/EventControllerRequests.ts index 1a8a13064..556541567 100644 --- a/api/validators/EventControllerRequests.ts +++ b/api/validators/EventControllerRequests.ts @@ -9,7 +9,7 @@ import { Event as IEvent, Uuid, } from '../../types'; -import { IsValidEventFeedback } from '../decorators/Validators'; +import { IsValidEventFeedback } from '../decorators'; export class OptionalEventProperties implements IOptionalEventProperties { @IsNotEmpty() diff --git a/api/validators/FeedbackControllerRequests.ts b/api/validators/FeedbackControllerRequests.ts index da712713d..efde3feb9 100644 --- a/api/validators/FeedbackControllerRequests.ts +++ b/api/validators/FeedbackControllerRequests.ts @@ -1,6 +1,6 @@ import { Type } from 'class-transformer'; import { Allow, IsDefined, IsNotEmpty, MinLength, ValidateNested } from 'class-validator'; -import { IsValidFeedbackType, IsValidFeedbackStatus } from '../decorators/Validators'; +import { IsValidFeedbackType, IsValidFeedbackStatus } from '../decorators'; import { SubmitEventFeedbackRequest as ISubmitEventFeedbackRequest, SubmitFeedbackRequest as ISubmitFeedbackRequest, diff --git a/api/validators/GenericRequests.ts b/api/validators/GenericRequests.ts index 3cc757a56..a3c17fdce 100644 --- a/api/validators/GenericRequests.ts +++ b/api/validators/GenericRequests.ts @@ -1,5 +1,5 @@ import { Min, IsEmail, IsUUID, IsHexadecimal, Length } from 'class-validator'; -import { IsValidHandle } from '../decorators/Validators'; +import { IsValidHandle } from '../decorators'; import { Pagination as IPagination, Uuid } from '../../types'; export class Pagination implements IPagination { diff --git a/api/validators/UserControllerRequests.ts b/api/validators/UserControllerRequests.ts index f0b03f9be..5593c68dc 100644 --- a/api/validators/UserControllerRequests.ts +++ b/api/validators/UserControllerRequests.ts @@ -11,7 +11,7 @@ import { IsValidGraduationYear, HasMatchingPasswords, IsValidHandle, -} from '../decorators/Validators'; +} from '../decorators'; import { PasswordUpdate as IPasswordUpdate, PatchUserRequest as IPatchUserRequest, diff --git a/api/validators/UserSocialMediaControllerRequests.ts b/api/validators/UserSocialMediaControllerRequests.ts index 2f9a46721..e9f159dd7 100644 --- a/api/validators/UserSocialMediaControllerRequests.ts +++ b/api/validators/UserSocialMediaControllerRequests.ts @@ -1,6 +1,6 @@ import { Type } from 'class-transformer'; import { IsDefined, IsNotEmpty, ValidateNested } from 'class-validator'; -import { IsValidSocialMediaType } from '../decorators/Validators'; +import { IsValidSocialMediaType } from '../decorators'; import { InsertUserSocialMediaRequest as IInsertUserSocialMediaRequest, UpdateUserSocialMediaRequest as IUpdateUserSocialMediaRequest, diff --git a/api/validators/index.ts b/api/validators/index.ts new file mode 100644 index 000000000..f9902c1d9 --- /dev/null +++ b/api/validators/index.ts @@ -0,0 +1,12 @@ +export * from './AdminControllerRequests'; +export * from './AttendanceControllerRequests'; +export * from './AuthControllerRequests'; +// Clashing exports from EventControllerRequests and FeedbackControllerRequests, left unexported for now +// export * from './EventControllerRequests'; +// export * from './FeedbackControllerRequests'; +export * from './GenericRequests'; +export * from './LeaderboardControllerRequests'; +export * from './MerchStoreRequests'; +export * from './ResumeControllerRequests'; +export * from './UserControllerRequests'; +export * from './UserSocialMediaControllerRequests'; diff --git a/config/index.ts b/config/index.ts index b2a13d264..1ccc7f2e6 100644 --- a/config/index.ts +++ b/config/index.ts @@ -83,3 +83,5 @@ export const Config = { EVENT_FEEDBACK_POINT_REWARD: Number(process.env.EVENT_FEEDBACK_POINT_REWARD), }, }; + +export * from './DatabaseNamingStrategy'; diff --git a/error/index.ts b/error/index.ts index c86021d4f..65153014e 100644 --- a/error/index.ts +++ b/error/index.ts @@ -2,7 +2,7 @@ import * as express from 'express'; import { HttpError } from 'routing-controllers'; import { ApiResponse, CustomErrorBody } from '../types'; import { Config } from '../config'; -import { logger as log } from '../utils/Logger'; +import { logger as log } from '../utils'; export function handleError(error: Error, request: express.Request, diff --git a/index.ts b/index.ts index ed1aafffa..4a00ea3cb 100644 --- a/index.ts +++ b/index.ts @@ -7,8 +7,7 @@ import { Container } from 'typedi'; import { models as entities } from './models'; import { Config } from './config'; -import { InMemoryDatabaseCache } from './utils/InMemoryDatabaseCache'; -import { logger as log } from './utils/Logger'; +import { InMemoryDatabaseCache, logger as log } from './utils'; import { controllers } from './api/controllers'; import { middlewares } from './api/middleware'; diff --git a/models/index.ts b/models/index.ts index 0838f0588..6323f9989 100644 --- a/models/index.ts +++ b/models/index.ts @@ -33,3 +33,23 @@ export const models = [ UserSocialMediaModel, ExpressCheckinModel, ]; + +// can't export imports in the same line if imports are used in the file so must export separately +export { + UserModel, + FeedbackModel, + ActivityModel, + EventModel, + AttendanceModel, + MerchandiseCollectionModel, + MerchCollectionPhotoModel, + MerchandiseItemModel, + MerchandiseItemPhotoModel, + MerchandiseItemOptionModel, + OrderModel, + OrderItemModel, + OrderPickupEventModel, + ResumeModel, + UserSocialMediaModel, + ExpressCheckinModel, +}; diff --git a/ormconfig.ts b/ormconfig.ts index 8bf561c5d..9540aec0c 100644 --- a/ormconfig.ts +++ b/ormconfig.ts @@ -1,5 +1,4 @@ -import { Config } from './config'; -import { DatabaseNamingStrategy } from './config/DatabaseNamingStrategy'; +import { Config, DatabaseNamingStrategy } from './config'; module.exports = { type: 'postgres', diff --git a/repositories/ActivityRepository.ts b/repositories/ActivityRepository.ts index efda6780c..22c7e6189 100644 --- a/repositories/ActivityRepository.ts +++ b/repositories/ActivityRepository.ts @@ -1,8 +1,7 @@ import { EntityRepository, Raw } from 'typeorm'; import * as moment from 'moment'; import { ActivityScope, ActivityType, Uuid } from '../types'; -import { UserModel } from '../models/UserModel'; -import { ActivityModel } from '../models/ActivityModel'; +import { UserModel, ActivityModel } from '../models'; import { BaseRepository } from './BaseRepository'; import { Activity, ActivityTypeToScope } from '../types/internal'; diff --git a/repositories/AttendanceRepository.ts b/repositories/AttendanceRepository.ts index aa16270e2..5111bbc91 100644 --- a/repositories/AttendanceRepository.ts +++ b/repositories/AttendanceRepository.ts @@ -1,9 +1,6 @@ import { EntityRepository } from 'typeorm'; -import { ExpressCheckinModel } from '../models/ExpressCheckinModel'; +import { ExpressCheckinModel, AttendanceModel, UserModel, EventModel } from '../models'; import { Uuid } from '../types'; -import { AttendanceModel } from '../models/AttendanceModel'; -import { UserModel } from '../models/UserModel'; -import { EventModel } from '../models/EventModel'; import { BaseRepository } from './BaseRepository'; import { Attendance } from '../types/internal'; diff --git a/repositories/EventRepository.ts b/repositories/EventRepository.ts index 70b488102..623245615 100644 --- a/repositories/EventRepository.ts +++ b/repositories/EventRepository.ts @@ -1,6 +1,6 @@ import { EntityRepository, SelectQueryBuilder } from 'typeorm'; import { EventSearchOptions, Uuid } from '../types'; -import { EventModel } from '../models/EventModel'; +import { EventModel } from '../models'; import { BaseRepository } from './BaseRepository'; @EntityRepository(EventModel) diff --git a/repositories/FeedbackRepository.ts b/repositories/FeedbackRepository.ts index aa6250d46..58d3dce52 100644 --- a/repositories/FeedbackRepository.ts +++ b/repositories/FeedbackRepository.ts @@ -1,7 +1,5 @@ import { EntityRepository, SelectQueryBuilder } from 'typeorm'; -import { FeedbackModel } from '../models/FeedbackModel'; -import { UserModel } from '../models/UserModel'; -import { EventModel } from '../models/EventModel'; +import { FeedbackModel, UserModel, EventModel } from '../models'; import { BaseRepository } from './BaseRepository'; import { FeedbackSearchOptions, Uuid } from '../types'; diff --git a/repositories/LeaderboardRepository.ts b/repositories/LeaderboardRepository.ts index 4e1db9db0..d05ada314 100644 --- a/repositories/LeaderboardRepository.ts +++ b/repositories/LeaderboardRepository.ts @@ -1,8 +1,7 @@ import { EntityRepository, Not, Raw } from 'typeorm'; import * as moment from 'moment'; import { Config } from '../config'; -import { ActivityModel } from '../models/ActivityModel'; -import { UserModel } from '../models/UserModel'; +import { ActivityModel, UserModel } from '../models'; import { UserState } from '../types'; import { BaseRepository } from './BaseRepository'; diff --git a/repositories/MerchOrderRepository.ts b/repositories/MerchOrderRepository.ts index 769ceefda..d4980f0c2 100644 --- a/repositories/MerchOrderRepository.ts +++ b/repositories/MerchOrderRepository.ts @@ -1,11 +1,7 @@ import { EntityRepository, In, SelectQueryBuilder } from 'typeorm'; import { OrderStatus, Uuid } from '../types'; -import { OrderModel } from '../models/OrderModel'; -import { UserModel } from '../models/UserModel'; -import { OrderItemModel } from '../models/OrderItemModel'; -import { OrderPickupEventModel } from '../models/OrderPickupEventModel'; +import { OrderModel, UserModel, OrderItemModel, OrderPickupEventModel, MerchandiseItemModel } from '../models'; import { BaseRepository } from './BaseRepository'; -import { MerchandiseItemModel } from '../models/MerchandiseItemModel'; @EntityRepository(OrderModel) export class MerchOrderRepository extends BaseRepository { diff --git a/repositories/MerchStoreRepository.ts b/repositories/MerchStoreRepository.ts index 0eedb4b7c..54f89fa49 100644 --- a/repositories/MerchStoreRepository.ts +++ b/repositories/MerchStoreRepository.ts @@ -1,9 +1,11 @@ import { EntityRepository, SelectQueryBuilder } from 'typeorm'; -import { MerchandiseItemOptionModel } from '../models/MerchandiseItemOptionModel'; -import { MerchandiseItemPhotoModel } from '../models/MerchandiseItemPhotoModel'; -import { MerchandiseCollectionModel } from '../models/MerchandiseCollectionModel'; -import { MerchCollectionPhotoModel } from '../models/MerchCollectionPhotoModel'; -import { MerchandiseItemModel } from '../models/MerchandiseItemModel'; +import { + MerchandiseItemOptionModel, + MerchandiseItemPhotoModel, + MerchandiseCollectionModel, + MerchCollectionPhotoModel, + MerchandiseItemModel, +} from '../models'; import { Uuid } from '../types'; import { BaseRepository } from './BaseRepository'; diff --git a/repositories/ResumeRepository.ts b/repositories/ResumeRepository.ts index 538c68bee..822f62f2b 100644 --- a/repositories/ResumeRepository.ts +++ b/repositories/ResumeRepository.ts @@ -1,7 +1,6 @@ import { EntityRepository } from 'typeorm'; -import { ResumeModel } from '../models/ResumeModel'; +import { ResumeModel, UserModel } from '../models'; import { BaseRepository } from './BaseRepository'; -import { UserModel } from '../models/UserModel'; @EntityRepository(ResumeModel) export class ResumeRepository extends BaseRepository { diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index 95eb5934a..f04c1881f 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -1,7 +1,7 @@ import { EntityRepository, In } from 'typeorm'; import * as bcrypt from 'bcrypt'; import { Activity } from '../types/internal'; -import { UserModel } from '../models/UserModel'; +import { UserModel } from '../models'; import { Uuid } from '../types'; import { BaseRepository } from './BaseRepository'; diff --git a/repositories/UserSocialMediaRepository.ts b/repositories/UserSocialMediaRepository.ts index 4554ed10b..7ebc514b0 100644 --- a/repositories/UserSocialMediaRepository.ts +++ b/repositories/UserSocialMediaRepository.ts @@ -1,7 +1,6 @@ import { EntityRepository } from 'typeorm'; import { SocialMediaType, Uuid } from 'types'; -import { UserSocialMediaModel } from '../models/UserSocialMediaModel'; -import { UserModel } from '../models/UserModel'; +import { UserSocialMediaModel, UserModel } from '../models'; import { BaseRepository } from './BaseRepository'; @EntityRepository(UserSocialMediaModel) diff --git a/repositories/index.ts b/repositories/index.ts index 9ede2b5c5..c1bfb36d9 100644 --- a/repositories/index.ts +++ b/repositories/index.ts @@ -20,7 +20,7 @@ import { UserSocialMediaRepository } from './UserSocialMediaRepository'; const HINT_FOR_RETRIABLE_TRANSACTIONS : string = 'The transaction might succeed if retried.'; const AMOUNT_OF_RETRIES : number = 10; -export default class Repositories { +export class Repositories { public static activity(transactionalEntityManager: EntityManager): ActivityRepository { return transactionalEntityManager.getCustomRepository(ActivityRepository); } @@ -128,3 +128,25 @@ export class TransactionsManager { }); } } + +export { + ActivityRepository, + AttendanceRepository, + ExpressCheckinRepository, + EventRepository, + FeedbackRepository, + LeaderboardRepository, + MerchOrderRepository, + OrderItemRepository, + OrderPickupEventRepository, + MerchCollectionRepository, + MerchCollectionPhotoRepository, + MerchItemRepository, + MerchItemOptionRepository, + MerchItemPhotoRepository, + ResumeRepository, + UserRepository, + UserSocialMediaRepository, +}; + +export { BaseRepository } from './BaseRepository'; diff --git a/services/AttendanceService.ts b/services/AttendanceService.ts index 166ef16f8..6f61ac54e 100644 --- a/services/AttendanceService.ts +++ b/services/AttendanceService.ts @@ -5,15 +5,13 @@ import { EntityManager } from 'typeorm'; import * as moment from 'moment'; import { ActivityType, PublicAttendance, PublicExpressCheckin, Uuid } from '../types'; import { Config } from '../config'; -import { UserModel } from '../models/UserModel'; -import { EventModel } from '../models/EventModel'; -import { AttendanceModel } from '../models/AttendanceModel'; -import { UserError } from '../utils/Errors'; -import Repositories, { TransactionsManager } from '../repositories'; +import { UserModel, EventModel, AttendanceModel } from '../models'; +import { UserError } from '../utils'; +import { Repositories, TransactionsManager } from '../repositories'; import { Activity, Attendance } from '../types/internal'; @Service() -export default class AttendanceService { +export class AttendanceService { private transactions: TransactionsManager; constructor(@InjectManager() entityManager: EntityManager) { diff --git a/services/EmailService.ts b/services/EmailService.ts index ac99929cd..098631ba9 100644 --- a/services/EmailService.ts +++ b/services/EmailService.ts @@ -2,13 +2,13 @@ import { MailService, MailDataRequired } from '@sendgrid/mail'; import * as ejs from 'ejs'; import * as fs from 'fs'; import * as path from 'path'; -import { logger as log } from '../utils/Logger'; +import { logger as log } from '../utils'; import { Config } from '../config'; import { Uuid } from '../types'; type EmailData = MailDataRequired; -export default class EmailService { +export class EmailService { private readonly mailer = new MailService(); private static readonly itemDisplayTemplate = EmailService.readTemplate('itemDisplay.ejs'); diff --git a/services/EventService.ts b/services/EventService.ts index 9994e080e..fa6a5aee8 100644 --- a/services/EventService.ts +++ b/services/EventService.ts @@ -2,13 +2,13 @@ import { Service } from 'typedi'; import { InjectManager } from 'typeorm-typedi-extensions'; import { ForbiddenError, NotFoundError } from 'routing-controllers'; import { EntityManager } from 'typeorm'; -import { EventModel } from '../models/EventModel'; +import { EventModel } from '../models'; import { Uuid, PublicEvent, Event, EventSearchOptions } from '../types'; -import Repositories, { TransactionsManager } from '../repositories'; -import { UserError } from '../utils/Errors'; +import { Repositories, TransactionsManager } from '../repositories'; +import { UserError } from '../utils'; @Service() -export default class EventService { +export class EventService { private transactions: TransactionsManager; constructor(@InjectManager() entityManager: EntityManager) { diff --git a/services/FeedbackService.ts b/services/FeedbackService.ts index f8d5f059c..2174d1099 100644 --- a/services/FeedbackService.ts +++ b/services/FeedbackService.ts @@ -2,14 +2,13 @@ import { Service } from 'typedi'; import { EntityManager } from 'typeorm'; import { InjectManager } from 'typeorm-typedi-extensions'; import { NotFoundError } from 'routing-controllers'; -import { FeedbackModel } from '../models/FeedbackModel'; -import { UserModel } from '../models/UserModel'; -import Repositories, { TransactionsManager } from '../repositories'; +import { FeedbackModel, UserModel } from '../models'; +import { Repositories, TransactionsManager } from '../repositories'; import { PublicFeedback, Feedback, Uuid, ActivityType, FeedbackStatus, FeedbackSearchOptions } from '../types'; -import { UserError } from '../utils/Errors'; +import { UserError } from '../utils'; @Service() -export default class FeedbackService { +export class FeedbackService { private transactions: TransactionsManager; constructor(@InjectManager() entityManager: EntityManager) { diff --git a/services/MerchStoreService.ts b/services/MerchStoreService.ts index b32839c39..0de2327ce 100644 --- a/services/MerchStoreService.ts +++ b/services/MerchStoreService.ts @@ -5,7 +5,18 @@ import { EntityManager } from 'typeorm'; import { difference, flatten, intersection } from 'underscore'; import * as moment from 'moment-timezone'; import { MerchItemWithQuantity, OrderItemPriceAndQuantity } from 'types/internal'; -import { MerchandiseItemOptionModel } from '../models/MerchandiseItemOptionModel'; +import { + MerchandiseItemOptionModel, + MerchandiseItemModel, + OrderModel, + UserModel, + EventModel, + MerchandiseCollectionModel, + MerchCollectionPhotoModel, + OrderItemModel, + OrderPickupEventModel, + MerchandiseItemPhotoModel, +} from '../models'; import { Uuid, PublicMerchCollection, @@ -28,21 +39,12 @@ import { PublicMerchCollectionPhoto, MerchCollectionPhoto, } from '../types'; -import { MerchandiseItemModel } from '../models/MerchandiseItemModel'; -import { OrderModel } from '../models/OrderModel'; -import { UserModel } from '../models/UserModel'; -import { EventModel } from '../models/EventModel'; -import Repositories, { TransactionsManager } from '../repositories'; -import { MerchandiseCollectionModel } from '../models/MerchandiseCollectionModel'; -import { MerchCollectionPhotoModel } from '../models/MerchCollectionPhotoModel'; +import { Repositories, TransactionsManager } from '../repositories'; import EmailService, { OrderInfo, OrderPickupEventInfo } from './EmailService'; -import { UserError } from '../utils/Errors'; -import { OrderItemModel } from '../models/OrderItemModel'; -import { OrderPickupEventModel } from '../models/OrderPickupEventModel'; -import { MerchandiseItemPhotoModel } from '../models/MerchandiseItemPhotoModel'; +import { UserError } from '../utils'; @Service() -export default class MerchStoreService { +export class MerchStoreService { private static readonly MAX_MERCH_PHOTO_COUNT = 5; private static readonly MAX_COLLECTION_PHOTO_COUNT = 5; diff --git a/services/PermissionsService.ts b/services/PermissionsService.ts index 21cef53af..76a105f6d 100644 --- a/services/PermissionsService.ts +++ b/services/PermissionsService.ts @@ -1,9 +1,9 @@ import { Service } from 'typedi'; -import { UserModel } from '../models/UserModel'; +import { UserModel } from '../models'; import { UserState, PublicOrder } from '../types'; @Service() -export default class PermissionsService { +export class PermissionsService { public static canEditEvents(user: UserModel): boolean { return user.isAdmin() || user.isMarketing(); } diff --git a/services/ResumeService.ts b/services/ResumeService.ts index 756d59629..0fbcaaf1e 100644 --- a/services/ResumeService.ts +++ b/services/ResumeService.ts @@ -3,12 +3,11 @@ import { Service } from 'typedi'; import { EntityManager } from 'typeorm'; import { InjectManager } from 'typeorm-typedi-extensions'; import { ActivityType, ResumePatches } from '../types'; -import { ResumeModel } from '../models/ResumeModel'; -import { UserModel } from '../models/UserModel'; -import Repositories, { TransactionsManager } from '../repositories'; +import { ResumeModel, UserModel } from '../models'; +import { Repositories, TransactionsManager } from '../repositories'; @Service() -export default class ResumeService { +export class ResumeService { private transactions: TransactionsManager; constructor(@InjectManager() entityManager: EntityManager) { diff --git a/services/StorageService.ts b/services/StorageService.ts index 647c34131..07d115896 100644 --- a/services/StorageService.ts +++ b/services/StorageService.ts @@ -17,7 +17,7 @@ interface MediaTypeConfig { } @Service() -export default class StorageService { +export class StorageService { private s3 = new aws.S3({ apiVersion: '2006-03-01', region: Config.s3.region, diff --git a/services/UserAccountService.ts b/services/UserAccountService.ts index d59e2d964..83a2f4f78 100644 --- a/services/UserAccountService.ts +++ b/services/UserAccountService.ts @@ -4,13 +4,13 @@ import { InjectManager } from 'typeorm-typedi-extensions'; import { EntityManager } from 'typeorm'; import * as moment from 'moment'; import * as faker from 'faker'; -import { UserAccessUpdates } from 'api/validators/AdminControllerRequests'; +import { UserAccessUpdates } from 'api/validators'; import { RegExpMatcher, englishDataset, englishRecommendedTransformers, } from 'obscenity'; -import Repositories, { TransactionsManager } from '../repositories'; +import { Repositories, TransactionsManager, UserRepository } from '../repositories'; import { Uuid, PublicProfile, @@ -21,11 +21,10 @@ import { UserState, PrivateProfile, } from '../types'; -import { UserRepository } from '../repositories/UserRepository'; -import { UserModel } from '../models/UserModel'; +import { UserModel } from '../models'; @Service() -export default class UserAccountService { +export class UserAccountService { private transactions: TransactionsManager; private matcher: RegExpMatcher; diff --git a/services/UserAuthService.ts b/services/UserAuthService.ts index 0565fa73b..b358c9ac5 100644 --- a/services/UserAuthService.ts +++ b/services/UserAuthService.ts @@ -4,12 +4,11 @@ import * as crypto from 'crypto'; import * as jwt from 'jsonwebtoken'; import { InjectManager } from 'typeorm-typedi-extensions'; import { EntityManager } from 'typeorm'; -import { ExpressCheckinModel } from 'models/ExpressCheckinModel'; -import { UserRepository } from '../repositories/UserRepository'; +import { ExpressCheckinModel } from 'models'; +import { Repositories, UserRepository, TransactionsManager } from '../repositories'; import { Uuid, ActivityType, UserState, UserRegistration } from '../types'; import { Config } from '../config'; -import { UserModel } from '../models/UserModel'; -import Repositories, { TransactionsManager } from '../repositories'; +import { UserModel } from '../models'; import UserAccountService from './UserAccountService'; interface AuthToken { @@ -18,7 +17,7 @@ interface AuthToken { } @Service() -export default class UserAuthService { +export class UserAuthService { private transactions: TransactionsManager; constructor(@InjectManager() entityManager: EntityManager) { diff --git a/services/UserSocialMediaService.ts b/services/UserSocialMediaService.ts index 2f59e5e76..20521eee4 100644 --- a/services/UserSocialMediaService.ts +++ b/services/UserSocialMediaService.ts @@ -2,14 +2,13 @@ import { Service } from 'typedi'; import { EntityManager } from 'typeorm'; import { InjectManager } from 'typeorm-typedi-extensions'; import { ForbiddenError, NotFoundError } from 'routing-controllers'; -import { UserError } from '../utils/Errors'; -import { UserSocialMediaModel } from '../models/UserSocialMediaModel'; -import { UserModel } from '../models/UserModel'; -import Repositories, { TransactionsManager } from '../repositories'; +import { UserError } from '../utils'; +import { UserSocialMediaModel, UserModel } from '../models'; +import { Repositories, TransactionsManager } from '../repositories'; import { Uuid, SocialMedia, SocialMediaPatches } from '../types'; @Service() -export default class UserSocialMediaService { +export class UserSocialMediaService { private transactions: TransactionsManager; constructor(@InjectManager() entityManager: EntityManager) { diff --git a/services/index.ts b/services/index.ts new file mode 100644 index 000000000..bc43dc0b6 --- /dev/null +++ b/services/index.ts @@ -0,0 +1,11 @@ +export * from './AttendanceService'; +export * from './EmailService'; +export * from './EventService'; +export * from './FeedbackService'; +export * from './MerchStoreService'; +export * from './PermissionsService'; +export * from './ResumeService'; +export * from './StorageService'; +export * from './UserAccountService'; +export * from './UserAuthService'; +export * from './UserSocialMediaService'; diff --git a/tests/Seeds.ts b/tests/Seeds.ts index 979db0fc7..b26a139bf 100644 --- a/tests/Seeds.ts +++ b/tests/Seeds.ts @@ -1,8 +1,15 @@ import * as moment from 'moment'; import { UserAccessType, SocialMediaType, FeedbackStatus, FeedbackType } from '../types'; -import { DatabaseConnection, EventFactory, MerchFactory, - PortalState, UserFactory, ResumeFactory, UserSocialMediaFactory } from './data'; -import { FeedbackFactory } from './data/FeedbackFactory'; +import { + DatabaseConnection, + EventFactory, + MerchFactory, + PortalState, + UserFactory, + ResumeFactory, + UserSocialMediaFactory, + FeedbackFactory, +} from './data'; function getGraduationYear(n: number) { return moment().year() + n; diff --git a/tests/admin.test.ts b/tests/admin.test.ts index 8c697a580..94878a0c2 100644 --- a/tests/admin.test.ts +++ b/tests/admin.test.ts @@ -3,7 +3,7 @@ import { In } from 'typeorm'; import { ActivityScope, ActivityType, SubmitAttendanceForUsersRequest, UserAccessType } from '../types'; import { ControllerFactory } from './controllers'; import { DatabaseConnection, EventFactory, PortalState, UserFactory } from './data'; -import { UserModel } from '../models/UserModel'; +import { UserModel } from '../models'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/auth.test.ts b/tests/auth.test.ts index cb935ab57..fb6327820 100644 --- a/tests/auth.test.ts +++ b/tests/auth.test.ts @@ -4,16 +4,18 @@ import { NotFoundError } from 'routing-controllers'; import { anyString, instance, mock, verify, when } from 'ts-mockito'; import * as faker from 'faker'; import { Config } from '../config'; -import { UserModel } from '../models/UserModel'; -import EmailService from '../services/EmailService'; -import UserAuthService from '../services/UserAuthService'; +import { UserModel, AttendanceModel, ActivityModel } from '../models'; +import { EmailService, UserAuthService } from '../services'; import { ActivityType, UserAccessType, UserState } from '../types'; import { ControllerFactory } from './controllers'; -import { DatabaseConnection, EventFactory, PortalState, UserFactory } from './data'; -import FactoryUtils from './data/FactoryUtils'; -import { UserRegistrationFactory } from './data/UserRegistrationFactory'; -import { AttendanceModel } from '../models/AttendanceModel'; -import { ActivityModel } from '../models/ActivityModel'; +import { + DatabaseConnection, + FactoryUtils, + EventFactory, + PortalState, + UserFactory, + UserRegistrationFactory, +} from './data'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/controllers/ControllerFactory.ts b/tests/controllers/ControllerFactory.ts index 8d9932842..345536aef 100644 --- a/tests/controllers/ControllerFactory.ts +++ b/tests/controllers/ControllerFactory.ts @@ -1,23 +1,27 @@ import { Connection } from 'typeorm'; -import FeedbackService from '../../services/FeedbackService'; -import { FeedbackController } from '../../api/controllers/FeedbackController'; -import { UserController } from '../../api/controllers/UserController'; -import UserAccountService from '../../services/UserAccountService'; -import StorageService from '../../services/StorageService'; -import { AdminController } from '../../api/controllers/AdminController'; -import AttendanceService from '../../services/AttendanceService'; -import { AttendanceController } from '../../api/controllers/AttendanceController'; -import { AuthController } from '../../api/controllers/AuthController'; -import { EventController } from '../../api/controllers/EventController'; -import { LeaderboardController } from '../../api/controllers/LeaderboardController'; -import { MerchStoreController } from '../../api/controllers/MerchStoreController'; -import UserAuthService from '../../services/UserAuthService'; -import EmailService from '../../services/EmailService'; -import EventService from '../../services/EventService'; -import MerchStoreService from '../../services/MerchStoreService'; -import { ResumeController } from '../../api/controllers/ResumeController'; -import ResumeService from '../../services/ResumeService'; -import UserSocialMediaService from '../../services/UserSocialMediaService'; +import { + FeedbackService, + UserAccountService, + StorageService, + AttendanceService, + UserAuthService, + EmailService, + EventService, + MerchStoreService, + ResumeService, + UserSocialMediaService, +} from '../../services'; +import { + FeedbackController, + UserController, + AdminController, + AttendanceController, + AuthController, + EventController, + LeaderboardController, + MerchStoreController, + ResumeController, +} from '../../api/controllers'; export class ControllerFactory { public static user(conn: Connection, storageService = new StorageService()): UserController { diff --git a/tests/controllers/MerchStoreControllerWrapper.ts b/tests/controllers/MerchStoreControllerWrapper.ts index 4523afef6..bb72e5b37 100644 --- a/tests/controllers/MerchStoreControllerWrapper.ts +++ b/tests/controllers/MerchStoreControllerWrapper.ts @@ -1,9 +1,8 @@ import * as moment from 'moment'; import { Connection } from 'typeorm'; -import { MerchStoreController } from '../../api/controllers/MerchStoreController'; -import { UuidParam } from '../../api/validators/GenericRequests'; -import { OrderPickupEventModel } from '../../models/OrderPickupEventModel'; -import { UserModel } from '../../models/UserModel'; +import { MerchStoreController } from '../../api/controllers'; +import { UuidParam } from '../../api/validators'; +import { OrderPickupEventModel, UserModel } from '../../models'; import { FulfillMerchOrderRequest } from '../../types'; /** diff --git a/tests/controllers/index.ts b/tests/controllers/index.ts index 9957d4392..1717f9288 100644 --- a/tests/controllers/index.ts +++ b/tests/controllers/index.ts @@ -1 +1,2 @@ export * from './ControllerFactory'; +export * from './MerchStoreControllerWrapper'; diff --git a/tests/data/EventFactory.ts b/tests/data/EventFactory.ts index cefd6d146..e398edfb5 100644 --- a/tests/data/EventFactory.ts +++ b/tests/data/EventFactory.ts @@ -1,8 +1,8 @@ import * as faker from 'faker'; import * as moment from 'moment'; import { v4 as uuid } from 'uuid'; -import { EventModel } from '../../models/EventModel'; -import FactoryUtils from './FactoryUtils'; +import { EventModel } from '../../models'; +import { FactoryUtils } from '.'; export class EventFactory { private static readonly ORGS = [ diff --git a/tests/data/FactoryUtils.ts b/tests/data/FactoryUtils.ts index 567990cff..412c72d82 100644 --- a/tests/data/FactoryUtils.ts +++ b/tests/data/FactoryUtils.ts @@ -1,7 +1,7 @@ import * as faker from 'faker'; import * as moment from 'moment'; -export default class FactoryUtils { +export class FactoryUtils { public static create(n: number, fn: () => T): T[] { return Array(n).fill(null).map(fn); } diff --git a/tests/data/FeedbackFactory.ts b/tests/data/FeedbackFactory.ts index 35e82ca22..4457cc96b 100644 --- a/tests/data/FeedbackFactory.ts +++ b/tests/data/FeedbackFactory.ts @@ -1,10 +1,8 @@ import * as faker from 'faker'; import { v4 as uuid } from 'uuid'; import { FeedbackStatus, FeedbackType } from '../../types'; -import FactoryUtils from './FactoryUtils'; -import { UserFactory } from './UserFactory'; -import { EventFactory } from './EventFactory'; -import { FeedbackModel } from '../../models/FeedbackModel'; +import { FactoryUtils, UserFactory, EventFactory } from '.'; +import { FeedbackModel } from '../../models'; export class FeedbackFactory { public static create(n: number): FeedbackModel[] { diff --git a/tests/data/MerchFactory.ts b/tests/data/MerchFactory.ts index 5885fde04..f0b15c9d0 100644 --- a/tests/data/MerchFactory.ts +++ b/tests/data/MerchFactory.ts @@ -2,13 +2,15 @@ import * as faker from 'faker'; import * as moment from 'moment'; import { v4 as uuid } from 'uuid'; import { MerchItemOptionMetadata, OrderPickupEventStatus } from '../../types'; -import { OrderPickupEventModel } from '../../models/OrderPickupEventModel'; -import { MerchandiseCollectionModel } from '../../models/MerchandiseCollectionModel'; -import { MerchCollectionPhotoModel } from '../../models/MerchCollectionPhotoModel'; -import { MerchandiseItemModel } from '../../models/MerchandiseItemModel'; -import { MerchandiseItemOptionModel } from '../../models/MerchandiseItemOptionModel'; -import { MerchandiseItemPhotoModel } from '../../models/MerchandiseItemPhotoModel'; -import FactoryUtils from './FactoryUtils'; +import { + OrderPickupEventModel, + MerchandiseCollectionModel, + MerchCollectionPhotoModel, + MerchandiseItemModel, + MerchandiseItemOptionModel, + MerchandiseItemPhotoModel, +} from '../../models'; +import { FactoryUtils } from '.'; export class MerchFactory { public static fakeCollection(substitute?: Partial): MerchandiseCollectionModel { diff --git a/tests/data/PortalState.ts b/tests/data/PortalState.ts index f19af280e..09f0de9fe 100644 --- a/tests/data/PortalState.ts +++ b/tests/data/PortalState.ts @@ -1,23 +1,25 @@ import * as rfdc from 'rfdc'; import { flatten } from 'underscore'; import * as moment from 'moment'; -import { OrderPickupEventModel } from '../../models/OrderPickupEventModel'; -import { MerchandiseItemModel } from '../../models/MerchandiseItemModel'; -import { AttendanceModel } from '../../models/AttendanceModel'; -import { EventModel } from '../../models/EventModel'; -import { MerchandiseCollectionModel } from '../../models/MerchandiseCollectionModel'; -import { OrderModel } from '../../models/OrderModel'; -import { UserModel } from '../../models/UserModel'; -import { ActivityModel } from '../../models/ActivityModel'; +import { + OrderPickupEventModel, + MerchandiseItemModel, + AttendanceModel, + EventModel, + MerchandiseCollectionModel, + OrderModel, + UserModel, + ActivityModel, + MerchandiseItemOptionModel, + OrderItemModel, + FeedbackModel, + UserSocialMediaModel, + ResumeModel, + ExpressCheckinModel, +} from '../../models'; import { ActivityScope, ActivityType } from '../../types'; -import { MerchandiseItemOptionModel } from '../../models/MerchandiseItemOptionModel'; -import { OrderItemModel } from '../../models/OrderItemModel'; -import { FeedbackModel } from '../../models/FeedbackModel'; -import { UserSocialMediaModel } from '../../models/UserSocialMediaModel'; -import { DatabaseConnection } from './DatabaseConnection'; +import { DatabaseConnection } from '.'; import { MerchFactory } from '.'; -import { ResumeModel } from '../../models/ResumeModel'; -import { ExpressCheckinModel } from '../../models/ExpressCheckinModel'; export class PortalState { users: UserModel[] = []; diff --git a/tests/data/ResumeFactory.ts b/tests/data/ResumeFactory.ts index 6b179a293..2cf7996a1 100644 --- a/tests/data/ResumeFactory.ts +++ b/tests/data/ResumeFactory.ts @@ -1,8 +1,8 @@ import * as faker from 'faker'; import { v4 as uuid } from 'uuid'; -import { ResumeModel } from '../../models/ResumeModel'; -import FactoryUtils from './FactoryUtils'; -import { UserFactory } from './UserFactory'; +import { ResumeModel } from '../../models'; +import { FactoryUtils } from '.'; +import { UserFactory } from '.'; export class ResumeFactory { public static create(n: number) { diff --git a/tests/data/UserFactory.ts b/tests/data/UserFactory.ts index 17017e014..3ece1f844 100644 --- a/tests/data/UserFactory.ts +++ b/tests/data/UserFactory.ts @@ -1,10 +1,10 @@ import * as faker from 'faker'; import * as moment from 'moment'; import { v4 as uuid } from 'uuid'; -import UserAccountService from '../../services/UserAccountService'; +import { UserAccountService } from '../../services'; import { UserAccessType, UserState } from '../../types'; -import { UserModel } from '../../models/UserModel'; -import FactoryUtils from './FactoryUtils'; +import { UserModel } from '../../models'; +import { FactoryUtils } from '.'; export class UserFactory { public static readonly PASSWORD_RAW = 'password'; diff --git a/tests/data/UserRegistrationFactory.ts b/tests/data/UserRegistrationFactory.ts index 4fa865e96..7659f906e 100644 --- a/tests/data/UserRegistrationFactory.ts +++ b/tests/data/UserRegistrationFactory.ts @@ -1,7 +1,7 @@ import { UserRegistration } from 'types'; import * as faker from 'faker'; -import FactoryUtils from './FactoryUtils'; -import { UserFactory } from './UserFactory'; +import { FactoryUtils } from '.'; +import { UserFactory } from '.'; export class UserRegistrationFactory { public static create(n: number) { diff --git a/tests/data/UserSocialMediaFactory.ts b/tests/data/UserSocialMediaFactory.ts index c210076d9..3f8ec88b0 100644 --- a/tests/data/UserSocialMediaFactory.ts +++ b/tests/data/UserSocialMediaFactory.ts @@ -1,9 +1,9 @@ import * as faker from 'faker'; import { v4 as uuid } from 'uuid'; -import { UserSocialMediaModel } from '../../models/UserSocialMediaModel'; +import { UserSocialMediaModel } from '../../models'; import { SocialMediaType } from '../../types'; -import FactoryUtils from './FactoryUtils'; -import { UserFactory } from './UserFactory'; +import { FactoryUtils } from '.'; +import { UserFactory } from '.'; export class UserSocialMediaFactory { public static create(n: number): UserSocialMediaModel[] { diff --git a/tests/data/index.ts b/tests/data/index.ts index 4d6945570..02660f5d5 100644 --- a/tests/data/index.ts +++ b/tests/data/index.ts @@ -1,9 +1,14 @@ export * from './DatabaseConnection'; -export * from './UserFactory'; +export * from './FactoryUtils'; + export * from './EventFactory'; +export * from './FeedbackFactory'; +export * from './FileFactory'; export * from './MerchFactory'; -export * from './UserSocialMediaFactory'; export * from './ResumeFactory'; +export * from './UserFactory'; +export * from './UserRegistrationFactory'; +export * from './UserSocialMediaFactory'; export * from './PortalState'; diff --git a/tests/event.test.ts b/tests/event.test.ts index ef1d64dd1..499b99ea5 100644 --- a/tests/event.test.ts +++ b/tests/event.test.ts @@ -4,7 +4,7 @@ import { UserAccessType } from '../types'; import { ControllerFactory } from './controllers'; import { DatabaseConnection, EventFactory, PortalState, UserFactory } from './data'; import { CreateEventRequest } from '../api/validators/EventControllerRequests'; -import { EventModel } from '../models/EventModel'; +import { EventModel } from '../models'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/expressCheckin.test.ts b/tests/expressCheckin.test.ts index 5b33d18de..fae35a490 100644 --- a/tests/expressCheckin.test.ts +++ b/tests/expressCheckin.test.ts @@ -3,8 +3,8 @@ import { } from '../types'; import { anything, instance, mock, verify, when } from 'ts-mockito'; import { ControllerFactory } from './controllers'; import { DatabaseConnection, EventFactory, PortalState, UserFactory } from './data'; -import EmailService from '../services/EmailService'; -import { ExpressCheckinModel } from '../models/ExpressCheckinModel'; +import { EmailService } from '../services'; +import { ExpressCheckinModel } from '../models'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/feedback.test.ts b/tests/feedback.test.ts index f25163072..5b63a78c2 100644 --- a/tests/feedback.test.ts +++ b/tests/feedback.test.ts @@ -1,7 +1,6 @@ import { validate } from 'class-validator'; import { plainToClass } from 'class-transformer'; -import { DatabaseConnection, EventFactory, PortalState, UserFactory } from './data'; -import { FeedbackFactory } from './data/FeedbackFactory'; +import { DatabaseConnection, EventFactory, PortalState, UserFactory, FeedbackFactory } from './data'; import { ActivityScope, ActivityType, FeedbackStatus, FeedbackType, UserAccessType } from '../types'; import { Feedback } from '../api/validators/FeedbackControllerRequests'; import { ControllerFactory } from './controllers'; diff --git a/tests/merchOrder.test.ts b/tests/merchOrder.test.ts index 4c7967fe2..5f78fad57 100644 --- a/tests/merchOrder.test.ts +++ b/tests/merchOrder.test.ts @@ -2,14 +2,11 @@ import * as faker from 'faker'; import * as moment from 'moment'; import { mock, when, anything, instance, verify, anyString } from 'ts-mockito'; import { ForbiddenError, NotFoundError } from 'routing-controllers'; -import EmailService from '../services/EmailService'; -import { OrderModel } from '../models/OrderModel'; -import { OrderPickupEventModel } from '../models/OrderPickupEventModel'; +import { EmailService } from '../services'; +import { OrderModel, OrderPickupEventModel, UserModel } from '../models'; import { UserAccessType, OrderStatus, ActivityType, OrderPickupEventStatus } from '../types'; -import { ControllerFactory } from './controllers'; +import { ControllerFactory, MerchStoreControllerWrapper } from './controllers'; import { DatabaseConnection, EventFactory, MerchFactory, PortalState, UserFactory } from './data'; -import { MerchStoreControllerWrapper } from './controllers/MerchStoreControllerWrapper'; -import { UserModel } from '../models/UserModel'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/merchStore.test.ts b/tests/merchStore.test.ts index cbaa4bce6..41982265d 100644 --- a/tests/merchStore.test.ts +++ b/tests/merchStore.test.ts @@ -2,15 +2,13 @@ import * as faker from 'faker'; import { ForbiddenError, NotFoundError } from 'routing-controllers'; import { zip } from 'underscore'; import { anything, instance, verify, mock, when } from 'ts-mockito'; -import { OrderModel } from '../models/OrderModel'; -import { MerchandiseItemOptionModel } from '../models/MerchandiseItemOptionModel'; +import { OrderModel, MerchandiseItemOptionModel } from '../models'; import { MediaType, MerchItemEdit, UserAccessType } from '../types'; import { ControllerFactory } from './controllers'; -import { DatabaseConnection, MerchFactory, PortalState, UserFactory } from './data'; -import EmailService from '../services/EmailService'; -import { FileFactory } from './data/FileFactory'; +import { DatabaseConnection, MerchFactory, PortalState, UserFactory, FileFactory } from './data'; +import { EmailService } from '../services'; import { Config } from '../config'; -import Mocks from './mocks/MockFactory'; +import { Mocks } from './mocks'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/mocks/MockFactory.ts b/tests/mocks/MockFactory.ts index e2f30f988..0b791b321 100644 --- a/tests/mocks/MockFactory.ts +++ b/tests/mocks/MockFactory.ts @@ -1,9 +1,9 @@ import { anything, mock, when } from 'ts-mockito'; -import StorageService from '../../services/StorageService'; +import { StorageService } from '../../services'; const DEFAULT_FILE_URL = 'https://s3.amazonaws.com/default-file-url.pdf'; -export default class Mocks { +export class Mocks { public static storage(fileLocation = DEFAULT_FILE_URL): StorageService { const storageMock = mock(StorageService); when(storageMock.uploadToFolder(anything(), anything(), anything(), anything())).thenResolve(fileLocation); diff --git a/tests/mocks/index.ts b/tests/mocks/index.ts new file mode 100644 index 000000000..086f703af --- /dev/null +++ b/tests/mocks/index.ts @@ -0,0 +1 @@ +export * from './MockFactory'; diff --git a/tests/resume.test.ts b/tests/resume.test.ts index 34c2021f1..408bc2cab 100644 --- a/tests/resume.test.ts +++ b/tests/resume.test.ts @@ -1,14 +1,11 @@ import { BadRequestError, ForbiddenError } from 'routing-controllers'; import { anything, instance, verify } from 'ts-mockito'; import { ActivityType, UserAccessType, MediaType } from '../types'; -import { ResumeModel } from '../models/ResumeModel'; +import { ResumeModel, ActivityModel } from '../models'; import { Config } from '../config'; import { ControllerFactory } from './controllers'; -import { DatabaseConnection, PortalState, UserFactory } from './data'; -import { FileFactory } from './data/FileFactory'; -import Mocks from './mocks/MockFactory'; -import { ResumeFactory } from './data/ResumeFactory'; -import { ActivityModel } from '../models/ActivityModel'; +import { DatabaseConnection, PortalState, UserFactory, FileFactory, ResumeFactory } from './data'; +import { Mocks } from './mocks'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/sample.test.ts b/tests/sample.test.ts index 7b1c89b90..e96235b2c 100644 --- a/tests/sample.test.ts +++ b/tests/sample.test.ts @@ -1,13 +1,14 @@ import { ActivityType } from '../types'; -import { ActivityModel } from '../models/ActivityModel'; -import { AttendanceModel } from '../models/AttendanceModel'; -import { EventModel } from '../models/EventModel'; -import { UserModel } from '../models/UserModel'; -import { DatabaseConnection, UserFactory, EventFactory, MerchFactory, PortalState } from './data'; -import { OrderModel } from '../models/OrderModel'; -import { FeedbackFactory } from './data/FeedbackFactory'; -import { MerchandiseItemModel } from '../models/MerchandiseItemModel'; -import { MerchandiseCollectionModel } from '../models/MerchandiseCollectionModel'; +import { + ActivityModel, + AttendanceModel, + EventModel, + UserModel, + OrderModel, + MerchandiseItemModel, + MerchandiseCollectionModel, +} from '../models'; +import { DatabaseConnection, UserFactory, EventFactory, MerchFactory, PortalState, FeedbackFactory } from './data'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/user.handles.test.ts b/tests/user.handles.test.ts index 0d2cabaab..4fc78637c 100644 --- a/tests/user.handles.test.ts +++ b/tests/user.handles.test.ts @@ -2,7 +2,7 @@ import 'reflect-metadata'; // this shim is required import { plainToClass } from 'class-transformer'; import { validate } from 'class-validator'; import * as faker from 'faker'; -import { UserPatches } from '../api/validators/UserControllerRequests'; +import { UserPatches } from '../api/validators'; import { ControllerFactory } from './controllers'; import { DatabaseConnection, PortalState, UserFactory } from './data'; diff --git a/tests/userSocialMedia.test.ts b/tests/userSocialMedia.test.ts index 5c70c72d8..9df719444 100644 --- a/tests/userSocialMedia.test.ts +++ b/tests/userSocialMedia.test.ts @@ -1,11 +1,10 @@ import faker = require('faker'); import { Connection } from 'typeorm'; -import { UserModel } from '../models/UserModel'; +import { UserModel } from '../models'; import { SocialMediaType } from '../types'; import { ControllerFactory } from './controllers'; -import { DatabaseConnection, PortalState, UserFactory } from './data'; -import { UserSocialMediaFactory } from './data/UserSocialMediaFactory'; -import { UserController } from '../api/controllers/UserController'; +import { DatabaseConnection, PortalState, UserFactory, UserSocialMediaFactory } from './data'; +import { UserController } from '../api/controllers'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/types/ApiRequests.ts b/types/ApiRequests.ts index 816b59f79..2f4ee4dd5 100644 --- a/types/ApiRequests.ts +++ b/types/ApiRequests.ts @@ -1,5 +1,4 @@ -import { Uuid } from '.'; -import { FeedbackStatus, FeedbackType, SocialMediaType, UserAccessType } from './Enums'; +import { Uuid, FeedbackStatus, FeedbackType, SocialMediaType, UserAccessType } from '.'; // REQUEST TYPES diff --git a/types/ApiResponses.ts b/types/ApiResponses.ts index f04792246..4f28950f5 100644 --- a/types/ApiResponses.ts +++ b/types/ApiResponses.ts @@ -1,9 +1,15 @@ import { - ActivityScope, ActivityType, FeedbackStatus, - FeedbackType, OrderPickupEventStatus, - OrderStatus, UserAccessType, SocialMediaType, -} from './Enums'; -import { MerchItemOptionMetadata, Uuid } from '.'; + ActivityScope, + ActivityType, + FeedbackStatus, + FeedbackType, + OrderPickupEventStatus, + OrderStatus, + UserAccessType, + SocialMediaType, + MerchItemOptionMetadata, + Uuid, +} from '.'; // RESPONSE TYPES diff --git a/types/internal/index.ts b/types/internal/index.ts index a068e0131..8967c1c04 100644 --- a/types/internal/index.ts +++ b/types/internal/index.ts @@ -1,7 +1,5 @@ -import { MerchandiseItemModel } from '../../models/MerchandiseItemModel'; -import { EventModel } from '../../models/EventModel'; -import { UserModel } from '../../models/UserModel'; -import { ActivityScope, ActivityType } from '../Enums'; +import { MerchandiseItemModel, EventModel, UserModel } from '../../models'; +import { ActivityScope, ActivityType } from '..'; export type Attendance = { user: UserModel, diff --git a/utils/AuthActionMetadata.ts b/utils/AuthActionMetadata.ts index 8f448645e..9b0c22dca 100644 --- a/utils/AuthActionMetadata.ts +++ b/utils/AuthActionMetadata.ts @@ -1,5 +1,5 @@ import { Uuid } from '../types'; -import { UserModel } from '../models/UserModel'; +import { UserModel } from '../models'; export interface AuthActionMetadata { trace_id: string; diff --git a/utils/index.ts b/utils/index.ts new file mode 100644 index 000000000..0841e7bf4 --- /dev/null +++ b/utils/index.ts @@ -0,0 +1,4 @@ +export * from './AuthActionMetadata'; +export * from './Errors'; +export * from './InMemoryDatabaseCache'; +export * from './Logger'; From 66c924f801f33e9d76189c77e3b2f9116293108c Mon Sep 17 00:00:00 2001 From: Eric Chang <55172722+echang594@users.noreply.github.com> Date: Wed, 17 Apr 2024 00:51:29 -0700 Subject: [PATCH 2/5] Fixed some using default imports --- services/MerchStoreService.ts | 2 +- services/UserAuthService.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/MerchStoreService.ts b/services/MerchStoreService.ts index 0de2327ce..52befc9c7 100644 --- a/services/MerchStoreService.ts +++ b/services/MerchStoreService.ts @@ -40,7 +40,7 @@ import { MerchCollectionPhoto, } from '../types'; import { Repositories, TransactionsManager } from '../repositories'; -import EmailService, { OrderInfo, OrderPickupEventInfo } from './EmailService'; +import { EmailService, OrderInfo, OrderPickupEventInfo } from '.'; import { UserError } from '../utils'; @Service() diff --git a/services/UserAuthService.ts b/services/UserAuthService.ts index b358c9ac5..9191ef619 100644 --- a/services/UserAuthService.ts +++ b/services/UserAuthService.ts @@ -9,7 +9,7 @@ import { Repositories, UserRepository, TransactionsManager } from '../repositori import { Uuid, ActivityType, UserState, UserRegistration } from '../types'; import { Config } from '../config'; import { UserModel } from '../models'; -import UserAccountService from './UserAccountService'; +import { UserAccountService } from '.'; interface AuthToken { uuid: Uuid; From 755949f0a70a633b3cc2bcde734bdc9bf51add08 Mon Sep 17 00:00:00 2001 From: Eric Chang <55172722+echang594@users.noreply.github.com> Date: Wed, 17 Apr 2024 01:36:54 -0700 Subject: [PATCH 3/5] Made same level also use barrel files --- api/validators/LeaderboardControllerRequests.ts | 2 +- api/validators/UserControllerRequests.ts | 2 +- models/ActivityModel.ts | 2 +- models/AttendanceModel.ts | 3 +-- models/EventModel.ts | 4 +--- models/ExpressCheckinModel.ts | 2 +- models/FeedbackModel.ts | 3 +-- models/MerchCollectionPhotoModel.ts | 2 +- models/MerchandiseCollectionModel.ts | 3 +-- models/MerchandiseItemModel.ts | 4 +--- models/MerchandiseItemOptionModel.ts | 3 +-- models/MerchandiseItemPhotoModel.ts | 2 +- models/OrderItemModel.ts | 3 +-- models/OrderModel.ts | 4 +--- models/OrderPickupEventModel.ts | 3 +-- models/ResumeModel.ts | 2 +- models/UserModel.ts | 7 +------ models/UserSocialMediaModel.ts | 2 +- repositories/ActivityRepository.ts | 2 +- repositories/AttendanceRepository.ts | 2 +- repositories/EventRepository.ts | 2 +- repositories/FeedbackRepository.ts | 2 +- repositories/LeaderboardRepository.ts | 2 +- repositories/MerchOrderRepository.ts | 2 +- repositories/MerchStoreRepository.ts | 2 +- repositories/ResumeRepository.ts | 2 +- repositories/UserRepository.ts | 2 +- repositories/UserSocialMediaRepository.ts | 2 +- repositories/index.ts | 4 ++-- 29 files changed, 30 insertions(+), 47 deletions(-) diff --git a/api/validators/LeaderboardControllerRequests.ts b/api/validators/LeaderboardControllerRequests.ts index 6687e6f5a..a56dee6cd 100644 --- a/api/validators/LeaderboardControllerRequests.ts +++ b/api/validators/LeaderboardControllerRequests.ts @@ -1,6 +1,6 @@ import { Min } from 'class-validator'; import { SlidingLeaderboardQueryParams as ISlidingLeaderboardQueryParams } from '../../types'; -import { Pagination } from './GenericRequests'; +import { Pagination } from '.'; export class SlidingLeaderboardQueryParams extends Pagination implements ISlidingLeaderboardQueryParams { @Min(0) diff --git a/api/validators/UserControllerRequests.ts b/api/validators/UserControllerRequests.ts index 5593c68dc..18eaf3b5e 100644 --- a/api/validators/UserControllerRequests.ts +++ b/api/validators/UserControllerRequests.ts @@ -17,7 +17,7 @@ import { PatchUserRequest as IPatchUserRequest, UserPatches as IUserPatches, } from '../../types'; -import { PasswordChange } from './AuthControllerRequests'; +import { PasswordChange } from '.'; export class PasswordUpdate extends PasswordChange implements IPasswordUpdate { @IsDefined() diff --git a/models/ActivityModel.ts b/models/ActivityModel.ts index 7f31346eb..35d026c0e 100644 --- a/models/ActivityModel.ts +++ b/models/ActivityModel.ts @@ -1,6 +1,6 @@ import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, Index, ManyToOne, JoinColumn } from 'typeorm'; import { ActivityScope, ActivityType, PublicActivity, Uuid } from '../types'; -import { UserModel } from './UserModel'; +import { UserModel } from '.'; @Entity('Activities') @Index('sliding_leaderboard_index', ['timestamp', 'pointsEarned'], { where: '"pointsEarned" > 0' }) diff --git a/models/AttendanceModel.ts b/models/AttendanceModel.ts index f152da94f..340189a65 100644 --- a/models/AttendanceModel.ts +++ b/models/AttendanceModel.ts @@ -1,7 +1,6 @@ import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, Index, ManyToOne, JoinColumn } from 'typeorm'; import { PublicAttendance, Uuid } from '../types'; -import { UserModel } from './UserModel'; -import { EventModel } from './EventModel'; +import { UserModel, EventModel } from '.'; @Entity('Attendances') export class AttendanceModel extends BaseEntity { diff --git a/models/EventModel.ts b/models/EventModel.ts index 0fae36f59..1ff220c70 100644 --- a/models/EventModel.ts +++ b/models/EventModel.ts @@ -1,9 +1,7 @@ import * as moment from 'moment'; import { BaseEntity, Column, Entity, Index, PrimaryGeneratedColumn, OneToMany } from 'typeorm'; import { PublicEvent, Uuid } from '../types'; -import { AttendanceModel } from './AttendanceModel'; -import { FeedbackModel } from './FeedbackModel'; -import { ExpressCheckinModel } from './ExpressCheckinModel'; +import { AttendanceModel, FeedbackModel, ExpressCheckinModel } from '.'; @Entity('Events') @Index('event_start_end_index', ['start', 'end']) diff --git a/models/ExpressCheckinModel.ts b/models/ExpressCheckinModel.ts index d9e39d841..a9546bd17 100644 --- a/models/ExpressCheckinModel.ts +++ b/models/ExpressCheckinModel.ts @@ -1,6 +1,6 @@ import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { PublicExpressCheckin, Uuid } from '../types'; -import { EventModel } from './EventModel'; +import { EventModel } from '.'; @Entity('ExpressCheckins') export class ExpressCheckinModel extends BaseEntity { diff --git a/models/FeedbackModel.ts b/models/FeedbackModel.ts index 2bc2348df..899b382fc 100644 --- a/models/FeedbackModel.ts +++ b/models/FeedbackModel.ts @@ -1,7 +1,6 @@ import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { FeedbackStatus, FeedbackType, PublicFeedback, Uuid } from '../types'; -import { UserModel } from './UserModel'; -import { EventModel } from './EventModel'; +import { UserModel, EventModel } from '.'; @Entity('Feedback') export class FeedbackModel extends BaseEntity { diff --git a/models/MerchCollectionPhotoModel.ts b/models/MerchCollectionPhotoModel.ts index e3e3bdbea..f04c74fd5 100644 --- a/models/MerchCollectionPhotoModel.ts +++ b/models/MerchCollectionPhotoModel.ts @@ -1,6 +1,6 @@ import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { PublicMerchCollectionPhoto, Uuid } from '../types'; -import { MerchandiseCollectionModel } from './MerchandiseCollectionModel'; +import { MerchandiseCollectionModel } from '.'; @Entity('MerchCollectionPhotos') export class MerchCollectionPhotoModel extends BaseEntity { diff --git a/models/MerchandiseCollectionModel.ts b/models/MerchandiseCollectionModel.ts index 6c7d5da2a..078d3d336 100644 --- a/models/MerchandiseCollectionModel.ts +++ b/models/MerchandiseCollectionModel.ts @@ -1,7 +1,6 @@ import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, OneToMany, CreateDateColumn } from 'typeorm'; import { Uuid, PublicMerchCollection } from '../types'; -import { MerchandiseItemModel } from './MerchandiseItemModel'; -import { MerchCollectionPhotoModel } from './MerchCollectionPhotoModel'; +import { MerchandiseItemModel, MerchCollectionPhotoModel } from '.'; @Entity('MerchandiseCollections') export class MerchandiseCollectionModel extends BaseEntity { diff --git a/models/MerchandiseItemModel.ts b/models/MerchandiseItemModel.ts index e27971d3a..f15f1ff45 100644 --- a/models/MerchandiseItemModel.ts +++ b/models/MerchandiseItemModel.ts @@ -2,9 +2,7 @@ import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, Index, ManyToOne, JoinColumn, OneToMany, } from 'typeorm'; import { Uuid, PublicMerchItem, PublicCartMerchItem } from '../types'; -import { MerchandiseCollectionModel } from './MerchandiseCollectionModel'; -import { MerchandiseItemOptionModel } from './MerchandiseItemOptionModel'; -import { MerchandiseItemPhotoModel } from './MerchandiseItemPhotoModel'; +import { MerchandiseCollectionModel, MerchandiseItemOptionModel, MerchandiseItemPhotoModel } from '.'; @Entity('MerchandiseItems') export class MerchandiseItemModel extends BaseEntity { diff --git a/models/MerchandiseItemOptionModel.ts b/models/MerchandiseItemOptionModel.ts index 4da70499e..42208eca3 100644 --- a/models/MerchandiseItemOptionModel.ts +++ b/models/MerchandiseItemOptionModel.ts @@ -2,8 +2,7 @@ import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn, OneToMany, Index, } from 'typeorm'; import { Uuid, PublicMerchItemOption, MerchItemOptionMetadata, PublicOrderMerchItemOption } from '../types'; -import { OrderItemModel } from './OrderItemModel'; -import { MerchandiseItemModel } from './MerchandiseItemModel'; +import { OrderItemModel, MerchandiseItemModel } from '.'; @Entity('MerchandiseItemOptions') export class MerchandiseItemOptionModel extends BaseEntity { diff --git a/models/MerchandiseItemPhotoModel.ts b/models/MerchandiseItemPhotoModel.ts index e20334e3e..e48818f4d 100644 --- a/models/MerchandiseItemPhotoModel.ts +++ b/models/MerchandiseItemPhotoModel.ts @@ -1,6 +1,6 @@ import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { PublicMerchItemPhoto, Uuid } from '../types'; -import { MerchandiseItemModel } from './MerchandiseItemModel'; +import { MerchandiseItemModel } from '.'; @Entity('MerchandiseItemPhotos') export class MerchandiseItemPhotoModel extends BaseEntity { diff --git a/models/OrderItemModel.ts b/models/OrderItemModel.ts index 554460388..cc6b692d7 100644 --- a/models/OrderItemModel.ts +++ b/models/OrderItemModel.ts @@ -1,7 +1,6 @@ import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn } from 'typeorm'; import { Uuid, PublicOrderItem } from '../types'; -import { OrderModel } from './OrderModel'; -import { MerchandiseItemOptionModel } from './MerchandiseItemOptionModel'; +import { OrderModel, MerchandiseItemOptionModel } from '.'; @Entity('OrderItems') export class OrderItemModel extends BaseEntity { diff --git a/models/OrderModel.ts b/models/OrderModel.ts index 08c4dcd3d..bb0974441 100644 --- a/models/OrderModel.ts +++ b/models/OrderModel.ts @@ -9,9 +9,7 @@ import { JoinColumn, } from 'typeorm'; import { Uuid, PublicOrder, OrderStatus, PublicOrderWithItems } from '../types'; -import { UserModel } from './UserModel'; -import { OrderItemModel } from './OrderItemModel'; -import { OrderPickupEventModel } from './OrderPickupEventModel'; +import { UserModel, OrderItemModel, OrderPickupEventModel } from '.'; @Entity('Orders') export class OrderModel extends BaseEntity { diff --git a/models/OrderPickupEventModel.ts b/models/OrderPickupEventModel.ts index 928fe1da7..6b2526b21 100644 --- a/models/OrderPickupEventModel.ts +++ b/models/OrderPickupEventModel.ts @@ -1,7 +1,6 @@ import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, JoinColumn, OneToMany, OneToOne } from 'typeorm'; import { Uuid, PublicOrderPickupEvent, OrderPickupEventStatus } from '../types'; -import { OrderModel } from './OrderModel'; -import { EventModel } from './EventModel'; +import { OrderModel, EventModel } from '.'; @Entity('OrderPickupEvents') export class OrderPickupEventModel extends BaseEntity { diff --git a/models/ResumeModel.ts b/models/ResumeModel.ts index a792584ef..223e853c3 100644 --- a/models/ResumeModel.ts +++ b/models/ResumeModel.ts @@ -1,6 +1,6 @@ import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { PublicResume, Uuid } from '../types'; -import { UserModel } from './UserModel'; +import { UserModel } from '.'; @Entity('Resumes') export class ResumeModel extends BaseEntity { diff --git a/models/UserModel.ts b/models/UserModel.ts index 677ec3f10..a8fcc4f91 100644 --- a/models/UserModel.ts +++ b/models/UserModel.ts @@ -1,12 +1,7 @@ import { BaseEntity, Column, Entity, Index, PrimaryGeneratedColumn, OneToMany } from 'typeorm'; import * as bcrypt from 'bcrypt'; import { PrivateProfile, PublicProfile, Uuid, UserAccessType, UserState } from '../types'; -import { ActivityModel } from './ActivityModel'; -import { AttendanceModel } from './AttendanceModel'; -import { OrderModel } from './OrderModel'; -import { FeedbackModel } from './FeedbackModel'; -import { ResumeModel } from './ResumeModel'; -import { UserSocialMediaModel } from './UserSocialMediaModel'; +import { ActivityModel, AttendanceModel, OrderModel, FeedbackModel, ResumeModel, UserSocialMediaModel } from '.'; @Entity('Users') export class UserModel extends BaseEntity { diff --git a/models/UserSocialMediaModel.ts b/models/UserSocialMediaModel.ts index ffa4b539f..d7671a189 100644 --- a/models/UserSocialMediaModel.ts +++ b/models/UserSocialMediaModel.ts @@ -1,5 +1,5 @@ import { BaseEntity, Column, Entity, PrimaryGeneratedColumn, JoinColumn, ManyToOne } from 'typeorm'; -import { UserModel } from './UserModel'; +import { UserModel } from '.'; import { Uuid, SocialMediaType, PublicUserSocialMedia } from '../types'; @Entity('UserSocialMedia') diff --git a/repositories/ActivityRepository.ts b/repositories/ActivityRepository.ts index 22c7e6189..0f8a40efc 100644 --- a/repositories/ActivityRepository.ts +++ b/repositories/ActivityRepository.ts @@ -2,7 +2,7 @@ import { EntityRepository, Raw } from 'typeorm'; import * as moment from 'moment'; import { ActivityScope, ActivityType, Uuid } from '../types'; import { UserModel, ActivityModel } from '../models'; -import { BaseRepository } from './BaseRepository'; +import { BaseRepository } from '.'; import { Activity, ActivityTypeToScope } from '../types/internal'; @EntityRepository(ActivityModel) diff --git a/repositories/AttendanceRepository.ts b/repositories/AttendanceRepository.ts index 5111bbc91..78f9c901a 100644 --- a/repositories/AttendanceRepository.ts +++ b/repositories/AttendanceRepository.ts @@ -1,7 +1,7 @@ import { EntityRepository } from 'typeorm'; import { ExpressCheckinModel, AttendanceModel, UserModel, EventModel } from '../models'; import { Uuid } from '../types'; -import { BaseRepository } from './BaseRepository'; +import { BaseRepository } from '.'; import { Attendance } from '../types/internal'; @EntityRepository(AttendanceModel) diff --git a/repositories/EventRepository.ts b/repositories/EventRepository.ts index 623245615..c4f168e06 100644 --- a/repositories/EventRepository.ts +++ b/repositories/EventRepository.ts @@ -1,7 +1,7 @@ import { EntityRepository, SelectQueryBuilder } from 'typeorm'; import { EventSearchOptions, Uuid } from '../types'; import { EventModel } from '../models'; -import { BaseRepository } from './BaseRepository'; +import { BaseRepository } from '.'; @EntityRepository(EventModel) export class EventRepository extends BaseRepository { diff --git a/repositories/FeedbackRepository.ts b/repositories/FeedbackRepository.ts index 58d3dce52..8c3249d96 100644 --- a/repositories/FeedbackRepository.ts +++ b/repositories/FeedbackRepository.ts @@ -1,6 +1,6 @@ import { EntityRepository, SelectQueryBuilder } from 'typeorm'; import { FeedbackModel, UserModel, EventModel } from '../models'; -import { BaseRepository } from './BaseRepository'; +import { BaseRepository } from '.'; import { FeedbackSearchOptions, Uuid } from '../types'; @EntityRepository(FeedbackModel) diff --git a/repositories/LeaderboardRepository.ts b/repositories/LeaderboardRepository.ts index d05ada314..40ed1ca20 100644 --- a/repositories/LeaderboardRepository.ts +++ b/repositories/LeaderboardRepository.ts @@ -3,7 +3,7 @@ import * as moment from 'moment'; import { Config } from '../config'; import { ActivityModel, UserModel } from '../models'; import { UserState } from '../types'; -import { BaseRepository } from './BaseRepository'; +import { BaseRepository } from '.'; @EntityRepository(UserModel) export class LeaderboardRepository extends BaseRepository { diff --git a/repositories/MerchOrderRepository.ts b/repositories/MerchOrderRepository.ts index d4980f0c2..30263fda3 100644 --- a/repositories/MerchOrderRepository.ts +++ b/repositories/MerchOrderRepository.ts @@ -1,7 +1,7 @@ import { EntityRepository, In, SelectQueryBuilder } from 'typeorm'; import { OrderStatus, Uuid } from '../types'; import { OrderModel, UserModel, OrderItemModel, OrderPickupEventModel, MerchandiseItemModel } from '../models'; -import { BaseRepository } from './BaseRepository'; +import { BaseRepository } from '.'; @EntityRepository(OrderModel) export class MerchOrderRepository extends BaseRepository { diff --git a/repositories/MerchStoreRepository.ts b/repositories/MerchStoreRepository.ts index 54f89fa49..48b735bf0 100644 --- a/repositories/MerchStoreRepository.ts +++ b/repositories/MerchStoreRepository.ts @@ -7,7 +7,7 @@ import { MerchandiseItemModel, } from '../models'; import { Uuid } from '../types'; -import { BaseRepository } from './BaseRepository'; +import { BaseRepository } from '.'; @EntityRepository(MerchandiseCollectionModel) export class MerchCollectionRepository extends BaseRepository { diff --git a/repositories/ResumeRepository.ts b/repositories/ResumeRepository.ts index 822f62f2b..3d28ecddc 100644 --- a/repositories/ResumeRepository.ts +++ b/repositories/ResumeRepository.ts @@ -1,6 +1,6 @@ import { EntityRepository } from 'typeorm'; import { ResumeModel, UserModel } from '../models'; -import { BaseRepository } from './BaseRepository'; +import { BaseRepository } from '.'; @EntityRepository(ResumeModel) export class ResumeRepository extends BaseRepository { diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index f04c1881f..805ba97e8 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -3,7 +3,7 @@ import * as bcrypt from 'bcrypt'; import { Activity } from '../types/internal'; import { UserModel } from '../models'; import { Uuid } from '../types'; -import { BaseRepository } from './BaseRepository'; +import { BaseRepository } from '.'; @EntityRepository(UserModel) export class UserRepository extends BaseRepository { diff --git a/repositories/UserSocialMediaRepository.ts b/repositories/UserSocialMediaRepository.ts index 7ebc514b0..4d69cf5d7 100644 --- a/repositories/UserSocialMediaRepository.ts +++ b/repositories/UserSocialMediaRepository.ts @@ -1,7 +1,7 @@ import { EntityRepository } from 'typeorm'; import { SocialMediaType, Uuid } from 'types'; import { UserSocialMediaModel, UserModel } from '../models'; -import { BaseRepository } from './BaseRepository'; +import { BaseRepository } from '.'; @EntityRepository(UserSocialMediaModel) export class UserSocialMediaRepository extends BaseRepository { diff --git a/repositories/index.ts b/repositories/index.ts index c1bfb36d9..01b7a50aa 100644 --- a/repositories/index.ts +++ b/repositories/index.ts @@ -1,5 +1,6 @@ import { EntityManager } from 'typeorm'; import AsyncRetry = require('async-retry'); +import { BaseRepository } from './BaseRepository'; import { UserRepository } from './UserRepository'; import { FeedbackRepository } from './FeedbackRepository'; import { AttendanceRepository, ExpressCheckinRepository } from './AttendanceRepository'; @@ -132,6 +133,7 @@ export class TransactionsManager { export { ActivityRepository, AttendanceRepository, + BaseRepository, ExpressCheckinRepository, EventRepository, FeedbackRepository, @@ -148,5 +150,3 @@ export { UserRepository, UserSocialMediaRepository, }; - -export { BaseRepository } from './BaseRepository'; From 005d68accc5871e08bf0c91ebbedbf134cc200ac Mon Sep 17 00:00:00 2001 From: Eric Chang <55172722+echang594@users.noreply.github.com> Date: Mon, 22 Apr 2024 22:57:52 -0700 Subject: [PATCH 4/5] Added module aliases --- aliases.ts | 16 +++++++++ api/controllers/AdminController.ts | 22 ++++++------ api/controllers/AttendanceController.ts | 12 +++---- api/controllers/AuthController.ts | 14 ++++---- api/controllers/EventController.ts | 12 +++---- api/controllers/FeedbackController.ts | 12 +++---- api/controllers/LeaderboardController.ts | 8 ++--- api/controllers/MerchStoreController.ts | 14 ++++---- api/controllers/ResumeController.ts | 12 +++---- api/controllers/UserController.ts | 12 +++---- api/controllers/index.ts | 3 +- api/decorators/Validators.ts | 2 +- api/middleware/ErrorHandler.ts | 2 +- api/middleware/NotFoundHandler.ts | 2 +- api/middleware/UserAuthentication.ts | 4 +-- api/validators/AdminControllerRequests.ts | 2 +- .../AttendanceControllerRequests.ts | 2 +- api/validators/AuthControllerRequests.ts | 8 ++--- api/validators/EventControllerRequests.ts | 4 +-- api/validators/FeedbackControllerRequests.ts | 4 +-- api/validators/GenericRequests.ts | 4 +-- .../LeaderboardControllerRequests.ts | 4 +-- api/validators/MerchStoreRequests.ts | 2 +- api/validators/ResumeControllerRequests.ts | 2 +- api/validators/UserControllerRequests.ts | 14 ++++---- .../UserSocialMediaControllerRequests.ts | 4 +-- api/validators/index.ts | 2 +- error/index.ts | 6 ++-- index.ts | 12 ++++--- jest.config.json | 16 ++++++++- migrations/0020-replace-enums-with-strings.ts | 2 +- models/ActivityModel.ts | 4 +-- models/AttendanceModel.ts | 4 +-- models/EventModel.ts | 4 +-- models/ExpressCheckinModel.ts | 4 +-- models/FeedbackModel.ts | 4 +-- models/MerchCollectionPhotoModel.ts | 4 +-- models/MerchandiseCollectionModel.ts | 4 +-- models/MerchandiseItemModel.ts | 4 +-- models/MerchandiseItemOptionModel.ts | 4 +-- models/MerchandiseItemPhotoModel.ts | 4 +-- models/OrderItemModel.ts | 4 +-- models/OrderModel.ts | 4 +-- models/OrderPickupEventModel.ts | 4 +-- models/ResumeModel.ts | 4 +-- models/UserModel.ts | 4 +-- models/UserSocialMediaModel.ts | 4 +-- ormconfig.ts | 4 ++- package.json | 2 ++ repositories/ActivityRepository.ts | 8 ++--- repositories/AttendanceRepository.ts | 8 ++--- repositories/EventRepository.ts | 6 ++-- repositories/FeedbackRepository.ts | 6 ++-- repositories/LeaderboardRepository.ts | 8 ++--- repositories/MerchOrderRepository.ts | 6 ++-- repositories/MerchStoreRepository.ts | 6 ++-- repositories/ResumeRepository.ts | 4 +-- repositories/UserRepository.ts | 8 ++--- repositories/UserSocialMediaRepository.ts | 6 ++-- services/AttendanceService.ts | 12 +++---- services/EmailService.ts | 6 ++-- services/EventService.ts | 8 ++--- services/FeedbackService.ts | 8 ++--- services/MerchStoreService.ts | 34 +++++++++---------- services/PermissionsService.ts | 4 +-- services/ResumeService.ts | 6 ++-- services/StorageService.ts | 4 +-- services/UserAccountService.ts | 8 ++--- services/UserAuthService.ts | 11 +++--- services/UserSocialMediaService.ts | 8 ++--- tests/Seeds.ts | 6 ++-- tests/admin.test.ts | 8 ++--- tests/attendance.test.ts | 6 ++-- tests/auth.test.ts | 12 +++---- tests/controllers/ControllerFactory.ts | 4 +-- .../MerchStoreControllerWrapper.ts | 8 ++--- tests/data/DatabaseConnection.ts | 4 +-- tests/data/EventFactory.ts | 4 +-- tests/data/FeedbackFactory.ts | 6 ++-- tests/data/FileFactory.ts | 2 +- tests/data/MerchFactory.ts | 6 ++-- tests/data/PortalState.ts | 7 ++-- tests/data/ResumeFactory.ts | 5 ++- tests/data/UserFactory.ts | 8 ++--- tests/data/UserRegistrationFactory.ts | 5 ++- tests/data/UserSocialMediaFactory.ts | 7 ++-- tests/event.test.ts | 8 ++--- tests/expressCheckin.test.ts | 10 +++--- tests/feedback.test.ts | 6 ++-- tests/merchOrder.test.ts | 10 +++--- tests/merchStore.test.ts | 14 ++++---- tests/mocks/MockFactory.ts | 2 +- tests/resume.test.ts | 12 +++---- tests/sample.test.ts | 6 ++-- tests/user.handles.test.ts | 6 ++-- tests/userSocialMedia.test.ts | 10 +++--- tsconfig.json | 17 +++++++++- types/ApiRequests.ts | 2 +- types/ApiResponses.ts | 2 +- types/internal/index.ts | 4 +-- utils/AuthActionMetadata.ts | 4 +-- utils/Logger.ts | 2 +- yarn.lock | 10 ++++++ 103 files changed, 380 insertions(+), 323 deletions(-) create mode 100644 aliases.ts diff --git a/aliases.ts b/aliases.ts new file mode 100644 index 000000000..8ce5e29a9 --- /dev/null +++ b/aliases.ts @@ -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`, +}); diff --git a/api/controllers/AdminController.ts b/api/controllers/AdminController.ts index de9a3b897..6d8e0cb9f 100644 --- a/api/controllers/AdminController.ts +++ b/api/controllers/AdminController.ts @@ -1,11 +1,4 @@ import { JsonController, Post, Patch, UploadedFile, UseBefore, ForbiddenError, Body, Get } from 'routing-controllers'; -import { UserAuthentication } from '../middleware'; -import { - CreateBonusRequest, - CreateMilestoneRequest, - SubmitAttendanceForUsersRequest, - ModifyUserAccessLevelRequest, -} from '../validators'; import { File, MediaType, @@ -16,10 +9,17 @@ import { SubmitAttendanceForUsersResponse, ModifyUserAccessLevelResponse, GetAllUserAccessLevelsResponse, -} from '../../types'; -import { AuthenticatedUser } from '../decorators'; -import { UserAccountService, StorageService, PermissionsService, AttendanceService } from '../../services'; -import { UserModel } from '../../models'; +} 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') diff --git a/api/controllers/AttendanceController.ts b/api/controllers/AttendanceController.ts index 07c956fb0..41e317d50 100644 --- a/api/controllers/AttendanceController.ts +++ b/api/controllers/AttendanceController.ts @@ -1,10 +1,10 @@ import { JsonController, Get, Post, UseBefore, Params, ForbiddenError, Body } from 'routing-controllers'; -import { EmailService, AttendanceService, PermissionsService } from '../../services'; -import { UserAuthentication } from '../middleware'; -import { AuthenticatedUser } from '../decorators'; -import { AttendEventRequest, AttendViaExpressCheckinRequest, UuidParam } from '../validators'; -import { UserModel } from '../../models'; -import { GetAttendancesForEventResponse, GetAttendancesForUserResponse, AttendEventResponse } from '../../types'; +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 { diff --git a/api/controllers/AuthController.ts b/api/controllers/AuthController.ts index 2d44b28bb..27636dbc5 100644 --- a/api/controllers/AuthController.ts +++ b/api/controllers/AuthController.ts @@ -8,10 +8,9 @@ import { VerifyEmailResponse, ResendEmailVerificationResponse, EmailModificationResponse, -} from '../../types'; -import { UserAccountService, UserAuthService, EmailService } from '../../services'; -import { logger as log, authActionMetadata } from '../../utils'; -import { RequestTrace, AuthenticatedUser } from '../decorators'; +} from '@customtypes'; +import { UserAccountService, UserAuthService, EmailService } from '@services'; +import { UserModel } from '@models'; import { LoginRequest, RegistrationRequest, @@ -19,9 +18,10 @@ import { EmailModificationRequest, EmailParam, AccessCodeParam, -} from '../validators'; -import { OptionalUserAuthentication, UserAuthentication } from '../middleware'; -import { UserModel } from '../../models'; +} from '@validators'; +import { OptionalUserAuthentication, UserAuthentication } from '@middleware'; +import { RequestTrace, AuthenticatedUser } from '@decorators'; +import { logger as log, authActionMetadata } from '@utils'; @JsonController('/auth') export class AuthController { diff --git a/api/controllers/EventController.ts b/api/controllers/EventController.ts index 9226cf7d3..5a9ba8eba 100644 --- a/api/controllers/EventController.ts +++ b/api/controllers/EventController.ts @@ -1,10 +1,6 @@ import { JsonController, Get, Patch, Delete, Post, UseBefore, Params, ForbiddenError, QueryParams, UploadedFile, Body, } from 'routing-controllers'; -import { EventService, PermissionsService, StorageService, AttendanceService } from '../../services'; -import { UserAuthentication, OptionalUserAuthentication } from '../middleware'; -import { AuthenticatedUser } from '../decorators'; -import { UserModel } from '../../models'; import { MediaType, File, @@ -16,8 +12,12 @@ import { GetFutureEventsResponse, GetAllEventsResponse, GetPastEventsResponse, -} from '../../types'; -import { UuidParam } from '../validators'; +} 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, diff --git a/api/controllers/FeedbackController.ts b/api/controllers/FeedbackController.ts index 18bd728f5..d87b901bc 100644 --- a/api/controllers/FeedbackController.ts +++ b/api/controllers/FeedbackController.ts @@ -9,12 +9,12 @@ import { UseBefore, QueryParams, } from 'routing-controllers'; -import { AuthenticatedUser } from '../decorators'; -import { UserModel } from '../../models'; -import { PermissionsService, FeedbackService } from '../../services'; -import { GetFeedbackResponse, SubmitFeedbackResponse, UpdateFeedbackStatusResponse } from '../../types'; -import { UuidParam } from '../validators'; -import { UserAuthentication } from '../middleware'; +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, diff --git a/api/controllers/LeaderboardController.ts b/api/controllers/LeaderboardController.ts index 3ef17f272..5dc04403f 100644 --- a/api/controllers/LeaderboardController.ts +++ b/api/controllers/LeaderboardController.ts @@ -1,8 +1,8 @@ import { UseBefore, JsonController, Get, QueryParams } from 'routing-controllers'; -import { GetLeaderboardResponse } from '../../types'; -import { UserAuthentication } from '../middleware'; -import { UserAccountService } from '../../services'; -import { SlidingLeaderboardQueryParams } from '../validators'; +import { GetLeaderboardResponse } from '@customtypes'; +import { UserAccountService } from '@services'; +import { SlidingLeaderboardQueryParams } from '@validators'; +import { UserAuthentication } from '@middleware'; @UseBefore(UserAuthentication) @JsonController('/leaderboard') diff --git a/api/controllers/MerchStoreController.ts b/api/controllers/MerchStoreController.ts index de81c926d..09a002c3e 100644 --- a/api/controllers/MerchStoreController.ts +++ b/api/controllers/MerchStoreController.ts @@ -13,8 +13,6 @@ import { UploadedFile, } from 'routing-controllers'; import { v4 as uuid } from 'uuid'; -import { PermissionsService, MerchStoreService, StorageService } from '../../services'; -import { UserAuthentication } from '../middleware'; import { GetOneMerchCollectionResponse, GetAllMerchCollectionsResponse, @@ -50,7 +48,9 @@ import { GetOrderPickupEventResponse, CancelOrderPickupEventResponse, CancelMerchOrderResponse, -} from '../../types'; +} from '@customtypes'; +import { PermissionsService, MerchStoreService, StorageService } from '@services'; +import { UserModel } from '@models'; import { UuidParam, CreateMerchCollectionRequest, @@ -67,10 +67,10 @@ import { CreateOrderPickupEventRequest, EditOrderPickupEventRequest, GetCartRequest, -} from '../validators'; -import { AuthenticatedUser } from '../decorators'; -import { UserModel } from '../../models'; -import { UserError } from '../../utils'; +} from '@validators'; +import { UserAuthentication } from '@middleware'; +import { AuthenticatedUser } from '@decorators'; +import { UserError } from '@utils'; @UseBefore(UserAuthentication) @JsonController('/merch') diff --git a/api/controllers/ResumeController.ts b/api/controllers/ResumeController.ts index cf7266af7..c079c9747 100644 --- a/api/controllers/ResumeController.ts +++ b/api/controllers/ResumeController.ts @@ -12,10 +12,6 @@ import { Delete, } from 'routing-controllers'; import * as path from 'path'; -import { PermissionsService, StorageService, ResumeService } from '../../services'; -import { UserAuthentication } from '../middleware'; -import { UserModel } from '../../models'; -import { AuthenticatedUser } from '../decorators'; import { File, MediaType, @@ -23,8 +19,12 @@ import { PatchResumeResponse, UpdateResumeResponse, DeleteResumeResponse, -} from '../../types'; -import { PatchResumeRequest, UploadResumeRequest, UuidParam } from '../validators'; +} 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') diff --git a/api/controllers/UserController.ts b/api/controllers/UserController.ts index b1e16c1b4..59a216bde 100644 --- a/api/controllers/UserController.ts +++ b/api/controllers/UserController.ts @@ -1,10 +1,6 @@ import { JsonController, Params, Get, Post, Patch, UseBefore, UploadedFile, Body, Delete, } from 'routing-controllers'; -import { UserModel } from '../../models'; -import { UserAccountService, UserSocialMediaService, StorageService } from '../../services'; -import { UserAuthentication } from '../middleware'; -import { AuthenticatedUser } from '../decorators'; import { MediaType, File, @@ -16,14 +12,18 @@ import { InsertSocialMediaResponse, UpdateSocialMediaResponse, DeleteSocialMediaResponse, -} from '../../types'; +} from '@customtypes'; +import { UserAccountService, UserSocialMediaService, StorageService } from '@services'; +import { UserModel } from '@models'; import { UserHandleParam, UuidParam, PatchUserRequest, InsertSocialMediaRequest, UpdateSocialMediaRequest, -} from '../validators'; +} from '@validators'; +import { UserAuthentication } from '@middleware'; +import { AuthenticatedUser } from '@decorators'; @UseBefore(UserAuthentication) @JsonController('/user') diff --git a/api/controllers/index.ts b/api/controllers/index.ts index 0505a16be..69ffe0f12 100644 --- a/api/controllers/index.ts +++ b/api/controllers/index.ts @@ -1,5 +1,5 @@ // eslint-disable-next-line @typescript-eslint/no-unused-vars -import { UserModel } from '../../models'; +import { UserModel } from '@models'; import { UserController } from './UserController'; import { AuthController } from './AuthController'; import { EventController } from './EventController'; @@ -22,7 +22,6 @@ export const controllers = [ ResumeController, ]; -// can't export imports in the same line if imports are used in the file so must export separately export { UserController, AuthController, diff --git a/api/decorators/Validators.ts b/api/decorators/Validators.ts index cea6d8f89..7e434be86 100644 --- a/api/decorators/Validators.ts +++ b/api/decorators/Validators.ts @@ -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, diff --git a/api/middleware/ErrorHandler.ts b/api/middleware/ErrorHandler.ts index df195b290..626473962 100644 --- a/api/middleware/ErrorHandler.ts +++ b/api/middleware/ErrorHandler.ts @@ -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 { diff --git a/api/middleware/NotFoundHandler.ts b/api/middleware/NotFoundHandler.ts index 5ce650446..054dc5191 100644 --- a/api/middleware/NotFoundHandler.ts +++ b/api/middleware/NotFoundHandler.ts @@ -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 { diff --git a/api/middleware/UserAuthentication.ts b/api/middleware/UserAuthentication.ts index 57e35a854..b261781b1 100644 --- a/api/middleware/UserAuthentication.ts +++ b/api/middleware/UserAuthentication.ts @@ -1,8 +1,8 @@ import { ExpressMiddlewareInterface, ForbiddenError } from 'routing-controllers'; import * as express from 'express'; import { Inject } from 'typedi'; -import { UserAuthService } from '../../services'; -import { authActionMetadata, logger as log } from '../../utils'; +import { UserAuthService } from '@services'; +import { authActionMetadata, logger as log } from '@utils'; export class UserAuthentication implements ExpressMiddlewareInterface { @Inject() diff --git a/api/validators/AdminControllerRequests.ts b/api/validators/AdminControllerRequests.ts index 3739d4d20..ef19cd20e 100644 --- a/api/validators/AdminControllerRequests.ts +++ b/api/validators/AdminControllerRequests.ts @@ -9,7 +9,7 @@ import { Bonus as IBonus, UserAccessUpdates as IUserAccessUpdates, UserAccessType, -} from '../../types'; +} from '@customtypes'; const validUserAccessTypes = Object.values(UserAccessType); diff --git a/api/validators/AttendanceControllerRequests.ts b/api/validators/AttendanceControllerRequests.ts index bc90ea658..818bbdf42 100644 --- a/api/validators/AttendanceControllerRequests.ts +++ b/api/validators/AttendanceControllerRequests.ts @@ -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() diff --git a/api/validators/AuthControllerRequests.ts b/api/validators/AuthControllerRequests.ts index 1fa5a24e1..7a383f078 100644 --- a/api/validators/AuthControllerRequests.ts +++ b/api/validators/AuthControllerRequests.ts @@ -1,8 +1,5 @@ import { IsEmail, IsDefined, ValidateNested, Length } from 'class-validator'; import { Type } from 'class-transformer'; -import { - IsValidPassword, IsValidName, IsValidGraduationYear, IsValidMajor, HasMatchingPasswords, IsValidHandle, -} from '../decorators'; import { LoginRequest as ILoginRequest, RegistrationRequest as IRegistrationRequest, @@ -10,7 +7,10 @@ import { UserRegistration as IUserRegistration, PasswordChange as IPasswordChange, EmailModificationRequest as IEmailModificationRequest, -} from '../../types'; +} from '@customtypes'; +import { + IsValidPassword, IsValidName, IsValidGraduationYear, IsValidMajor, HasMatchingPasswords, IsValidHandle, +} from '@decorators'; export class UserRegistration implements IUserRegistration { @IsDefined() diff --git a/api/validators/EventControllerRequests.ts b/api/validators/EventControllerRequests.ts index 556541567..1562bc357 100644 --- a/api/validators/EventControllerRequests.ts +++ b/api/validators/EventControllerRequests.ts @@ -8,8 +8,8 @@ import { SubmitEventFeedbackRequest as ISubmitEventFeedbackRequest, Event as IEvent, Uuid, -} from '../../types'; -import { IsValidEventFeedback } from '../decorators'; +} from '@customtypes'; +import { IsValidEventFeedback } from '@decorators'; export class OptionalEventProperties implements IOptionalEventProperties { @IsNotEmpty() diff --git a/api/validators/FeedbackControllerRequests.ts b/api/validators/FeedbackControllerRequests.ts index efde3feb9..8aaf9401e 100644 --- a/api/validators/FeedbackControllerRequests.ts +++ b/api/validators/FeedbackControllerRequests.ts @@ -1,6 +1,5 @@ import { Type } from 'class-transformer'; import { Allow, IsDefined, IsNotEmpty, MinLength, ValidateNested } from 'class-validator'; -import { IsValidFeedbackType, IsValidFeedbackStatus } from '../decorators'; import { SubmitEventFeedbackRequest as ISubmitEventFeedbackRequest, SubmitFeedbackRequest as ISubmitFeedbackRequest, @@ -10,7 +9,8 @@ import { FeedbackType, FeedbackStatus, Uuid, -} from '../../types'; +} from '@customtypes'; +import { IsValidFeedbackType, IsValidFeedbackStatus } from '@decorators'; export class Feedback implements IFeedback { @IsDefined() diff --git a/api/validators/GenericRequests.ts b/api/validators/GenericRequests.ts index a3c17fdce..43b491aa7 100644 --- a/api/validators/GenericRequests.ts +++ b/api/validators/GenericRequests.ts @@ -1,6 +1,6 @@ import { Min, IsEmail, IsUUID, IsHexadecimal, Length } from 'class-validator'; -import { IsValidHandle } from '../decorators'; -import { Pagination as IPagination, Uuid } from '../../types'; +import { Pagination as IPagination, Uuid } from '@customtypes'; +import { IsValidHandle } from '@decorators'; export class Pagination implements IPagination { @Min(0) diff --git a/api/validators/LeaderboardControllerRequests.ts b/api/validators/LeaderboardControllerRequests.ts index a56dee6cd..711d2aa65 100644 --- a/api/validators/LeaderboardControllerRequests.ts +++ b/api/validators/LeaderboardControllerRequests.ts @@ -1,6 +1,6 @@ import { Min } from 'class-validator'; -import { SlidingLeaderboardQueryParams as ISlidingLeaderboardQueryParams } from '../../types'; -import { Pagination } from '.'; +import { SlidingLeaderboardQueryParams as ISlidingLeaderboardQueryParams } from '@customtypes'; +import { Pagination } from '@validators'; export class SlidingLeaderboardQueryParams extends Pagination implements ISlidingLeaderboardQueryParams { @Min(0) diff --git a/api/validators/MerchStoreRequests.ts b/api/validators/MerchStoreRequests.ts index 5159025ee..09ab9e9f4 100644 --- a/api/validators/MerchStoreRequests.ts +++ b/api/validators/MerchStoreRequests.ts @@ -46,7 +46,7 @@ import { OrderPickupEvent as IOrderPickupEvent, OrderPickupEventEdit as IOrderPickupEventEdit, Uuid, -} from '../../types'; +} from '@customtypes'; export class MerchCollection implements IMerchCollection { @IsDefined() diff --git a/api/validators/ResumeControllerRequests.ts b/api/validators/ResumeControllerRequests.ts index e771d0963..b359bc352 100644 --- a/api/validators/ResumeControllerRequests.ts +++ b/api/validators/ResumeControllerRequests.ts @@ -4,7 +4,7 @@ import { UploadResumeRequest as IUploadResumeRequest, ResumePatches as IResumePatches, PatchResumeRequest as IPatchResumeRequest, -} from '../../types'; +} from '@customtypes'; export class UploadResumeRequest implements IUploadResumeRequest { // IsBooleanString is used here instead of IsBoolean since multipart/form-data diff --git a/api/validators/UserControllerRequests.ts b/api/validators/UserControllerRequests.ts index 18eaf3b5e..c5d6fc459 100644 --- a/api/validators/UserControllerRequests.ts +++ b/api/validators/UserControllerRequests.ts @@ -5,19 +5,19 @@ import { Length, } from 'class-validator'; import { Type } from 'class-transformer'; +import { + PasswordUpdate as IPasswordUpdate, + PatchUserRequest as IPatchUserRequest, + UserPatches as IUserPatches, +} from '@customtypes'; import { IsValidName, IsValidMajor, IsValidGraduationYear, HasMatchingPasswords, IsValidHandle, -} from '../decorators'; -import { - PasswordUpdate as IPasswordUpdate, - PatchUserRequest as IPatchUserRequest, - UserPatches as IUserPatches, -} from '../../types'; -import { PasswordChange } from '.'; +} from '@decorators'; +import { PasswordChange } from '@validators'; export class PasswordUpdate extends PasswordChange implements IPasswordUpdate { @IsDefined() diff --git a/api/validators/UserSocialMediaControllerRequests.ts b/api/validators/UserSocialMediaControllerRequests.ts index e9f159dd7..e88cf4176 100644 --- a/api/validators/UserSocialMediaControllerRequests.ts +++ b/api/validators/UserSocialMediaControllerRequests.ts @@ -1,13 +1,13 @@ import { Type } from 'class-transformer'; import { IsDefined, IsNotEmpty, ValidateNested } from 'class-validator'; -import { IsValidSocialMediaType } from '../decorators'; import { InsertUserSocialMediaRequest as IInsertUserSocialMediaRequest, UpdateUserSocialMediaRequest as IUpdateUserSocialMediaRequest, SocialMedia as ISocialMedia, SocialMediaPatches as ISocialMediaPatches, SocialMediaType, -} from '../../types'; +} from '@customtypes'; +import { IsValidSocialMediaType } from '@decorators'; export class SocialMedia implements ISocialMedia { @IsDefined() diff --git a/api/validators/index.ts b/api/validators/index.ts index f9902c1d9..7482130db 100644 --- a/api/validators/index.ts +++ b/api/validators/index.ts @@ -1,7 +1,7 @@ export * from './AdminControllerRequests'; export * from './AttendanceControllerRequests'; export * from './AuthControllerRequests'; -// Clashing exports from EventControllerRequests and FeedbackControllerRequests, left unexported for now +// TODO Clashing exports from EventControllerRequests and FeedbackControllerRequests, left unexported for now // export * from './EventControllerRequests'; // export * from './FeedbackControllerRequests'; export * from './GenericRequests'; diff --git a/error/index.ts b/error/index.ts index 65153014e..91cab2fe9 100644 --- a/error/index.ts +++ b/error/index.ts @@ -1,8 +1,8 @@ import * as express from 'express'; import { HttpError } from 'routing-controllers'; -import { ApiResponse, CustomErrorBody } from '../types'; -import { Config } from '../config'; -import { logger as log } from '../utils'; +import { ApiResponse, CustomErrorBody } from '@customtypes'; +import { Config } from '@config'; +import { logger as log } from '@utils'; export function handleError(error: Error, request: express.Request, diff --git a/index.ts b/index.ts index 4a00ea3cb..947317fa3 100644 --- a/index.ts +++ b/index.ts @@ -1,15 +1,17 @@ +import './aliases'; + import 'reflect-metadata'; // this shim is required import { createExpressServer, useContainer as routingUseContainer } from 'routing-controllers'; import { createConnection, useContainer as ormUseContainer } from 'typeorm'; import { Container } from 'typedi'; -import { models as entities } from './models'; +import { models as entities } from '@models'; -import { Config } from './config'; -import { InMemoryDatabaseCache, logger as log } from './utils'; -import { controllers } from './api/controllers'; -import { middlewares } from './api/middleware'; +import { Config } from '@config'; +import { InMemoryDatabaseCache, logger as log } from '@utils'; +import { controllers } from '@controllers'; +import { middlewares } from '@middleware'; routingUseContainer(Container); ormUseContainer(Container); diff --git a/jest.config.json b/jest.config.json index a5d5d3d4d..42e82a946 100644 --- a/jest.config.json +++ b/jest.config.json @@ -9,5 +9,19 @@ "js", "json", "node" - ] + ], + "moduleNameMapper": { + "@controllers": "/api/controllers", + "@decorators": "/api/decorators", + "@middleware": "/api/middleware", + "@validators": "/api/validators", + "@config": "/config", + "@error": "/error", + "@models": "/models", + "@repositories": "/repositories", + "@services": "/services", + "@tests/(.*)": "/tests/$1", + "@customtypes(.*)": "/types$1", + "@utils": "/utils" + } } diff --git a/migrations/0020-replace-enums-with-strings.ts b/migrations/0020-replace-enums-with-strings.ts index 09dc4e37d..1e9e20860 100644 --- a/migrations/0020-replace-enums-with-strings.ts +++ b/migrations/0020-replace-enums-with-strings.ts @@ -1,6 +1,6 @@ import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm'; import { TableColumnOptions } from 'typeorm/schema-builder/options/TableColumnOptions'; -import { ActivityType, UserAccessType, UserState } from '../types'; +import { ActivityType, UserAccessType, UserState } from '@customtypes'; interface ReplacementInfo { table: string; diff --git a/models/ActivityModel.ts b/models/ActivityModel.ts index 35d026c0e..67109583e 100644 --- a/models/ActivityModel.ts +++ b/models/ActivityModel.ts @@ -1,6 +1,6 @@ import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, Index, ManyToOne, JoinColumn } from 'typeorm'; -import { ActivityScope, ActivityType, PublicActivity, Uuid } from '../types'; -import { UserModel } from '.'; +import { ActivityScope, ActivityType, PublicActivity, Uuid } from '@customtypes'; +import { UserModel } from '@models'; @Entity('Activities') @Index('sliding_leaderboard_index', ['timestamp', 'pointsEarned'], { where: '"pointsEarned" > 0' }) diff --git a/models/AttendanceModel.ts b/models/AttendanceModel.ts index 340189a65..5f9c077f8 100644 --- a/models/AttendanceModel.ts +++ b/models/AttendanceModel.ts @@ -1,6 +1,6 @@ import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, Index, ManyToOne, JoinColumn } from 'typeorm'; -import { PublicAttendance, Uuid } from '../types'; -import { UserModel, EventModel } from '.'; +import { PublicAttendance, Uuid } from '@customtypes'; +import { UserModel, EventModel } from '@models'; @Entity('Attendances') export class AttendanceModel extends BaseEntity { diff --git a/models/EventModel.ts b/models/EventModel.ts index 1ff220c70..0dcbe75b0 100644 --- a/models/EventModel.ts +++ b/models/EventModel.ts @@ -1,7 +1,7 @@ import * as moment from 'moment'; import { BaseEntity, Column, Entity, Index, PrimaryGeneratedColumn, OneToMany } from 'typeorm'; -import { PublicEvent, Uuid } from '../types'; -import { AttendanceModel, FeedbackModel, ExpressCheckinModel } from '.'; +import { PublicEvent, Uuid } from '@customtypes'; +import { AttendanceModel, FeedbackModel, ExpressCheckinModel } from '@models'; @Entity('Events') @Index('event_start_end_index', ['start', 'end']) diff --git a/models/ExpressCheckinModel.ts b/models/ExpressCheckinModel.ts index a9546bd17..97e27c681 100644 --- a/models/ExpressCheckinModel.ts +++ b/models/ExpressCheckinModel.ts @@ -1,6 +1,6 @@ import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; -import { PublicExpressCheckin, Uuid } from '../types'; -import { EventModel } from '.'; +import { PublicExpressCheckin, Uuid } from '@customtypes'; +import { EventModel } from '@models'; @Entity('ExpressCheckins') export class ExpressCheckinModel extends BaseEntity { diff --git a/models/FeedbackModel.ts b/models/FeedbackModel.ts index 899b382fc..b368f46ab 100644 --- a/models/FeedbackModel.ts +++ b/models/FeedbackModel.ts @@ -1,6 +1,6 @@ import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; -import { FeedbackStatus, FeedbackType, PublicFeedback, Uuid } from '../types'; -import { UserModel, EventModel } from '.'; +import { FeedbackStatus, FeedbackType, PublicFeedback, Uuid } from '@customtypes'; +import { UserModel, EventModel } from '@models'; @Entity('Feedback') export class FeedbackModel extends BaseEntity { diff --git a/models/MerchCollectionPhotoModel.ts b/models/MerchCollectionPhotoModel.ts index f04c74fd5..fc7e51dbb 100644 --- a/models/MerchCollectionPhotoModel.ts +++ b/models/MerchCollectionPhotoModel.ts @@ -1,6 +1,6 @@ import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; -import { PublicMerchCollectionPhoto, Uuid } from '../types'; -import { MerchandiseCollectionModel } from '.'; +import { PublicMerchCollectionPhoto, Uuid } from '@customtypes'; +import { MerchandiseCollectionModel } from '@models'; @Entity('MerchCollectionPhotos') export class MerchCollectionPhotoModel extends BaseEntity { diff --git a/models/MerchandiseCollectionModel.ts b/models/MerchandiseCollectionModel.ts index 078d3d336..7fc522cb0 100644 --- a/models/MerchandiseCollectionModel.ts +++ b/models/MerchandiseCollectionModel.ts @@ -1,6 +1,6 @@ import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, OneToMany, CreateDateColumn } from 'typeorm'; -import { Uuid, PublicMerchCollection } from '../types'; -import { MerchandiseItemModel, MerchCollectionPhotoModel } from '.'; +import { Uuid, PublicMerchCollection } from '@customtypes'; +import { MerchandiseItemModel, MerchCollectionPhotoModel } from '@models'; @Entity('MerchandiseCollections') export class MerchandiseCollectionModel extends BaseEntity { diff --git a/models/MerchandiseItemModel.ts b/models/MerchandiseItemModel.ts index f15f1ff45..1b1af2239 100644 --- a/models/MerchandiseItemModel.ts +++ b/models/MerchandiseItemModel.ts @@ -1,8 +1,8 @@ import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, Index, ManyToOne, JoinColumn, OneToMany, } from 'typeorm'; -import { Uuid, PublicMerchItem, PublicCartMerchItem } from '../types'; -import { MerchandiseCollectionModel, MerchandiseItemOptionModel, MerchandiseItemPhotoModel } from '.'; +import { Uuid, PublicMerchItem, PublicCartMerchItem } from '@customtypes'; +import { MerchandiseCollectionModel, MerchandiseItemOptionModel, MerchandiseItemPhotoModel } from '@models'; @Entity('MerchandiseItems') export class MerchandiseItemModel extends BaseEntity { diff --git a/models/MerchandiseItemOptionModel.ts b/models/MerchandiseItemOptionModel.ts index 42208eca3..14dc24cb4 100644 --- a/models/MerchandiseItemOptionModel.ts +++ b/models/MerchandiseItemOptionModel.ts @@ -1,8 +1,8 @@ import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn, OneToMany, Index, } from 'typeorm'; -import { Uuid, PublicMerchItemOption, MerchItemOptionMetadata, PublicOrderMerchItemOption } from '../types'; -import { OrderItemModel, MerchandiseItemModel } from '.'; +import { Uuid, PublicMerchItemOption, MerchItemOptionMetadata, PublicOrderMerchItemOption } from '@customtypes'; +import { OrderItemModel, MerchandiseItemModel } from '@models'; @Entity('MerchandiseItemOptions') export class MerchandiseItemOptionModel extends BaseEntity { diff --git a/models/MerchandiseItemPhotoModel.ts b/models/MerchandiseItemPhotoModel.ts index e48818f4d..1a78b1bf2 100644 --- a/models/MerchandiseItemPhotoModel.ts +++ b/models/MerchandiseItemPhotoModel.ts @@ -1,6 +1,6 @@ import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; -import { PublicMerchItemPhoto, Uuid } from '../types'; -import { MerchandiseItemModel } from '.'; +import { PublicMerchItemPhoto, Uuid } from '@customtypes'; +import { MerchandiseItemModel } from '@models'; @Entity('MerchandiseItemPhotos') export class MerchandiseItemPhotoModel extends BaseEntity { diff --git a/models/OrderItemModel.ts b/models/OrderItemModel.ts index cc6b692d7..30832b5d9 100644 --- a/models/OrderItemModel.ts +++ b/models/OrderItemModel.ts @@ -1,6 +1,6 @@ import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn } from 'typeorm'; -import { Uuid, PublicOrderItem } from '../types'; -import { OrderModel, MerchandiseItemOptionModel } from '.'; +import { Uuid, PublicOrderItem } from '@customtypes'; +import { OrderModel, MerchandiseItemOptionModel } from '@models'; @Entity('OrderItems') export class OrderItemModel extends BaseEntity { diff --git a/models/OrderModel.ts b/models/OrderModel.ts index bb0974441..e20f283ff 100644 --- a/models/OrderModel.ts +++ b/models/OrderModel.ts @@ -8,8 +8,8 @@ import { ManyToOne, JoinColumn, } from 'typeorm'; -import { Uuid, PublicOrder, OrderStatus, PublicOrderWithItems } from '../types'; -import { UserModel, OrderItemModel, OrderPickupEventModel } from '.'; +import { Uuid, PublicOrder, OrderStatus, PublicOrderWithItems } from '@customtypes'; +import { UserModel, OrderItemModel, OrderPickupEventModel } from '@models'; @Entity('Orders') export class OrderModel extends BaseEntity { diff --git a/models/OrderPickupEventModel.ts b/models/OrderPickupEventModel.ts index 6b2526b21..873830447 100644 --- a/models/OrderPickupEventModel.ts +++ b/models/OrderPickupEventModel.ts @@ -1,6 +1,6 @@ import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, JoinColumn, OneToMany, OneToOne } from 'typeorm'; -import { Uuid, PublicOrderPickupEvent, OrderPickupEventStatus } from '../types'; -import { OrderModel, EventModel } from '.'; +import { Uuid, PublicOrderPickupEvent, OrderPickupEventStatus } from '@customtypes'; +import { OrderModel, EventModel } from '@models'; @Entity('OrderPickupEvents') export class OrderPickupEventModel extends BaseEntity { diff --git a/models/ResumeModel.ts b/models/ResumeModel.ts index 223e853c3..7dc6dab05 100644 --- a/models/ResumeModel.ts +++ b/models/ResumeModel.ts @@ -1,6 +1,6 @@ import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; -import { PublicResume, Uuid } from '../types'; -import { UserModel } from '.'; +import { PublicResume, Uuid } from '@customtypes'; +import { UserModel } from '@models'; @Entity('Resumes') export class ResumeModel extends BaseEntity { diff --git a/models/UserModel.ts b/models/UserModel.ts index a8fcc4f91..310d65ca4 100644 --- a/models/UserModel.ts +++ b/models/UserModel.ts @@ -1,7 +1,7 @@ import { BaseEntity, Column, Entity, Index, PrimaryGeneratedColumn, OneToMany } from 'typeorm'; import * as bcrypt from 'bcrypt'; -import { PrivateProfile, PublicProfile, Uuid, UserAccessType, UserState } from '../types'; -import { ActivityModel, AttendanceModel, OrderModel, FeedbackModel, ResumeModel, UserSocialMediaModel } from '.'; +import { PrivateProfile, PublicProfile, Uuid, UserAccessType, UserState } from '@customtypes'; +import { ActivityModel, AttendanceModel, OrderModel, FeedbackModel, ResumeModel, UserSocialMediaModel } from '@models'; @Entity('Users') export class UserModel extends BaseEntity { diff --git a/models/UserSocialMediaModel.ts b/models/UserSocialMediaModel.ts index d7671a189..b635f7242 100644 --- a/models/UserSocialMediaModel.ts +++ b/models/UserSocialMediaModel.ts @@ -1,6 +1,6 @@ import { BaseEntity, Column, Entity, PrimaryGeneratedColumn, JoinColumn, ManyToOne } from 'typeorm'; -import { UserModel } from '.'; -import { Uuid, SocialMediaType, PublicUserSocialMedia } from '../types'; +import { Uuid, SocialMediaType, PublicUserSocialMedia } from '@customtypes'; +import { UserModel } from '@models'; @Entity('UserSocialMedia') export class UserSocialMediaModel extends BaseEntity { diff --git a/ormconfig.ts b/ormconfig.ts index 9540aec0c..aa240a96e 100644 --- a/ormconfig.ts +++ b/ormconfig.ts @@ -1,4 +1,6 @@ -import { Config, DatabaseNamingStrategy } from './config'; +import './aliases'; + +import { Config, DatabaseNamingStrategy } from '@config'; module.exports = { type: 'postgres', diff --git a/package.json b/package.json index bb1c64096..a7b0f0659 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "express": "^4.17.1", "faker": "^5.5.3", "jsonwebtoken": "^8.5.1", + "module-alias": "^2.2.3", "moment": "^2.27.0", "moment-timezone": "^0.5.34", "morgan": "^1.10.0", @@ -82,6 +83,7 @@ "@types/faker": "^5.5.5", "@types/jest": "^27.0.2", "@types/jsonwebtoken": "^8.5.0", + "@types/module-alias": "^2.0.4", "@types/morgan": "^1.9.1", "@types/multer": "^1.4.3", "@types/node": "^14.0.13", diff --git a/repositories/ActivityRepository.ts b/repositories/ActivityRepository.ts index 0f8a40efc..0a26e83c4 100644 --- a/repositories/ActivityRepository.ts +++ b/repositories/ActivityRepository.ts @@ -1,9 +1,9 @@ import { EntityRepository, Raw } from 'typeorm'; import * as moment from 'moment'; -import { ActivityScope, ActivityType, Uuid } from '../types'; -import { UserModel, ActivityModel } from '../models'; -import { BaseRepository } from '.'; -import { Activity, ActivityTypeToScope } from '../types/internal'; +import { ActivityScope, ActivityType, Uuid } from '@customtypes'; +import { Activity, ActivityTypeToScope } from '@customtypes/internal'; +import { UserModel, ActivityModel } from '@models'; +import { BaseRepository } from '@repositories'; @EntityRepository(ActivityModel) export class ActivityRepository extends BaseRepository { diff --git a/repositories/AttendanceRepository.ts b/repositories/AttendanceRepository.ts index 78f9c901a..d65b215cf 100644 --- a/repositories/AttendanceRepository.ts +++ b/repositories/AttendanceRepository.ts @@ -1,8 +1,8 @@ import { EntityRepository } from 'typeorm'; -import { ExpressCheckinModel, AttendanceModel, UserModel, EventModel } from '../models'; -import { Uuid } from '../types'; -import { BaseRepository } from '.'; -import { Attendance } from '../types/internal'; +import { Uuid } from '@customtypes'; +import { Attendance } from '@customtypes/internal'; +import { ExpressCheckinModel, AttendanceModel, UserModel, EventModel } from '@models'; +import { BaseRepository } from '@repositories'; @EntityRepository(AttendanceModel) export class AttendanceRepository extends BaseRepository { diff --git a/repositories/EventRepository.ts b/repositories/EventRepository.ts index c4f168e06..143bcd052 100644 --- a/repositories/EventRepository.ts +++ b/repositories/EventRepository.ts @@ -1,7 +1,7 @@ import { EntityRepository, SelectQueryBuilder } from 'typeorm'; -import { EventSearchOptions, Uuid } from '../types'; -import { EventModel } from '../models'; -import { BaseRepository } from '.'; +import { EventSearchOptions, Uuid } from '@customtypes'; +import { EventModel } from '@models'; +import { BaseRepository } from '@repositories'; @EntityRepository(EventModel) export class EventRepository extends BaseRepository { diff --git a/repositories/FeedbackRepository.ts b/repositories/FeedbackRepository.ts index 8c3249d96..fc2c57097 100644 --- a/repositories/FeedbackRepository.ts +++ b/repositories/FeedbackRepository.ts @@ -1,7 +1,7 @@ import { EntityRepository, SelectQueryBuilder } from 'typeorm'; -import { FeedbackModel, UserModel, EventModel } from '../models'; -import { BaseRepository } from '.'; -import { FeedbackSearchOptions, Uuid } from '../types'; +import { FeedbackSearchOptions, Uuid } from '@customtypes'; +import { FeedbackModel, UserModel, EventModel } from '@models'; +import { BaseRepository } from '@repositories'; @EntityRepository(FeedbackModel) export class FeedbackRepository extends BaseRepository { diff --git a/repositories/LeaderboardRepository.ts b/repositories/LeaderboardRepository.ts index 40ed1ca20..82b05ebab 100644 --- a/repositories/LeaderboardRepository.ts +++ b/repositories/LeaderboardRepository.ts @@ -1,9 +1,9 @@ import { EntityRepository, Not, Raw } from 'typeorm'; import * as moment from 'moment'; -import { Config } from '../config'; -import { ActivityModel, UserModel } from '../models'; -import { UserState } from '../types'; -import { BaseRepository } from '.'; +import { UserState } from '@customtypes'; +import { ActivityModel, UserModel } from '@models'; +import { Config } from '@config'; +import { BaseRepository } from '@repositories'; @EntityRepository(UserModel) export class LeaderboardRepository extends BaseRepository { diff --git a/repositories/MerchOrderRepository.ts b/repositories/MerchOrderRepository.ts index 30263fda3..4c74c9e0c 100644 --- a/repositories/MerchOrderRepository.ts +++ b/repositories/MerchOrderRepository.ts @@ -1,7 +1,7 @@ import { EntityRepository, In, SelectQueryBuilder } from 'typeorm'; -import { OrderStatus, Uuid } from '../types'; -import { OrderModel, UserModel, OrderItemModel, OrderPickupEventModel, MerchandiseItemModel } from '../models'; -import { BaseRepository } from '.'; +import { OrderStatus, Uuid } from '@customtypes'; +import { OrderModel, UserModel, OrderItemModel, OrderPickupEventModel, MerchandiseItemModel } from '@models'; +import { BaseRepository } from '@repositories'; @EntityRepository(OrderModel) export class MerchOrderRepository extends BaseRepository { diff --git a/repositories/MerchStoreRepository.ts b/repositories/MerchStoreRepository.ts index 48b735bf0..ed574bdc7 100644 --- a/repositories/MerchStoreRepository.ts +++ b/repositories/MerchStoreRepository.ts @@ -1,13 +1,13 @@ import { EntityRepository, SelectQueryBuilder } from 'typeorm'; +import { Uuid } from '@customtypes'; import { MerchandiseItemOptionModel, MerchandiseItemPhotoModel, MerchandiseCollectionModel, MerchCollectionPhotoModel, MerchandiseItemModel, -} from '../models'; -import { Uuid } from '../types'; -import { BaseRepository } from '.'; +} from '@models'; +import { BaseRepository } from '@repositories'; @EntityRepository(MerchandiseCollectionModel) export class MerchCollectionRepository extends BaseRepository { diff --git a/repositories/ResumeRepository.ts b/repositories/ResumeRepository.ts index 3d28ecddc..fb44c9045 100644 --- a/repositories/ResumeRepository.ts +++ b/repositories/ResumeRepository.ts @@ -1,6 +1,6 @@ import { EntityRepository } from 'typeorm'; -import { ResumeModel, UserModel } from '../models'; -import { BaseRepository } from '.'; +import { ResumeModel, UserModel } from '@models'; +import { BaseRepository } from '@repositories'; @EntityRepository(ResumeModel) export class ResumeRepository extends BaseRepository { diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index 805ba97e8..463535a01 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -1,9 +1,9 @@ import { EntityRepository, In } from 'typeorm'; import * as bcrypt from 'bcrypt'; -import { Activity } from '../types/internal'; -import { UserModel } from '../models'; -import { Uuid } from '../types'; -import { BaseRepository } from '.'; +import { Activity } from '@customtypes/internal'; +import { Uuid } from '@customtypes'; +import { UserModel } from '@models'; +import { BaseRepository } from '@repositories'; @EntityRepository(UserModel) export class UserRepository extends BaseRepository { diff --git a/repositories/UserSocialMediaRepository.ts b/repositories/UserSocialMediaRepository.ts index 4d69cf5d7..045bd0804 100644 --- a/repositories/UserSocialMediaRepository.ts +++ b/repositories/UserSocialMediaRepository.ts @@ -1,7 +1,7 @@ import { EntityRepository } from 'typeorm'; -import { SocialMediaType, Uuid } from 'types'; -import { UserSocialMediaModel, UserModel } from '../models'; -import { BaseRepository } from '.'; +import { SocialMediaType, Uuid } from '@customtypes'; +import { UserSocialMediaModel, UserModel } from '@models'; +import { BaseRepository } from '@repositories'; @EntityRepository(UserSocialMediaModel) export class UserSocialMediaRepository extends BaseRepository { diff --git a/services/AttendanceService.ts b/services/AttendanceService.ts index 6f61ac54e..a8a7856f1 100644 --- a/services/AttendanceService.ts +++ b/services/AttendanceService.ts @@ -3,12 +3,12 @@ import { InjectManager } from 'typeorm-typedi-extensions'; import { BadRequestError, ForbiddenError, NotFoundError } from 'routing-controllers'; import { EntityManager } from 'typeorm'; import * as moment from 'moment'; -import { ActivityType, PublicAttendance, PublicExpressCheckin, Uuid } from '../types'; -import { Config } from '../config'; -import { UserModel, EventModel, AttendanceModel } from '../models'; -import { UserError } from '../utils'; -import { Repositories, TransactionsManager } from '../repositories'; -import { Activity, Attendance } from '../types/internal'; +import { ActivityType, PublicAttendance, PublicExpressCheckin, Uuid } from '@customtypes'; +import { Activity, Attendance } from '@customtypes/internal'; +import { Repositories, TransactionsManager } from '@repositories'; +import { UserModel, EventModel, AttendanceModel } from '@models'; +import { Config } from '@config'; +import { UserError } from '@utils'; @Service() export class AttendanceService { diff --git a/services/EmailService.ts b/services/EmailService.ts index 098631ba9..615619a45 100644 --- a/services/EmailService.ts +++ b/services/EmailService.ts @@ -2,9 +2,9 @@ import { MailService, MailDataRequired } from '@sendgrid/mail'; import * as ejs from 'ejs'; import * as fs from 'fs'; import * as path from 'path'; -import { logger as log } from '../utils'; -import { Config } from '../config'; -import { Uuid } from '../types'; +import { Uuid } from '@customtypes'; +import { Config } from '@config'; +import { logger as log } from '@utils'; type EmailData = MailDataRequired; diff --git a/services/EventService.ts b/services/EventService.ts index fa6a5aee8..2e98a881d 100644 --- a/services/EventService.ts +++ b/services/EventService.ts @@ -2,10 +2,10 @@ import { Service } from 'typedi'; import { InjectManager } from 'typeorm-typedi-extensions'; import { ForbiddenError, NotFoundError } from 'routing-controllers'; import { EntityManager } from 'typeorm'; -import { EventModel } from '../models'; -import { Uuid, PublicEvent, Event, EventSearchOptions } from '../types'; -import { Repositories, TransactionsManager } from '../repositories'; -import { UserError } from '../utils'; +import { Uuid, PublicEvent, Event, EventSearchOptions } from '@customtypes'; +import { Repositories, TransactionsManager } from '@repositories'; +import { EventModel } from '@models'; +import { UserError } from '@utils'; @Service() export class EventService { diff --git a/services/FeedbackService.ts b/services/FeedbackService.ts index 2174d1099..2b2bab138 100644 --- a/services/FeedbackService.ts +++ b/services/FeedbackService.ts @@ -2,10 +2,10 @@ import { Service } from 'typedi'; import { EntityManager } from 'typeorm'; import { InjectManager } from 'typeorm-typedi-extensions'; import { NotFoundError } from 'routing-controllers'; -import { FeedbackModel, UserModel } from '../models'; -import { Repositories, TransactionsManager } from '../repositories'; -import { PublicFeedback, Feedback, Uuid, ActivityType, FeedbackStatus, FeedbackSearchOptions } from '../types'; -import { UserError } from '../utils'; +import { PublicFeedback, Feedback, Uuid, ActivityType, FeedbackStatus, FeedbackSearchOptions } from '@customtypes'; +import { Repositories, TransactionsManager } from '@repositories'; +import { FeedbackModel, UserModel } from '@models'; +import { UserError } from '@utils'; @Service() export class FeedbackService { diff --git a/services/MerchStoreService.ts b/services/MerchStoreService.ts index 52befc9c7..80e348363 100644 --- a/services/MerchStoreService.ts +++ b/services/MerchStoreService.ts @@ -4,19 +4,7 @@ import { NotFoundError, ForbiddenError } from 'routing-controllers'; import { EntityManager } from 'typeorm'; import { difference, flatten, intersection } from 'underscore'; import * as moment from 'moment-timezone'; -import { MerchItemWithQuantity, OrderItemPriceAndQuantity } from 'types/internal'; -import { - MerchandiseItemOptionModel, - MerchandiseItemModel, - OrderModel, - UserModel, - EventModel, - MerchandiseCollectionModel, - MerchCollectionPhotoModel, - OrderItemModel, - OrderPickupEventModel, - MerchandiseItemPhotoModel, -} from '../models'; +import { MerchItemWithQuantity, OrderItemPriceAndQuantity } from '@customtypes/internal'; import { Uuid, PublicMerchCollection, @@ -38,10 +26,22 @@ import { MerchItemPhoto, PublicMerchCollectionPhoto, MerchCollectionPhoto, -} from '../types'; -import { Repositories, TransactionsManager } from '../repositories'; -import { EmailService, OrderInfo, OrderPickupEventInfo } from '.'; -import { UserError } from '../utils'; +} from '@customtypes'; +import { Repositories, TransactionsManager } from '@repositories'; +import { + MerchandiseItemOptionModel, + MerchandiseItemModel, + OrderModel, + UserModel, + EventModel, + MerchandiseCollectionModel, + MerchCollectionPhotoModel, + OrderItemModel, + OrderPickupEventModel, + MerchandiseItemPhotoModel, +} from '@models'; +import { EmailService, OrderInfo, OrderPickupEventInfo } from '@services'; +import { UserError } from '@utils'; @Service() export class MerchStoreService { diff --git a/services/PermissionsService.ts b/services/PermissionsService.ts index 76a105f6d..4b2ec8455 100644 --- a/services/PermissionsService.ts +++ b/services/PermissionsService.ts @@ -1,6 +1,6 @@ import { Service } from 'typedi'; -import { UserModel } from '../models'; -import { UserState, PublicOrder } from '../types'; +import { UserState, PublicOrder } from '@customtypes'; +import { UserModel } from '@models'; @Service() export class PermissionsService { diff --git a/services/ResumeService.ts b/services/ResumeService.ts index 0fbcaaf1e..6f9c3de1e 100644 --- a/services/ResumeService.ts +++ b/services/ResumeService.ts @@ -2,9 +2,9 @@ import { ForbiddenError, NotFoundError } from 'routing-controllers'; import { Service } from 'typedi'; import { EntityManager } from 'typeorm'; import { InjectManager } from 'typeorm-typedi-extensions'; -import { ActivityType, ResumePatches } from '../types'; -import { ResumeModel, UserModel } from '../models'; -import { Repositories, TransactionsManager } from '../repositories'; +import { ActivityType, ResumePatches } from '@customtypes'; +import { Repositories, TransactionsManager } from '@repositories'; +import { ResumeModel, UserModel } from '@models'; @Service() export class ResumeService { diff --git a/services/StorageService.ts b/services/StorageService.ts index 07d115896..b142ebbce 100644 --- a/services/StorageService.ts +++ b/services/StorageService.ts @@ -4,8 +4,8 @@ import * as path from 'path'; import * as multer from 'multer'; import { InternalServerError } from 'routing-controllers'; import AmazonS3URI = require('amazon-s3-uri'); -import { Config } from '../config'; -import { MediaType } from '../types'; +import { MediaType } from '@customtypes'; +import { Config } from '@config'; type File = Express.Multer.File; type FileOptions = multer.Options; diff --git a/services/UserAccountService.ts b/services/UserAccountService.ts index 83a2f4f78..1df9a05c9 100644 --- a/services/UserAccountService.ts +++ b/services/UserAccountService.ts @@ -4,13 +4,12 @@ import { InjectManager } from 'typeorm-typedi-extensions'; import { EntityManager } from 'typeorm'; import * as moment from 'moment'; import * as faker from 'faker'; -import { UserAccessUpdates } from 'api/validators'; +import { UserAccessUpdates } from '@validators'; import { RegExpMatcher, englishDataset, englishRecommendedTransformers, } from 'obscenity'; -import { Repositories, TransactionsManager, UserRepository } from '../repositories'; import { Uuid, PublicProfile, @@ -20,8 +19,9 @@ import { UserPatches, UserState, PrivateProfile, -} from '../types'; -import { UserModel } from '../models'; +} from '@customtypes'; +import { Repositories, TransactionsManager, UserRepository } from '@repositories'; +import { UserModel } from '@models'; @Service() export class UserAccountService { diff --git a/services/UserAuthService.ts b/services/UserAuthService.ts index 9191ef619..c773500bb 100644 --- a/services/UserAuthService.ts +++ b/services/UserAuthService.ts @@ -4,12 +4,11 @@ import * as crypto from 'crypto'; import * as jwt from 'jsonwebtoken'; import { InjectManager } from 'typeorm-typedi-extensions'; import { EntityManager } from 'typeorm'; -import { ExpressCheckinModel } from 'models'; -import { Repositories, UserRepository, TransactionsManager } from '../repositories'; -import { Uuid, ActivityType, UserState, UserRegistration } from '../types'; -import { Config } from '../config'; -import { UserModel } from '../models'; -import { UserAccountService } from '.'; +import { ExpressCheckinModel, UserModel } from '@models'; +import { Uuid, ActivityType, UserState, UserRegistration } from '@customtypes'; +import { Repositories, UserRepository, TransactionsManager } from '@repositories'; +import { Config } from '@config'; +import { UserAccountService } from '@services'; interface AuthToken { uuid: Uuid; diff --git a/services/UserSocialMediaService.ts b/services/UserSocialMediaService.ts index 20521eee4..1a1e3accb 100644 --- a/services/UserSocialMediaService.ts +++ b/services/UserSocialMediaService.ts @@ -2,10 +2,10 @@ import { Service } from 'typedi'; import { EntityManager } from 'typeorm'; import { InjectManager } from 'typeorm-typedi-extensions'; import { ForbiddenError, NotFoundError } from 'routing-controllers'; -import { UserError } from '../utils'; -import { UserSocialMediaModel, UserModel } from '../models'; -import { Repositories, TransactionsManager } from '../repositories'; -import { Uuid, SocialMedia, SocialMediaPatches } from '../types'; +import { Uuid, SocialMedia, SocialMediaPatches } from '@customtypes'; +import { Repositories, TransactionsManager } from '@repositories'; +import { UserSocialMediaModel, UserModel } from '@models'; +import { UserError } from '@utils'; @Service() export class UserSocialMediaService { diff --git a/tests/Seeds.ts b/tests/Seeds.ts index b26a139bf..2e42de0df 100644 --- a/tests/Seeds.ts +++ b/tests/Seeds.ts @@ -1,5 +1,7 @@ +import '../aliases'; + import * as moment from 'moment'; -import { UserAccessType, SocialMediaType, FeedbackStatus, FeedbackType } from '../types'; +import { UserAccessType, SocialMediaType, FeedbackStatus, FeedbackType } from '@customtypes'; import { DatabaseConnection, EventFactory, @@ -9,7 +11,7 @@ import { ResumeFactory, UserSocialMediaFactory, FeedbackFactory, -} from './data'; +} from '@tests/data'; function getGraduationYear(n: number) { return moment().year() + n; diff --git a/tests/admin.test.ts b/tests/admin.test.ts index 94878a0c2..5e3f802b6 100644 --- a/tests/admin.test.ts +++ b/tests/admin.test.ts @@ -1,9 +1,9 @@ import { BadRequestError, ForbiddenError } from 'routing-controllers'; import { In } from 'typeorm'; -import { ActivityScope, ActivityType, SubmitAttendanceForUsersRequest, UserAccessType } from '../types'; -import { ControllerFactory } from './controllers'; -import { DatabaseConnection, EventFactory, PortalState, UserFactory } from './data'; -import { UserModel } from '../models'; +import { ControllerFactory } from '@tests/controllers'; +import { ActivityScope, ActivityType, SubmitAttendanceForUsersRequest, UserAccessType } from '@customtypes'; +import { DatabaseConnection, EventFactory, PortalState, UserFactory } from '@tests/data'; +import { UserModel } from '@models'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/attendance.test.ts b/tests/attendance.test.ts index 62b1b55a6..179eda2c3 100644 --- a/tests/attendance.test.ts +++ b/tests/attendance.test.ts @@ -1,9 +1,9 @@ import * as faker from 'faker'; import * as moment from 'moment'; import { ForbiddenError } from 'routing-controllers'; -import { ActivityType, UserAccessType } from '../types'; -import { ControllerFactory } from './controllers'; -import { DatabaseConnection, EventFactory, PortalState, UserFactory } from './data'; +import { ControllerFactory } from '@tests/controllers'; +import { ActivityType, UserAccessType } from '@customtypes'; +import { DatabaseConnection, EventFactory, PortalState, UserFactory } from '@tests/data'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/auth.test.ts b/tests/auth.test.ts index fb6327820..0a065fe5a 100644 --- a/tests/auth.test.ts +++ b/tests/auth.test.ts @@ -3,11 +3,8 @@ import * as bcrypt from 'bcrypt'; import { NotFoundError } from 'routing-controllers'; import { anyString, instance, mock, verify, when } from 'ts-mockito'; import * as faker from 'faker'; -import { Config } from '../config'; -import { UserModel, AttendanceModel, ActivityModel } from '../models'; -import { EmailService, UserAuthService } from '../services'; -import { ActivityType, UserAccessType, UserState } from '../types'; -import { ControllerFactory } from './controllers'; +import { ActivityType, UserAccessType, UserState } from '@customtypes'; +import { ControllerFactory } from '@tests/controllers'; import { DatabaseConnection, FactoryUtils, @@ -15,7 +12,10 @@ import { PortalState, UserFactory, UserRegistrationFactory, -} from './data'; +} from '@tests/data'; +import { EmailService, UserAuthService } from '@services'; +import { UserModel, AttendanceModel, ActivityModel } from '@models'; +import { Config } from '@config'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/controllers/ControllerFactory.ts b/tests/controllers/ControllerFactory.ts index 345536aef..fab6fd736 100644 --- a/tests/controllers/ControllerFactory.ts +++ b/tests/controllers/ControllerFactory.ts @@ -10,7 +10,7 @@ import { MerchStoreService, ResumeService, UserSocialMediaService, -} from '../../services'; +} from '@services'; import { FeedbackController, UserController, @@ -21,7 +21,7 @@ import { LeaderboardController, MerchStoreController, ResumeController, -} from '../../api/controllers'; +} from '@controllers'; export class ControllerFactory { public static user(conn: Connection, storageService = new StorageService()): UserController { diff --git a/tests/controllers/MerchStoreControllerWrapper.ts b/tests/controllers/MerchStoreControllerWrapper.ts index bb72e5b37..e9752013b 100644 --- a/tests/controllers/MerchStoreControllerWrapper.ts +++ b/tests/controllers/MerchStoreControllerWrapper.ts @@ -1,9 +1,9 @@ import * as moment from 'moment'; import { Connection } from 'typeorm'; -import { MerchStoreController } from '../../api/controllers'; -import { UuidParam } from '../../api/validators'; -import { OrderPickupEventModel, UserModel } from '../../models'; -import { FulfillMerchOrderRequest } from '../../types'; +import { FulfillMerchOrderRequest } from '@customtypes'; +import { OrderPickupEventModel, UserModel } from '@models'; +import { UuidParam } from '@validators'; +import { MerchStoreController } from '@controllers'; /** * Wrapper class over MerchStoreController for performing merch controller diff --git a/tests/data/DatabaseConnection.ts b/tests/data/DatabaseConnection.ts index 857f32f39..776d0c1ec 100644 --- a/tests/data/DatabaseConnection.ts +++ b/tests/data/DatabaseConnection.ts @@ -1,6 +1,6 @@ import { Connection, createConnection } from 'typeorm'; -import { Config } from '../../config'; -import { models as entities } from '../../models'; +import { models as entities } from '@models'; +import { Config } from '@config'; export class DatabaseConnection { private static conn: Connection = null; diff --git a/tests/data/EventFactory.ts b/tests/data/EventFactory.ts index e398edfb5..bdcc1dee5 100644 --- a/tests/data/EventFactory.ts +++ b/tests/data/EventFactory.ts @@ -1,8 +1,8 @@ import * as faker from 'faker'; import * as moment from 'moment'; import { v4 as uuid } from 'uuid'; -import { EventModel } from '../../models'; -import { FactoryUtils } from '.'; +import { EventModel } from '@models'; +import { FactoryUtils } from '@tests/data'; export class EventFactory { private static readonly ORGS = [ diff --git a/tests/data/FeedbackFactory.ts b/tests/data/FeedbackFactory.ts index 4457cc96b..893139e1c 100644 --- a/tests/data/FeedbackFactory.ts +++ b/tests/data/FeedbackFactory.ts @@ -1,8 +1,8 @@ import * as faker from 'faker'; import { v4 as uuid } from 'uuid'; -import { FeedbackStatus, FeedbackType } from '../../types'; -import { FactoryUtils, UserFactory, EventFactory } from '.'; -import { FeedbackModel } from '../../models'; +import { FeedbackStatus, FeedbackType } from '@customtypes'; +import { FeedbackModel } from '@models'; +import { FactoryUtils, UserFactory, EventFactory } from '@tests/data'; export class FeedbackFactory { public static create(n: number): FeedbackModel[] { diff --git a/tests/data/FileFactory.ts b/tests/data/FileFactory.ts index 86809a33b..d18380f8c 100644 --- a/tests/data/FileFactory.ts +++ b/tests/data/FileFactory.ts @@ -1,4 +1,4 @@ -import { File } from '../../types'; +import { File } from '@customtypes'; const ONE_BYTE_FILLER = 'a'; diff --git a/tests/data/MerchFactory.ts b/tests/data/MerchFactory.ts index f0b15c9d0..2579489b8 100644 --- a/tests/data/MerchFactory.ts +++ b/tests/data/MerchFactory.ts @@ -1,7 +1,7 @@ import * as faker from 'faker'; import * as moment from 'moment'; import { v4 as uuid } from 'uuid'; -import { MerchItemOptionMetadata, OrderPickupEventStatus } from '../../types'; +import { MerchItemOptionMetadata, OrderPickupEventStatus } from '@customtypes'; import { OrderPickupEventModel, MerchandiseCollectionModel, @@ -9,8 +9,8 @@ import { MerchandiseItemModel, MerchandiseItemOptionModel, MerchandiseItemPhotoModel, -} from '../../models'; -import { FactoryUtils } from '.'; +} from '@models'; +import { FactoryUtils } from '@tests/data'; export class MerchFactory { public static fakeCollection(substitute?: Partial): MerchandiseCollectionModel { diff --git a/tests/data/PortalState.ts b/tests/data/PortalState.ts index 09f0de9fe..3432366cf 100644 --- a/tests/data/PortalState.ts +++ b/tests/data/PortalState.ts @@ -1,6 +1,7 @@ import * as rfdc from 'rfdc'; import { flatten } from 'underscore'; import * as moment from 'moment'; +import { ActivityScope, ActivityType } from '@customtypes'; import { OrderPickupEventModel, MerchandiseItemModel, @@ -16,10 +17,8 @@ import { UserSocialMediaModel, ResumeModel, ExpressCheckinModel, -} from '../../models'; -import { ActivityScope, ActivityType } from '../../types'; -import { DatabaseConnection } from '.'; -import { MerchFactory } from '.'; +} from '@models'; +import { DatabaseConnection, MerchFactory } from '@tests/data'; export class PortalState { users: UserModel[] = []; diff --git a/tests/data/ResumeFactory.ts b/tests/data/ResumeFactory.ts index 2cf7996a1..9180d7dca 100644 --- a/tests/data/ResumeFactory.ts +++ b/tests/data/ResumeFactory.ts @@ -1,8 +1,7 @@ import * as faker from 'faker'; import { v4 as uuid } from 'uuid'; -import { ResumeModel } from '../../models'; -import { FactoryUtils } from '.'; -import { UserFactory } from '.'; +import { ResumeModel } from '@models'; +import { FactoryUtils, UserFactory } from '@tests/data'; export class ResumeFactory { public static create(n: number) { diff --git a/tests/data/UserFactory.ts b/tests/data/UserFactory.ts index 3ece1f844..1e7d5706b 100644 --- a/tests/data/UserFactory.ts +++ b/tests/data/UserFactory.ts @@ -1,10 +1,10 @@ import * as faker from 'faker'; import * as moment from 'moment'; import { v4 as uuid } from 'uuid'; -import { UserAccountService } from '../../services'; -import { UserAccessType, UserState } from '../../types'; -import { UserModel } from '../../models'; -import { FactoryUtils } from '.'; +import { UserAccessType, UserState } from '@customtypes'; +import { UserAccountService } from '@services'; +import { UserModel } from '@models'; +import { FactoryUtils } from '@tests/data'; export class UserFactory { public static readonly PASSWORD_RAW = 'password'; diff --git a/tests/data/UserRegistrationFactory.ts b/tests/data/UserRegistrationFactory.ts index 7659f906e..043983abe 100644 --- a/tests/data/UserRegistrationFactory.ts +++ b/tests/data/UserRegistrationFactory.ts @@ -1,7 +1,6 @@ -import { UserRegistration } from 'types'; +import { UserRegistration } from '@customtypes'; import * as faker from 'faker'; -import { FactoryUtils } from '.'; -import { UserFactory } from '.'; +import { FactoryUtils, UserFactory } from '@tests/data'; export class UserRegistrationFactory { public static create(n: number) { diff --git a/tests/data/UserSocialMediaFactory.ts b/tests/data/UserSocialMediaFactory.ts index 3f8ec88b0..71eee448c 100644 --- a/tests/data/UserSocialMediaFactory.ts +++ b/tests/data/UserSocialMediaFactory.ts @@ -1,9 +1,8 @@ import * as faker from 'faker'; import { v4 as uuid } from 'uuid'; -import { UserSocialMediaModel } from '../../models'; -import { SocialMediaType } from '../../types'; -import { FactoryUtils } from '.'; -import { UserFactory } from '.'; +import { SocialMediaType } from '@customtypes'; +import { UserSocialMediaModel } from '@models'; +import { FactoryUtils, UserFactory } from '@tests/data'; export class UserSocialMediaFactory { public static create(n: number): UserSocialMediaModel[] { diff --git a/tests/event.test.ts b/tests/event.test.ts index 499b99ea5..8e790376c 100644 --- a/tests/event.test.ts +++ b/tests/event.test.ts @@ -1,10 +1,10 @@ import * as moment from 'moment'; import { ForbiddenError } from 'routing-controllers'; -import { UserAccessType } from '../types'; -import { ControllerFactory } from './controllers'; -import { DatabaseConnection, EventFactory, PortalState, UserFactory } from './data'; +import { UserAccessType } from '@customtypes'; +import { ControllerFactory } from '@tests/controllers'; +import { DatabaseConnection, EventFactory, PortalState, UserFactory } from '@tests/data'; +import { EventModel } from '@models'; import { CreateEventRequest } from '../api/validators/EventControllerRequests'; -import { EventModel } from '../models'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/expressCheckin.test.ts b/tests/expressCheckin.test.ts index fae35a490..bfa4aadcf 100644 --- a/tests/expressCheckin.test.ts +++ b/tests/expressCheckin.test.ts @@ -1,10 +1,10 @@ import * as faker from 'faker'; -import { } from '../types'; +import { } from '@customtypes'; import { anything, instance, mock, verify, when } from 'ts-mockito'; -import { ControllerFactory } from './controllers'; -import { DatabaseConnection, EventFactory, PortalState, UserFactory } from './data'; -import { EmailService } from '../services'; -import { ExpressCheckinModel } from '../models'; +import { ControllerFactory } from '@tests/controllers'; +import { DatabaseConnection, EventFactory, PortalState, UserFactory } from '@tests/data'; +import { EmailService } from '@services'; +import { ExpressCheckinModel } from '@models'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/feedback.test.ts b/tests/feedback.test.ts index 5b63a78c2..fcef0bb9a 100644 --- a/tests/feedback.test.ts +++ b/tests/feedback.test.ts @@ -1,9 +1,9 @@ import { validate } from 'class-validator'; import { plainToClass } from 'class-transformer'; -import { DatabaseConnection, EventFactory, PortalState, UserFactory, FeedbackFactory } from './data'; -import { ActivityScope, ActivityType, FeedbackStatus, FeedbackType, UserAccessType } from '../types'; +import { ActivityScope, ActivityType, FeedbackStatus, FeedbackType, UserAccessType } from '@customtypes'; +import { ControllerFactory } from '@tests/controllers'; +import { DatabaseConnection, EventFactory, PortalState, UserFactory, FeedbackFactory } from '@tests/data'; import { Feedback } from '../api/validators/FeedbackControllerRequests'; -import { ControllerFactory } from './controllers'; function buildFeedbackRequest(feedback) { return { diff --git a/tests/merchOrder.test.ts b/tests/merchOrder.test.ts index 5f78fad57..c48b538d1 100644 --- a/tests/merchOrder.test.ts +++ b/tests/merchOrder.test.ts @@ -2,11 +2,11 @@ import * as faker from 'faker'; import * as moment from 'moment'; import { mock, when, anything, instance, verify, anyString } from 'ts-mockito'; import { ForbiddenError, NotFoundError } from 'routing-controllers'; -import { EmailService } from '../services'; -import { OrderModel, OrderPickupEventModel, UserModel } from '../models'; -import { UserAccessType, OrderStatus, ActivityType, OrderPickupEventStatus } from '../types'; -import { ControllerFactory, MerchStoreControllerWrapper } from './controllers'; -import { DatabaseConnection, EventFactory, MerchFactory, PortalState, UserFactory } from './data'; +import { UserAccessType, OrderStatus, ActivityType, OrderPickupEventStatus } from '@customtypes'; +import { ControllerFactory, MerchStoreControllerWrapper } from '@tests/controllers'; +import { DatabaseConnection, EventFactory, MerchFactory, PortalState, UserFactory } from '@tests/data'; +import { EmailService } from '@services'; +import { OrderModel, OrderPickupEventModel, UserModel } from '@models'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/merchStore.test.ts b/tests/merchStore.test.ts index 41982265d..ad641e90d 100644 --- a/tests/merchStore.test.ts +++ b/tests/merchStore.test.ts @@ -2,13 +2,13 @@ import * as faker from 'faker'; import { ForbiddenError, NotFoundError } from 'routing-controllers'; import { zip } from 'underscore'; import { anything, instance, verify, mock, when } from 'ts-mockito'; -import { OrderModel, MerchandiseItemOptionModel } from '../models'; -import { MediaType, MerchItemEdit, UserAccessType } from '../types'; -import { ControllerFactory } from './controllers'; -import { DatabaseConnection, MerchFactory, PortalState, UserFactory, FileFactory } from './data'; -import { EmailService } from '../services'; -import { Config } from '../config'; -import { Mocks } from './mocks'; +import { MediaType, MerchItemEdit, UserAccessType } from '@customtypes'; +import { ControllerFactory } from '@tests/controllers'; +import { DatabaseConnection, MerchFactory, PortalState, UserFactory, FileFactory } from '@tests/data'; +import { Mocks } from '@tests/mocks'; +import { EmailService } from '@services'; +import { OrderModel, MerchandiseItemOptionModel } from '@models'; +import { Config } from '@config'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/mocks/MockFactory.ts b/tests/mocks/MockFactory.ts index 0b791b321..938e87454 100644 --- a/tests/mocks/MockFactory.ts +++ b/tests/mocks/MockFactory.ts @@ -1,5 +1,5 @@ import { anything, mock, when } from 'ts-mockito'; -import { StorageService } from '../../services'; +import { StorageService } from '@services'; const DEFAULT_FILE_URL = 'https://s3.amazonaws.com/default-file-url.pdf'; diff --git a/tests/resume.test.ts b/tests/resume.test.ts index 408bc2cab..cc1c1cdfc 100644 --- a/tests/resume.test.ts +++ b/tests/resume.test.ts @@ -1,11 +1,11 @@ import { BadRequestError, ForbiddenError } from 'routing-controllers'; import { anything, instance, verify } from 'ts-mockito'; -import { ActivityType, UserAccessType, MediaType } from '../types'; -import { ResumeModel, ActivityModel } from '../models'; -import { Config } from '../config'; -import { ControllerFactory } from './controllers'; -import { DatabaseConnection, PortalState, UserFactory, FileFactory, ResumeFactory } from './data'; -import { Mocks } from './mocks'; +import { ControllerFactory } from '@tests/controllers'; +import { ActivityType, UserAccessType, MediaType } from '@customtypes'; +import { DatabaseConnection, PortalState, UserFactory, FileFactory, ResumeFactory } from '@tests/data'; +import { Mocks } from '@tests/mocks'; +import { ResumeModel, ActivityModel } from '@models'; +import { Config } from '@config'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/sample.test.ts b/tests/sample.test.ts index e96235b2c..0cb3ee881 100644 --- a/tests/sample.test.ts +++ b/tests/sample.test.ts @@ -1,4 +1,5 @@ -import { ActivityType } from '../types'; +import { ActivityType } from '@customtypes'; +import { DatabaseConnection, UserFactory, EventFactory, MerchFactory, PortalState, FeedbackFactory } from '@tests/data'; import { ActivityModel, AttendanceModel, @@ -7,8 +8,7 @@ import { OrderModel, MerchandiseItemModel, MerchandiseCollectionModel, -} from '../models'; -import { DatabaseConnection, UserFactory, EventFactory, MerchFactory, PortalState, FeedbackFactory } from './data'; +} from '@models'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tests/user.handles.test.ts b/tests/user.handles.test.ts index 4fc78637c..d66c502a5 100644 --- a/tests/user.handles.test.ts +++ b/tests/user.handles.test.ts @@ -2,9 +2,9 @@ import 'reflect-metadata'; // this shim is required import { plainToClass } from 'class-transformer'; import { validate } from 'class-validator'; import * as faker from 'faker'; -import { UserPatches } from '../api/validators'; -import { ControllerFactory } from './controllers'; -import { DatabaseConnection, PortalState, UserFactory } from './data'; +import { ControllerFactory } from '@tests/controllers'; +import { DatabaseConnection, PortalState, UserFactory } from '@tests/data'; +import { UserPatches } from '@validators'; // Required to pass class-validator validation on user patch even for optional fields const passwordChange = { diff --git a/tests/userSocialMedia.test.ts b/tests/userSocialMedia.test.ts index 9df719444..e64f6637f 100644 --- a/tests/userSocialMedia.test.ts +++ b/tests/userSocialMedia.test.ts @@ -1,10 +1,10 @@ import faker = require('faker'); import { Connection } from 'typeorm'; -import { UserModel } from '../models'; -import { SocialMediaType } from '../types'; -import { ControllerFactory } from './controllers'; -import { DatabaseConnection, PortalState, UserFactory, UserSocialMediaFactory } from './data'; -import { UserController } from '../api/controllers'; +import { SocialMediaType } from '@customtypes'; +import { ControllerFactory } from '@tests/controllers'; +import { DatabaseConnection, PortalState, UserFactory, UserSocialMediaFactory } from '@tests/data'; +import { UserModel } from '@models'; +import { UserController } from '@controllers'; beforeAll(async () => { await DatabaseConnection.connect(); diff --git a/tsconfig.json b/tsconfig.json index 6474561e4..db3e3eac5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,22 @@ "moduleResolution": "node", "baseUrl": ".", "outDir": "./build", - "declaration": true + "declaration": true, + "paths": { + "@controllers": ["api/controllers"], + "@decorators": ["api/decorators"], + "@middleware": ["api/middleware"], + "@validators": ["api/validators"], + "@config": ["config"], + "@error": ["error"], + "@models": ["models"], + "@repositories": ["repositories"], + "@services": ["services"], + "@tests/*": ["tests/*"], + "@customtypes": ["types"], + "@customtypes/*": ["types/*"], + "@utils": ["utils"], + } }, "include": [ "./**/*.ts" diff --git a/types/ApiRequests.ts b/types/ApiRequests.ts index 2f4ee4dd5..fb8a5905b 100644 --- a/types/ApiRequests.ts +++ b/types/ApiRequests.ts @@ -1,4 +1,4 @@ -import { Uuid, FeedbackStatus, FeedbackType, SocialMediaType, UserAccessType } from '.'; +import { Uuid, FeedbackStatus, FeedbackType, SocialMediaType, UserAccessType } from '@customtypes'; // REQUEST TYPES diff --git a/types/ApiResponses.ts b/types/ApiResponses.ts index 4f28950f5..e9ddcf32e 100644 --- a/types/ApiResponses.ts +++ b/types/ApiResponses.ts @@ -9,7 +9,7 @@ import { SocialMediaType, MerchItemOptionMetadata, Uuid, -} from '.'; +} from '@customtypes'; // RESPONSE TYPES diff --git a/types/internal/index.ts b/types/internal/index.ts index 8967c1c04..e8f6c2ccf 100644 --- a/types/internal/index.ts +++ b/types/internal/index.ts @@ -1,5 +1,5 @@ -import { MerchandiseItemModel, EventModel, UserModel } from '../../models'; -import { ActivityScope, ActivityType } from '..'; +import { MerchandiseItemModel, EventModel, UserModel } from '@models'; +import { ActivityScope, ActivityType } from '@customtypes'; export type Attendance = { user: UserModel, diff --git a/utils/AuthActionMetadata.ts b/utils/AuthActionMetadata.ts index 9b0c22dca..92a91f8f1 100644 --- a/utils/AuthActionMetadata.ts +++ b/utils/AuthActionMetadata.ts @@ -1,5 +1,5 @@ -import { Uuid } from '../types'; -import { UserModel } from '../models'; +import { Uuid } from '@customtypes'; +import { UserModel } from '@models'; export interface AuthActionMetadata { trace_id: string; diff --git a/utils/Logger.ts b/utils/Logger.ts index 83808b232..c7d0238e6 100644 --- a/utils/Logger.ts +++ b/utils/Logger.ts @@ -1,6 +1,6 @@ import * as winston from 'winston'; import 'winston-daily-rotate-file'; -import { Config } from '../config'; +import { Config } from '@config'; export const logger = winston.createLogger({ level: Config.logging.level, diff --git a/yarn.lock b/yarn.lock index c84255721..76e6cad0c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -791,6 +791,11 @@ resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a" integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw== +"@types/module-alias@^2.0.4": + version "2.0.4" + resolved "https://registry.yarnpkg.com/@types/module-alias/-/module-alias-2.0.4.tgz#c6a784be6bc2ff5424889e23084ac001454d5f00" + integrity sha512-5+G/QXO/DvHZw60FjvbDzO4JmlD/nG5m2/vVGt25VN1eeP3w2bCoks1Wa7VuptMPM1TxJdx6RjO70N9Fw0nZPA== + "@types/morgan@^1.9.1": version "1.9.3" resolved "https://registry.yarnpkg.com/@types/morgan/-/morgan-1.9.3.tgz#ae04180dff02c437312bc0cfb1e2960086b2f540" @@ -4139,6 +4144,11 @@ mkdirp@^1.0.3, mkdirp@^1.0.4: resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e" integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw== +module-alias@^2.2.3: + version "2.2.3" + resolved "https://registry.yarnpkg.com/module-alias/-/module-alias-2.2.3.tgz#ec2e85c68973bda6ab71ce7c93b763ec96053221" + integrity sha512-23g5BFj4zdQL/b6tor7Ji+QY4pEfNH784BMslY9Qb0UnJWRAt+lQGLYmRaM0KDBwIG23ffEBELhZDP2rhi9f/Q== + moment-timezone@^0.5.34: version "0.5.34" resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.34.tgz#a75938f7476b88f155d3504a9343f7519d9a405c" From 5164bac7bd2f6521cca40aae7a342e6f8d2dafea Mon Sep 17 00:00:00 2001 From: Eric Chang <55172722+echang594@users.noreply.github.com> Date: Wed, 24 Apr 2024 17:18:19 -0700 Subject: [PATCH 5/5] Added comment about changing aliases --- aliases.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/aliases.ts b/aliases.ts index 8ce5e29a9..33268155e 100644 --- a/aliases.ts +++ b/aliases.ts @@ -1,5 +1,6 @@ import { addAliases } from 'module-alias'; +// Any changes to aliases must be mirrored in tsconfig.json and jest.config.json as well!! addAliases({ '@controllers': `${__dirname}/api/controllers`, '@decorators': `${__dirname}/api/decorators`,