Skip to content

Commit

Permalink
remove base entity
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwn04 committed Dec 18, 2024
1 parent 0715226 commit a7eb386
Show file tree
Hide file tree
Showing 34 changed files with 98 additions and 92 deletions.
4 changes: 2 additions & 2 deletions models/ActivityModel.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions models/AttendanceModel.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions models/EventModel.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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';
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;

Expand Down
4 changes: 2 additions & 2 deletions models/ExpressCheckinModel.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions models/FeedbackModel.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions models/MerchCollectionPhotoModel.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions models/MerchandiseCollectionModel.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions models/MerchandiseItemModel.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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';
import { MerchandiseItemOptionModel } from './MerchandiseItemOptionModel';
import { MerchandiseItemPhotoModel } from './MerchandiseItemPhotoModel';

@Entity('MerchandiseItems')
export class MerchandiseItemModel extends BaseEntity {
export class MerchandiseItemModel {
@PrimaryGeneratedColumn('uuid')
uuid: Uuid;

Expand Down
4 changes: 2 additions & 2 deletions models/MerchandiseItemOptionModel.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions models/MerchandiseItemPhotoModel.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions models/OrderItemModel.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
3 changes: 1 addition & 2 deletions models/OrderModel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Entity,
BaseEntity,
Column,
PrimaryGeneratedColumn,
Index,
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion models/OrderPickupEventModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions models/ResumeModel.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions models/UserModel.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions models/UserSocialMediaModel.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions repositories/ActivityRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export const ActivityRepository = Container.get(DataSource)
.extend({
async logActivity(activity: Activity): Promise<ActivityModel> {
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<ActivityModel[]> {
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);
},
Expand Down
8 changes: 4 additions & 4 deletions repositories/AttendanceRepository.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -33,11 +33,11 @@ export const AttendanceRepository = Container.get(DataSource)
},

async writeAttendance(attendance: Attendance): Promise<AttendanceModel> {
return this.repository.save(AttendanceModel.create(attendance as DeepPartial<AttendanceModel>));
return this.repository.save(this.repository.create(attendance));
},

async writeAttendanceBatch(attendances: Attendance[]) {
const attendanceModels = attendances.map((attendance) => AttendanceModel.create(attendance as DeepPartial<AttendanceModel>));
const attendanceModels = attendances.map((attendance) => this.repository.create(attendance));
return this.repository.save(attendanceModels);
},

Expand All @@ -59,6 +59,6 @@ export const ExpressCheckinRepository = Container.get(DataSource)
},

async createExpressCheckin(email: string, event: EventModel): Promise<ExpressCheckinModel> {
return this.repository.save(ExpressCheckinModel.create({ email, event }));
return this.repository.save(this.repository.create({ email, event }));
},
});
2 changes: 1 addition & 1 deletion repositories/EventRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const EventRepository = Container.get(DataSource)
.getRepository(EventModel)
.extend({
async upsertEvent(event: EventModel, changes?: Partial<EventModel>): Promise<EventModel> {
if (changes) event = EventModel.merge(event, changes) as EventModel;
if (changes) event = this.repository.merge(event, changes);
return this.repository.save(event);
},

Expand Down
8 changes: 4 additions & 4 deletions repositories/FeedbackRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ export const FeedbackRepository = Container.get(DataSource)

async upsertFeedback(feedback: FeedbackModel,
changes?: Partial<FeedbackModel>): Promise<FeedbackModel> {
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<boolean> {
const count = await this.repository.count({
const count = await this.count({
where: { user, event },
});
return count > 0;
},

getBaseFindQuery(options: FeedbackSearchOptions): SelectQueryBuilder<FeedbackModel> {
let query = this.repository.createQueryBuilder('feedback')
let query = this.createQueryBuilder('feedback')
.leftJoinAndSelect('feedback.user', 'user')
.leftJoinAndSelect('feedback.event', 'event')
.orderBy('timestamp', 'DESC');
Expand Down
4 changes: 2 additions & 2 deletions repositories/MerchOrderRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const MerchOrderRepository = Container.get(DataSource)
},

async upsertMerchOrder(order: OrderModel, changes?: Partial<OrderModel>): Promise<OrderModel> {
if (changes) order = OrderModel.merge(order, changes) as OrderModel;
if (changes) order = this.repository.merge(order, changes);
return this.repository.save(order);
},
});
Expand Down Expand Up @@ -176,7 +176,7 @@ export const OrderPickupEventRepository = Container.get(DataSource)
*/
async upsertPickupEvent(pickupEvent: OrderPickupEventModel, changes?: Partial<OrderPickupEventModel>):
Promise<OrderPickupEventModel> {
if (changes) pickupEvent = OrderPickupEventModel.merge(pickupEvent, changes) as OrderPickupEventModel;
if (changes) pickupEvent = this.repository.merge(pickupEvent, changes);
return this.repository.save(pickupEvent);
},

Expand Down
10 changes: 5 additions & 5 deletions repositories/MerchStoreRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const MerchCollectionRepository = Container.get(DataSource)

async upsertMerchCollection(collection: MerchandiseCollectionModel,
changes?: Partial<MerchandiseCollectionModel>): Promise<MerchandiseCollectionModel> {
if (changes) collection = MerchandiseCollectionModel.merge(collection, changes) as MerchandiseCollectionModel;
if (changes) collection = this.repository.merge(collection, changes) as MerchandiseCollectionModel;
return this.repository.save(collection);
},

Expand Down Expand Up @@ -63,7 +63,7 @@ export const MerchCollectionPhotoRepository = Container.get(DataSource)

async upsertCollectionPhoto(photo: MerchCollectionPhotoModel,
changes?: Partial<MerchCollectionPhotoModel>): Promise<MerchCollectionPhotoModel> {
if (changes) photo = MerchCollectionPhotoModel.merge(photo, changes) as MerchCollectionPhotoModel;
if (changes) photo = this.repository.merge(photo, changes) as MerchCollectionPhotoModel;
return this.repository.save(photo);
},

Expand All @@ -80,7 +80,7 @@ export const MerchItemRepository = Container.get(DataSource)
},

async upsertMerchItem(item: MerchandiseItemModel, changes?: Partial<MerchandiseItemModel>): Promise<MerchandiseItemModel> {
if (changes) item = MerchandiseItemModel.merge(item, changes) as MerchandiseItemModel;
if (changes) item = this.repository.merge(item, changes) as MerchandiseItemModel;
return this.repository.save(item);
},

Expand Down Expand Up @@ -114,7 +114,7 @@ export const MerchItemOptionRepository = Container.get(DataSource)

async upsertMerchItemOption(option: MerchandiseItemOptionModel,
changes?: Partial<MerchandiseItemOptionModel>): Promise<MerchandiseItemOptionModel> {
if (changes) option = MerchandiseItemOptionModel.merge(option, changes) as MerchandiseItemOptionModel;
if (changes) option = this.repository.merge(option, changes) as MerchandiseItemOptionModel;
return this.repository.save(option);
},

Expand Down Expand Up @@ -151,7 +151,7 @@ export const MerchItemPhotoRepository = Container.get(DataSource)

async upsertMerchItemPhoto(merchPhoto: MerchandiseItemPhotoModel,
changes?: Partial<MerchandiseItemPhotoModel>): Promise<MerchandiseItemPhotoModel> {
if (changes) merchPhoto = MerchandiseItemPhotoModel.merge(merchPhoto, changes) as MerchandiseItemPhotoModel;
if (changes) merchPhoto = this.repository.merge(merchPhoto, changes) as MerchandiseItemPhotoModel;
return this.repository.save(merchPhoto);
},

Expand Down
2 changes: 1 addition & 1 deletion repositories/ResumeRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const ResumeRepository = Container.get(DataSource)
},

async upsertResume(resume: ResumeModel, changes?: Partial<ResumeModel>): Promise<ResumeModel> {
if (changes) resume = ResumeModel.merge(resume, changes) as ResumeModel;
if (changes) resume = this.repository.merge(resume, changes) as ResumeModel;
return this.repository.save(resume);
},
});
2 changes: 1 addition & 1 deletion repositories/UserRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const UserRepository = Container.get(DataSource)
.getRepository(UserModel)
.extend({
async upsertUser(user: UserModel, changes?: Partial<UserModel>): Promise<UserModel> {
if (changes) user = UserModel.merge(user, changes) as UserModel;
if (changes) user = this.repository.merge(user, changes) as UserModel;
return this.repository.save(user);
},

Expand Down
2 changes: 1 addition & 1 deletion repositories/UserSocialMediaRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const UserSocialMediaRepository = Container.get(DataSource)

async upsertSocialMedia(userSocialMedia: UserSocialMediaModel,
changes?: Partial<UserSocialMediaModel>): Promise<UserSocialMediaModel> {
if (changes) userSocialMedia = UserSocialMediaModel.merge(userSocialMedia, changes) as UserSocialMediaModel;
if (changes) userSocialMedia = this.repository.merge(userSocialMedia, changes) as UserSocialMediaModel;
return this.repository.save(userSocialMedia);
},

Expand Down
4 changes: 4 additions & 0 deletions repositories/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit a7eb386

Please sign in to comment.