diff --git a/models/ActivityModel.ts b/models/ActivityModel.ts index 7f31346e..711898da 100644 --- a/models/ActivityModel.ts +++ b/models/ActivityModel.ts @@ -1,11 +1,11 @@ -import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, Index, ManyToOne, JoinColumn } from 'typeorm'; +import { Entity, Column, PrimaryGeneratedColumn, Index, ManyToOne, JoinColumn } from 'typeorm'; import { ActivityScope, ActivityType, PublicActivity, Uuid } from '../types'; import { UserModel } from './UserModel'; @Entity('Activities') @Index('sliding_leaderboard_index', ['timestamp', 'pointsEarned'], { where: '"pointsEarned" > 0' }) @Index('visible_activities_by_user_index', ['user', 'scope'], { where: 'scope = \'PUBLIC\' OR scope = \'PRIVATE\'' }) -export class ActivityModel extends BaseEntity { +export class ActivityModel { @PrimaryGeneratedColumn('uuid') uuid: Uuid; diff --git a/models/AttendanceModel.ts b/models/AttendanceModel.ts index f152da94..43258be2 100644 --- a/models/AttendanceModel.ts +++ b/models/AttendanceModel.ts @@ -1,10 +1,10 @@ -import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, Index, ManyToOne, JoinColumn } from 'typeorm'; +import { Entity, Column, PrimaryGeneratedColumn, Index, ManyToOne, JoinColumn } from 'typeorm'; import { PublicAttendance, Uuid } from '../types'; import { UserModel } from './UserModel'; import { EventModel } from './EventModel'; @Entity('Attendances') -export class AttendanceModel extends BaseEntity { +export class AttendanceModel { @PrimaryGeneratedColumn('uuid') uuid: Uuid; diff --git a/models/EventModel.ts b/models/EventModel.ts index ac58c94d..2de95d58 100644 --- a/models/EventModel.ts +++ b/models/EventModel.ts @@ -1,5 +1,5 @@ import * as moment from 'moment'; -import { BaseEntity, Column, Entity, Index, PrimaryGeneratedColumn, OneToMany } from 'typeorm'; +import { Column, Entity, Index, PrimaryGeneratedColumn, OneToMany } from 'typeorm'; import { PublicEvent, Uuid } from '../types'; import { AttendanceModel } from './AttendanceModel'; import { FeedbackModel } from './FeedbackModel'; @@ -7,7 +7,7 @@ import { ExpressCheckinModel } from './ExpressCheckinModel'; @Entity('Events') @Index('event_start_end_index', ['start', 'end']) -export class EventModel extends BaseEntity { +export class EventModel { @PrimaryGeneratedColumn('uuid') uuid: Uuid; diff --git a/models/ExpressCheckinModel.ts b/models/ExpressCheckinModel.ts index d9e39d84..2169174d 100644 --- a/models/ExpressCheckinModel.ts +++ b/models/ExpressCheckinModel.ts @@ -1,9 +1,9 @@ -import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; +import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { PublicExpressCheckin, Uuid } from '../types'; import { EventModel } from './EventModel'; @Entity('ExpressCheckins') -export class ExpressCheckinModel extends BaseEntity { +export class ExpressCheckinModel { @PrimaryGeneratedColumn('uuid') uuid: Uuid; diff --git a/models/FeedbackModel.ts b/models/FeedbackModel.ts index 2bc2348d..1ee1b547 100644 --- a/models/FeedbackModel.ts +++ b/models/FeedbackModel.ts @@ -1,10 +1,10 @@ -import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; +import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { FeedbackStatus, FeedbackType, PublicFeedback, Uuid } from '../types'; import { UserModel } from './UserModel'; import { EventModel } from './EventModel'; @Entity('Feedback') -export class FeedbackModel extends BaseEntity { +export class FeedbackModel { @PrimaryGeneratedColumn('uuid') uuid: Uuid; diff --git a/models/MerchCollectionPhotoModel.ts b/models/MerchCollectionPhotoModel.ts index e3e3bdbe..4c4c88b1 100644 --- a/models/MerchCollectionPhotoModel.ts +++ b/models/MerchCollectionPhotoModel.ts @@ -1,9 +1,9 @@ -import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; +import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { PublicMerchCollectionPhoto, Uuid } from '../types'; import { MerchandiseCollectionModel } from './MerchandiseCollectionModel'; @Entity('MerchCollectionPhotos') -export class MerchCollectionPhotoModel extends BaseEntity { +export class MerchCollectionPhotoModel { @PrimaryGeneratedColumn('uuid') uuid: Uuid; diff --git a/models/MerchandiseCollectionModel.ts b/models/MerchandiseCollectionModel.ts index 6c7d5da2..174ae2c0 100644 --- a/models/MerchandiseCollectionModel.ts +++ b/models/MerchandiseCollectionModel.ts @@ -1,10 +1,10 @@ -import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, OneToMany, CreateDateColumn } from 'typeorm'; +import { Entity, Column, PrimaryGeneratedColumn, OneToMany, CreateDateColumn } from 'typeorm'; import { Uuid, PublicMerchCollection } from '../types'; import { MerchandiseItemModel } from './MerchandiseItemModel'; import { MerchCollectionPhotoModel } from './MerchCollectionPhotoModel'; @Entity('MerchandiseCollections') -export class MerchandiseCollectionModel extends BaseEntity { +export class MerchandiseCollectionModel { @PrimaryGeneratedColumn('uuid') uuid: Uuid; diff --git a/models/MerchandiseItemModel.ts b/models/MerchandiseItemModel.ts index e27971d3..a5b029b8 100644 --- a/models/MerchandiseItemModel.ts +++ b/models/MerchandiseItemModel.ts @@ -1,5 +1,5 @@ import { - Entity, BaseEntity, Column, PrimaryGeneratedColumn, Index, ManyToOne, JoinColumn, OneToMany, + Entity, Column, PrimaryGeneratedColumn, Index, ManyToOne, JoinColumn, OneToMany, } from 'typeorm'; import { Uuid, PublicMerchItem, PublicCartMerchItem } from '../types'; import { MerchandiseCollectionModel } from './MerchandiseCollectionModel'; @@ -7,7 +7,7 @@ import { MerchandiseItemOptionModel } from './MerchandiseItemOptionModel'; import { MerchandiseItemPhotoModel } from './MerchandiseItemPhotoModel'; @Entity('MerchandiseItems') -export class MerchandiseItemModel extends BaseEntity { +export class MerchandiseItemModel { @PrimaryGeneratedColumn('uuid') uuid: Uuid; diff --git a/models/MerchandiseItemOptionModel.ts b/models/MerchandiseItemOptionModel.ts index 4da70499..3dca1ca3 100644 --- a/models/MerchandiseItemOptionModel.ts +++ b/models/MerchandiseItemOptionModel.ts @@ -1,12 +1,12 @@ import { - Entity, BaseEntity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn, OneToMany, Index, + Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn, OneToMany, Index, } from 'typeorm'; import { Uuid, PublicMerchItemOption, MerchItemOptionMetadata, PublicOrderMerchItemOption } from '../types'; import { OrderItemModel } from './OrderItemModel'; import { MerchandiseItemModel } from './MerchandiseItemModel'; @Entity('MerchandiseItemOptions') -export class MerchandiseItemOptionModel extends BaseEntity { +export class MerchandiseItemOptionModel { @PrimaryGeneratedColumn('uuid') uuid: Uuid; diff --git a/models/MerchandiseItemPhotoModel.ts b/models/MerchandiseItemPhotoModel.ts index e20334e3..068d963d 100644 --- a/models/MerchandiseItemPhotoModel.ts +++ b/models/MerchandiseItemPhotoModel.ts @@ -1,9 +1,9 @@ -import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; +import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { PublicMerchItemPhoto, Uuid } from '../types'; import { MerchandiseItemModel } from './MerchandiseItemModel'; @Entity('MerchandiseItemPhotos') -export class MerchandiseItemPhotoModel extends BaseEntity { +export class MerchandiseItemPhotoModel { @PrimaryGeneratedColumn('uuid') uuid: Uuid; diff --git a/models/OrderItemModel.ts b/models/OrderItemModel.ts index 55446038..3c16378d 100644 --- a/models/OrderItemModel.ts +++ b/models/OrderItemModel.ts @@ -1,10 +1,10 @@ -import { Entity, BaseEntity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn } from 'typeorm'; +import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn } from 'typeorm'; import { Uuid, PublicOrderItem } from '../types'; import { OrderModel } from './OrderModel'; import { MerchandiseItemOptionModel } from './MerchandiseItemOptionModel'; @Entity('OrderItems') -export class OrderItemModel extends BaseEntity { +export class OrderItemModel { @PrimaryGeneratedColumn('uuid') uuid: Uuid; diff --git a/models/OrderModel.ts b/models/OrderModel.ts index 08c4dcd3..9c1ee796 100644 --- a/models/OrderModel.ts +++ b/models/OrderModel.ts @@ -1,6 +1,5 @@ import { Entity, - BaseEntity, Column, PrimaryGeneratedColumn, Index, @@ -14,7 +13,7 @@ import { OrderItemModel } from './OrderItemModel'; import { OrderPickupEventModel } from './OrderPickupEventModel'; @Entity('Orders') -export class OrderModel extends BaseEntity { +export class OrderModel { @PrimaryGeneratedColumn('uuid') uuid: Uuid; diff --git a/models/OrderPickupEventModel.ts b/models/OrderPickupEventModel.ts index 928fe1da..7af4b132 100644 --- a/models/OrderPickupEventModel.ts +++ b/models/OrderPickupEventModel.ts @@ -4,7 +4,7 @@ import { OrderModel } from './OrderModel'; import { EventModel } from './EventModel'; @Entity('OrderPickupEvents') -export class OrderPickupEventModel extends BaseEntity { +export class OrderPickupEventModel { @PrimaryGeneratedColumn('uuid') uuid: Uuid; diff --git a/models/ResumeModel.ts b/models/ResumeModel.ts index a792584e..76464c7e 100644 --- a/models/ResumeModel.ts +++ b/models/ResumeModel.ts @@ -1,9 +1,9 @@ -import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; +import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { PublicResume, Uuid } from '../types'; import { UserModel } from './UserModel'; @Entity('Resumes') -export class ResumeModel extends BaseEntity { +export class ResumeModel { @PrimaryGeneratedColumn('uuid') uuid: Uuid; diff --git a/models/UserModel.ts b/models/UserModel.ts index 0b594c2a..aa6f2eb5 100644 --- a/models/UserModel.ts +++ b/models/UserModel.ts @@ -1,4 +1,4 @@ -import { BaseEntity, Column, Entity, Index, PrimaryGeneratedColumn, OneToMany } from 'typeorm'; +import { Column, Entity, Index, PrimaryGeneratedColumn, OneToMany } from 'typeorm'; import * as bcrypt from 'bcrypt'; import { PrivateProfile, PublicProfile, Uuid, UserAccessType, UserState } from '../types'; import { ActivityModel } from './ActivityModel'; @@ -9,7 +9,7 @@ import { ResumeModel } from './ResumeModel'; import { UserSocialMediaModel } from './UserSocialMediaModel'; @Entity('Users') -export class UserModel extends BaseEntity { +export class UserModel { @PrimaryGeneratedColumn('uuid') uuid: Uuid; diff --git a/models/UserSocialMediaModel.ts b/models/UserSocialMediaModel.ts index ffa4b539..91d670fe 100644 --- a/models/UserSocialMediaModel.ts +++ b/models/UserSocialMediaModel.ts @@ -1,9 +1,9 @@ -import { BaseEntity, Column, Entity, PrimaryGeneratedColumn, JoinColumn, ManyToOne } from 'typeorm'; +import { Column, Entity, PrimaryGeneratedColumn, JoinColumn, ManyToOne } from 'typeorm'; import { UserModel } from './UserModel'; import { Uuid, SocialMediaType, PublicUserSocialMedia } from '../types'; @Entity('UserSocialMedia') -export class UserSocialMediaModel extends BaseEntity { +export class UserSocialMediaModel { @PrimaryGeneratedColumn('uuid') uuid: Uuid; diff --git a/repositories/ActivityRepository.ts b/repositories/ActivityRepository.ts index f753e320..478bcbac 100644 --- a/repositories/ActivityRepository.ts +++ b/repositories/ActivityRepository.ts @@ -11,13 +11,13 @@ export const ActivityRepository = Container.get(DataSource) .extend({ async logActivity(activity: Activity): Promise { activity.scope = ActivityTypeToScope[activity.type]; - return this.repository.save(ActivityModel.create(activity as ActivityModel)); + return this.repository.save(this.repository.create(activity)); }, async logActivityBatch(activities: Activity[]): Promise { const activityModels = activities.map((activity) => { activity.scope = ActivityTypeToScope[activity.type]; - return ActivityModel.create(activity as ActivityModel); + return this.repository.create(activity); }); return this.repository.save(activityModels); }, diff --git a/repositories/AttendanceRepository.ts b/repositories/AttendanceRepository.ts index 0d473bf4..0a248788 100644 --- a/repositories/AttendanceRepository.ts +++ b/repositories/AttendanceRepository.ts @@ -1,4 +1,4 @@ -import { BaseEntity, DataSource, DeepPartial } from 'typeorm'; +import { DataSource, DeepPartial } from 'typeorm'; import Container from 'typedi'; import { ExpressCheckinModel } from '../models/ExpressCheckinModel'; import { Uuid } from '../types'; @@ -33,11 +33,11 @@ export const AttendanceRepository = Container.get(DataSource) }, async writeAttendance(attendance: Attendance): Promise { - return this.repository.save(AttendanceModel.create(attendance as DeepPartial)); + return this.repository.save(this.repository.create(attendance)); }, async writeAttendanceBatch(attendances: Attendance[]) { - const attendanceModels = attendances.map((attendance) => AttendanceModel.create(attendance as DeepPartial)); + const attendanceModels = attendances.map((attendance) => this.repository.create(attendance)); return this.repository.save(attendanceModels); }, @@ -59,6 +59,6 @@ export const ExpressCheckinRepository = Container.get(DataSource) }, async createExpressCheckin(email: string, event: EventModel): Promise { - return this.repository.save(ExpressCheckinModel.create({ email, event })); + return this.repository.save(this.repository.create({ email, event })); }, }); diff --git a/repositories/EventRepository.ts b/repositories/EventRepository.ts index cf3a3c71..c17b939b 100644 --- a/repositories/EventRepository.ts +++ b/repositories/EventRepository.ts @@ -7,7 +7,7 @@ export const EventRepository = Container.get(DataSource) .getRepository(EventModel) .extend({ async upsertEvent(event: EventModel, changes?: Partial): Promise { - if (changes) event = EventModel.merge(event, changes) as EventModel; + if (changes) event = this.repository.merge(event, changes); return this.repository.save(event); }, diff --git a/repositories/FeedbackRepository.ts b/repositories/FeedbackRepository.ts index 5849590d..75a4a9e8 100644 --- a/repositories/FeedbackRepository.ts +++ b/repositories/FeedbackRepository.ts @@ -29,19 +29,19 @@ export const FeedbackRepository = Container.get(DataSource) async upsertFeedback(feedback: FeedbackModel, changes?: Partial): Promise { - if (changes) feedback = FeedbackModel.merge(feedback, changes) as FeedbackModel; - return this.repository.save(feedback); + if (changes) feedback = FeedbackRepository.merge(feedback, changes); + return this.save(feedback); }, async hasUserSubmittedFeedback(user: UserModel, event: EventModel): Promise { - const count = await this.repository.count({ + const count = await this.count({ where: { user, event }, }); return count > 0; }, getBaseFindQuery(options: FeedbackSearchOptions): SelectQueryBuilder { - let query = this.repository.createQueryBuilder('feedback') + let query = this.createQueryBuilder('feedback') .leftJoinAndSelect('feedback.user', 'user') .leftJoinAndSelect('feedback.event', 'event') .orderBy('timestamp', 'DESC'); diff --git a/repositories/MerchOrderRepository.ts b/repositories/MerchOrderRepository.ts index 7e00ca64..74047e0d 100644 --- a/repositories/MerchOrderRepository.ts +++ b/repositories/MerchOrderRepository.ts @@ -82,7 +82,7 @@ export const MerchOrderRepository = Container.get(DataSource) }, async upsertMerchOrder(order: OrderModel, changes?: Partial): Promise { - if (changes) order = OrderModel.merge(order, changes) as OrderModel; + if (changes) order = this.repository.merge(order, changes); return this.repository.save(order); }, }); @@ -176,7 +176,7 @@ export const OrderPickupEventRepository = Container.get(DataSource) */ async upsertPickupEvent(pickupEvent: OrderPickupEventModel, changes?: Partial): Promise { - if (changes) pickupEvent = OrderPickupEventModel.merge(pickupEvent, changes) as OrderPickupEventModel; + if (changes) pickupEvent = this.repository.merge(pickupEvent, changes); return this.repository.save(pickupEvent); }, diff --git a/repositories/MerchStoreRepository.ts b/repositories/MerchStoreRepository.ts index 206adcb5..dca33bdc 100644 --- a/repositories/MerchStoreRepository.ts +++ b/repositories/MerchStoreRepository.ts @@ -32,7 +32,7 @@ export const MerchCollectionRepository = Container.get(DataSource) async upsertMerchCollection(collection: MerchandiseCollectionModel, changes?: Partial): Promise { - if (changes) collection = MerchandiseCollectionModel.merge(collection, changes) as MerchandiseCollectionModel; + if (changes) collection = this.repository.merge(collection, changes) as MerchandiseCollectionModel; return this.repository.save(collection); }, @@ -63,7 +63,7 @@ export const MerchCollectionPhotoRepository = Container.get(DataSource) async upsertCollectionPhoto(photo: MerchCollectionPhotoModel, changes?: Partial): Promise { - if (changes) photo = MerchCollectionPhotoModel.merge(photo, changes) as MerchCollectionPhotoModel; + if (changes) photo = this.repository.merge(photo, changes) as MerchCollectionPhotoModel; return this.repository.save(photo); }, @@ -80,7 +80,7 @@ export const MerchItemRepository = Container.get(DataSource) }, async upsertMerchItem(item: MerchandiseItemModel, changes?: Partial): Promise { - if (changes) item = MerchandiseItemModel.merge(item, changes) as MerchandiseItemModel; + if (changes) item = this.repository.merge(item, changes) as MerchandiseItemModel; return this.repository.save(item); }, @@ -114,7 +114,7 @@ export const MerchItemOptionRepository = Container.get(DataSource) async upsertMerchItemOption(option: MerchandiseItemOptionModel, changes?: Partial): Promise { - if (changes) option = MerchandiseItemOptionModel.merge(option, changes) as MerchandiseItemOptionModel; + if (changes) option = this.repository.merge(option, changes) as MerchandiseItemOptionModel; return this.repository.save(option); }, @@ -151,7 +151,7 @@ export const MerchItemPhotoRepository = Container.get(DataSource) async upsertMerchItemPhoto(merchPhoto: MerchandiseItemPhotoModel, changes?: Partial): Promise { - if (changes) merchPhoto = MerchandiseItemPhotoModel.merge(merchPhoto, changes) as MerchandiseItemPhotoModel; + if (changes) merchPhoto = this.repository.merge(merchPhoto, changes) as MerchandiseItemPhotoModel; return this.repository.save(merchPhoto); }, diff --git a/repositories/ResumeRepository.ts b/repositories/ResumeRepository.ts index f54107a8..7531e20e 100644 --- a/repositories/ResumeRepository.ts +++ b/repositories/ResumeRepository.ts @@ -40,7 +40,7 @@ export const ResumeRepository = Container.get(DataSource) }, async upsertResume(resume: ResumeModel, changes?: Partial): Promise { - if (changes) resume = ResumeModel.merge(resume, changes) as ResumeModel; + if (changes) resume = this.repository.merge(resume, changes) as ResumeModel; return this.repository.save(resume); }, }); diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index 9cdd5a9c..af7e3c89 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -11,7 +11,7 @@ export const UserRepository = Container.get(DataSource) .getRepository(UserModel) .extend({ async upsertUser(user: UserModel, changes?: Partial): Promise { - if (changes) user = UserModel.merge(user, changes) as UserModel; + if (changes) user = this.repository.merge(user, changes) as UserModel; return this.repository.save(user); }, diff --git a/repositories/UserSocialMediaRepository.ts b/repositories/UserSocialMediaRepository.ts index 68df9df8..f10b82e0 100644 --- a/repositories/UserSocialMediaRepository.ts +++ b/repositories/UserSocialMediaRepository.ts @@ -19,7 +19,7 @@ export const UserSocialMediaRepository = Container.get(DataSource) async upsertSocialMedia(userSocialMedia: UserSocialMediaModel, changes?: Partial): Promise { - if (changes) userSocialMedia = UserSocialMediaModel.merge(userSocialMedia, changes) as UserSocialMediaModel; + if (changes) userSocialMedia = this.repository.merge(userSocialMedia, changes) as UserSocialMediaModel; return this.repository.save(userSocialMedia); }, diff --git a/repositories/index.ts b/repositories/index.ts index 4174ea7c..55b84a39 100644 --- a/repositories/index.ts +++ b/repositories/index.ts @@ -34,6 +34,10 @@ export default class Repositories { return entityManager.withRepository(FeedbackRepository); } + public static expressCheckin(entityManager: EntityManager) { + return entityManager.withRepository(ExpressCheckinRepository); + } + public static leaderboard(entityManager: EntityManager) { return entityManager.withRepository(LeaderboardRepository); } diff --git a/services/AttendanceService.ts b/services/AttendanceService.ts index 166ef16f..f7a6c1b5 100644 --- a/services/AttendanceService.ts +++ b/services/AttendanceService.ts @@ -16,8 +16,8 @@ import { Activity, Attendance } from '../types/internal'; export default class AttendanceService { private transactions: TransactionsManager; - constructor(@InjectManager() entityManager: EntityManager) { - this.transactions = new TransactionsManager(entityManager); + constructor(transactions: TransactionsManager) { + this.transactions = transactions; } public async getAttendancesForEvent(event: Uuid): Promise { diff --git a/services/EventService.ts b/services/EventService.ts index 9994e080..f10c7da1 100644 --- a/services/EventService.ts +++ b/services/EventService.ts @@ -1,18 +1,18 @@ import { Service } from 'typedi'; -import { InjectManager } from 'typeorm-typedi-extensions'; import { ForbiddenError, NotFoundError } from 'routing-controllers'; -import { EntityManager } from 'typeorm'; +import { DeepPartial } from 'typeorm'; import { EventModel } from '../models/EventModel'; import { Uuid, PublicEvent, Event, EventSearchOptions } from '../types'; import Repositories, { TransactionsManager } from '../repositories'; import { UserError } from '../utils/Errors'; +import { EventRepository } from 'repositories/EventRepository'; @Service() export default class EventService { private transactions: TransactionsManager; - constructor(@InjectManager() entityManager: EntityManager) { - this.transactions = new TransactionsManager(entityManager); + constructor(transactions: TransactionsManager) { + this.transactions = transactions; } /** @@ -27,7 +27,7 @@ export default class EventService { const isUnusedAttendanceCode = await eventRepository.isUnusedAttendanceCode(event.attendanceCode); if (!isUnusedAttendanceCode) throw new UserError('Attendance code has already been used'); if (event.start > event.end) throw new UserError('Start date after end date'); - return eventRepository.upsertEvent(EventModel.create(event)); + return eventRepository.upsertEvent(EventRepository.create(event as DeepPartial)[0]); }); return eventCreated.getPublicEvent(); } diff --git a/services/FeedbackService.ts b/services/FeedbackService.ts index 43ad5a22..869b566d 100644 --- a/services/FeedbackService.ts +++ b/services/FeedbackService.ts @@ -1,12 +1,10 @@ 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 { PublicFeedback, Feedback, Uuid, ActivityType, FeedbackStatus, FeedbackSearchOptions } from '../types'; import { UserError } from '../utils/Errors'; +import { FeedbackRepository } from 'repositories/FeedbackRepository'; @Service() export default class FeedbackService { @@ -44,7 +42,7 @@ export default class FeedbackService { user, type: ActivityType.SUBMIT_FEEDBACK, }); - const addedFeedback = await feedbackRepository.upsertFeedback(FeedbackModel.create({ ...feedback, user, event })); + const addedFeedback = await feedbackRepository.upsertFeedback(FeedbackRepository.create({ ...feedback, user, event })); return addedFeedback.getPublicFeedback(); }); } diff --git a/services/MerchOrderService.ts b/services/MerchOrderService.ts index 363f6d7d..76f698b5 100644 --- a/services/MerchOrderService.ts +++ b/services/MerchOrderService.ts @@ -26,6 +26,8 @@ import { MerchandiseItemOptionModel } from '../models/MerchandiseItemOptionModel import EmailService, { OrderInfo, OrderPickupEventInfo } from './EmailService'; import Repositories, { TransactionsManager } from '../repositories'; +import { MerchOrderRepository, OrderItemRepository } from 'repositories/MerchOrderRepository'; +import { UserRepository } from 'repositories/UserRepository'; @Service() export default class MerchOrderService { @@ -103,13 +105,13 @@ export default class MerchOrderService { const merchOrderRepository = Repositories.merchOrder(txn); // if all checks pass, the order is placed - const createdOrder = await merchOrderRepository.upsertMerchOrder(OrderModel.create({ + const createdOrder = await merchOrderRepository.upsertMerchOrder(MerchOrderRepository.create({ user, totalCost, items: flatten(originalOrder.map((optionAndQuantity) => { const option = itemOptions.get(optionAndQuantity.option); const quantityRequested = optionAndQuantity.quantity; - return Array(quantityRequested).fill(OrderItemModel.create({ + return Array(quantityRequested).fill(OrderItemRepository.create({ option, salePriceAtPurchase: option.getPrice(), discountPercentageAtPurchase: option.discountPercentage, @@ -386,7 +388,7 @@ export default class MerchOrderService { txn: EntityManager): Promise { const orderRepository = Repositories.merchOrder(txn); const upsertedOrder = await orderRepository.upsertMerchOrder(order, { status: OrderStatus.CANCELLED }); - const orderWithOnlyUnfulfilledItems = OrderModel.merge(upsertedOrder, { items: refundedItems }); + const orderWithOnlyUnfulfilledItems = orderRepository.merge(upsertedOrder, { items: refundedItems }); return MerchOrderService.buildOrderUpdateInfo(orderWithOnlyUnfulfilledItems, upsertedOrder.pickupEvent, txn); } @@ -469,14 +471,14 @@ export default class MerchOrderService { // so convert order into fulfilled and unfulfilled item sets const fulfilledItems = order.items.filter((item) => item.fulfilled); const fulfilledItemsCost = fulfilledItems.reduce((cost, curr) => cost + curr.salePriceAtPurchase, 0); - const orderWithFulfilledItems = OrderModel.create({ + const orderWithFulfilledItems = orderRepository.create({ ...order, items: fulfilledItems, totalCost: fulfilledItemsCost, }); const unfulfilledItems = order.items.filter((item) => !item.fulfilled); const unfulfilledItemsCost = unfulfilledItems.reduce((cost, curr) => cost + curr.salePriceAtPurchase, 0); - const orderWithUnfulfilledItems = OrderModel.create({ + const orderWithUnfulfilledItems = orderRepository.create({ ...order, items: unfulfilledItems, totalCost: unfulfilledItemsCost, @@ -747,7 +749,7 @@ export default class MerchOrderService { throw new UserError('Order pickup event start time must come before the end time'); } - const pickupEventModel = OrderPickupEventModel.create(pickupEvent); + const pickupEventModel = orderPickupEventRepository.create(pickupEvent); if (pickupEvent.linkedEventUuid) { const linkedRegularEvent = await this.getLinkedRegularEvent(pickupEvent.linkedEventUuid); @@ -766,7 +768,7 @@ export default class MerchOrderService { return this.transactions.readWrite(async (txn) => { const orderPickupEventRepository = Repositories.merchOrderPickupEvent(txn); const pickupEvent = await orderPickupEventRepository.findByUuid(uuid); - const updatedPickupEvent = OrderPickupEventModel.merge(pickupEvent, changes); + const updatedPickupEvent = orderPickupEventRepository.merge(pickupEvent, changes); if (changes.linkedEventUuid) { const linkedRegularEvent = await this.getLinkedRegularEvent(changes.linkedEventUuid); @@ -821,7 +823,7 @@ export default class MerchOrderService { const { user } = order; await this.emailService.sendOrderPickupCancelled(user.email, user.firstName, orderUpdateInfo); await orderRepository.upsertMerchOrder(order, { status: OrderStatus.PICKUP_CANCELLED, pickupEvent: null }); - return OrderModel.merge(order, { pickupEvent: null }); + return orderRepository.merge(order, { pickupEvent: null }); })); await orderPickupEventRepository.upsertPickupEvent(pickupEvent, { status: OrderPickupEventStatus.CANCELLED }); }); diff --git a/services/MerchStoreService.ts b/services/MerchStoreService.ts index d003d8ff..a159620c 100644 --- a/services/MerchStoreService.ts +++ b/services/MerchStoreService.ts @@ -93,9 +93,12 @@ export default class MerchStoreService { } public async createCollection(collection: MerchCollection): Promise { - return this.transactions.readWrite(async (txn) => Repositories - .merchStoreCollection(txn) - .upsertMerchCollection(MerchandiseCollectionModel.create(collection))); + return this.transactions.readWrite(async (txn) => { + const merchStoreCollectionRepository = Repositories.merchStoreCollection(txn); + return merchStoreCollectionRepository.upsertMerchCollection( + merchStoreCollectionRepository.create(collection) + ); + }); } public async editCollection(uuid: Uuid, collectionEdit: MerchCollectionEdit): Promise { @@ -133,7 +136,7 @@ export default class MerchStoreService { currentCollection.collectionPhotos.map((currentPhoto) => { if (!photoUpdatesByUuid.has(currentPhoto.uuid)) return; const photoUpdate = photoUpdatesByUuid.get(currentPhoto.uuid); - return MerchCollectionPhotoModel.merge(currentPhoto, photoUpdate); + return Repositories.merchStoreCollectionPhoto(txn).merge(currentPhoto, photoUpdate); }); } @@ -179,11 +182,12 @@ export default class MerchStoreService { public async createCollectionPhoto(collection: Uuid, properties: MerchCollectionPhoto): Promise { return this.transactions.readWrite(async (txn) => { - const merchCollection = await Repositories.merchStoreCollection(txn).findByUuid(collection); + const merchCollectionRepository = Repositories.merchStoreCollection(txn); + const merchCollection = await merchCollectionRepository.findByUuid(collection); if (!merchCollection) throw new NotFoundError('Collection not found'); - const createdPhoto = MerchCollectionPhotoModel.create({ ...properties, merchCollection }); const merchStoreCollectionPhotoRepository = Repositories.merchStoreCollectionPhoto(txn); + const createdPhoto = merchStoreCollectionPhotoRepository.create({ ...properties, merchCollection }); // verify the result photos array merchCollection.collectionPhotos.push(createdPhoto); @@ -203,8 +207,7 @@ export default class MerchStoreService { */ public async getCollectionPhotoForDeletion(uuid: Uuid): Promise { return this.transactions.readWrite(async (txn) => { - const merchCollectionPhotoRepository = Repositories.merchStoreCollectionPhoto(txn); - const collectionPhoto = await merchCollectionPhotoRepository.findByUuid(uuid); + const collectionPhoto = await Repositories.merchStoreCollectionPhoto(txn).findByUuid(uuid); if (!collectionPhoto) throw new NotFoundError('Merch collection photo not found'); const collection = await Repositories.merchStoreCollection(txn).findByUuid(collectionPhoto.merchCollection.uuid); @@ -238,7 +241,7 @@ export default class MerchStoreService { if (!collection) throw new NotFoundError('Merch collection not found'); const merchItemRepository = Repositories.merchStoreItem(txn); - const merchItem = MerchandiseItemModel.create({ ...item, collection }); + const merchItem = Repositories.merchStoreItem(txn).create({ ...item, collection }); await merchItemRepository.upsertMerchItem(merchItem); return merchItemRepository.findByUuid(merchItem.uuid); }); @@ -299,7 +302,7 @@ export default class MerchStoreService { throw new UserError(`Cannot decrement option quantity below 0 for option: ${currentOption.uuid}`); } } - return MerchandiseItemOptionModel.merge(currentOption, optionUpdate); + return Repositories.merchStoreItemOption(txn).merge(currentOption, optionUpdate); }); } @@ -319,11 +322,11 @@ export default class MerchStoreService { item.merchPhotos.map((currentPhoto) => { if (!photoUpdatesByUuid.has(currentPhoto.uuid)) return; const photoUpdate = photoUpdatesByUuid.get(currentPhoto.uuid); - return MerchandiseItemPhotoModel.merge(currentPhoto, photoUpdate); + return Repositories.merchStoreItemPhoto(txn).merge(currentPhoto, photoUpdate); }); } - const updatedItem = MerchandiseItemModel.merge(item, changes); + const updatedItem = merchItemRepository.merge(item, changes); MerchStoreService.verifyItemHasValidOptions(updatedItem); if (updatedCollection) { @@ -364,7 +367,7 @@ export default class MerchStoreService { if (!merchItem) throw new NotFoundError('Merch item not found'); const merchItemOptionRepository = Repositories.merchStoreItemOption(txn); - const createdOption = MerchandiseItemOptionModel.create({ ...option, item: merchItem }); + const createdOption = merchItemOptionRepository.create({ ...option, item: merchItem }); merchItem.options.push(createdOption); MerchStoreService.verifyItemHasValidOptions(merchItem); @@ -419,8 +422,8 @@ export default class MerchStoreService { const merchItem = await Repositories.merchStoreItem(txn).findByUuid(item); if (!merchItem) throw new NotFoundError('Merch item not found'); - const createdPhoto = MerchandiseItemPhotoModel.create({ ...properties, merchItem }); const merchStoreItemPhotoRepository = Repositories.merchStoreItemPhoto(txn); + const createdPhoto = merchStoreItemPhotoRepository.create({ ...properties, merchItem }); // verify the result photos array merchItem.merchPhotos.push(createdPhoto); diff --git a/services/ResumeService.ts b/services/ResumeService.ts index 756d5962..7f90c3f8 100644 --- a/services/ResumeService.ts +++ b/services/ResumeService.ts @@ -11,8 +11,8 @@ import Repositories, { TransactionsManager } from '../repositories'; export default class ResumeService { private transactions: TransactionsManager; - constructor(@InjectManager() entityManager: EntityManager) { - this.transactions = new TransactionsManager(entityManager); + constructor(transactions: TransactionsManager) { + this.transactions = transactions; } public async getVisibleResumes() : Promise { @@ -28,7 +28,7 @@ export default class ResumeService { const oldResume = await resumeRepository.findByUserUuid(user.uuid); if (oldResume) await resumeRepository.deleteResume(oldResume); - const resume = await resumeRepository.upsertResume(ResumeModel.create({ + const resume = await resumeRepository.upsertResume(resumeRepository.create({ user, isResumeVisible, url: resumeURL, diff --git a/services/UserAuthService.ts b/services/UserAuthService.ts index 01afb69d..3749f146 100644 --- a/services/UserAuthService.ts +++ b/services/UserAuthService.ts @@ -40,7 +40,7 @@ export default class UserAuthService { const userHandle = registration.handle ?? UserAccountService.generateDefaultHandle(registration.firstName, registration.lastName); - const user = await userRepository.upsertUser(UserModel.create({ + const user = await userRepository.upsertUser(userRepository.create({ ...registration, hash: await UserRepository.generateHash(registration.password), accessCode: UserAuthService.generateAccessCode(), diff --git a/services/UserSocialMediaService.ts b/services/UserSocialMediaService.ts index 2f59e5e7..3f300e69 100644 --- a/services/UserSocialMediaService.ts +++ b/services/UserSocialMediaService.ts @@ -12,8 +12,8 @@ import { Uuid, SocialMedia, SocialMediaPatches } from '../types'; export default class UserSocialMediaService { private transactions: TransactionsManager; - constructor(@InjectManager() entityManager: EntityManager) { - this.transactions = new TransactionsManager(entityManager); + constructor(transactions: TransactionsManager) { + this.transactions = transactions; } public async getSocialMediaForUser(user: UserModel): Promise { @@ -42,7 +42,7 @@ export default class UserSocialMediaService { if (!isNewSocialMediaType) { throw new UserError(`Social media URL of type "${socialMedia.type}" has already been created for this user`); } - return userSocialMediaRepository.upsertSocialMedia(UserSocialMediaModel.create({ ...socialMedia, user })); + return userSocialMediaRepository.upsertSocialMedia(userSocialMediaRepository.create({ ...socialMedia, user })); })); return upsertedSocialMedias; });