Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinmarshall committed Apr 19, 2021
1 parent e390ccd commit 25a53cd
Show file tree
Hide file tree
Showing 33 changed files with 523 additions and 180 deletions.
29 changes: 7 additions & 22 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,27 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthModule } from './auth/auth.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { TypeOrmConfigService } from './libs';
import { NoticeModule } from './module/notice/notice.module';
import { NoticeMessageModule } from './module/notice-message/notice-message.module';
import { FeesModule } from './module/fees/fees.module';
import { StudentModule } from './module/student/student.module';
import { AttendanceModule } from './module/attendance/attendance.module';
import { StaffModule } from './module/staff/staff.module';
import { NotificationModule } from './module/notification/notification.module';
import { config, TypeOrmConfigService } from './libs';
import { ConfigModule } from '@nestjs/config';
import { config } from './libs/config/config';
import { ForumModule } from './module/forum/forum.module';
import { StudentModule } from './module/student/student.module';
import { getConnectionOptions } from 'typeorm';


@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
load: [config]
load: [config],
}),
AuthModule,
TypeOrmModule.forRootAsync({
useClass: TypeOrmConfigService
}),

StaffModule,
NoticeModule,
NoticeMessageModule,
FeesModule,
StudentModule,
AttendanceModule,
NotificationModule,
ForumModule

],
controllers: [AppController],
providers: [AppService],
})
export class AppModule { }
export class AppModule {
}
17 changes: 17 additions & 0 deletions src/entities/abstract-entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
BaseEntity,
PrimaryGeneratedColumn,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';

export abstract class AbstractEntity extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;

@CreateDateColumn({ name: 'created_at' })
createdAt: Date;

@UpdateDateColumn({ name: 'updated_at' })
updatedAt: Date;
}
8 changes: 8 additions & 0 deletions src/entities/address-type.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Column, Entity } from 'typeorm';
import { AbstractEntity } from './abstract-entity';

@Entity({ name: 'address_type' })
export class AddressTypeEntity extends AbstractEntity {
@Column()
name: string;
}
47 changes: 47 additions & 0 deletions src/entities/address.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
import { AbstractEntity } from './abstract-entity';
import { StudentEntity } from './student.entity';
import { ParentEntity } from './parent.entity';
import { TutorEntity } from './tutor.entity';

@Entity({ name: 'address' })
export class AddressEntity extends AbstractEntity {
@Column({ default: '' })
city: string;

@Column({ default: '' })
country: string;

@Column({ default: '' })
street: string;

@Column({ default: '' })
state: string;

@Column({ default: '' })
province: string;

@Column({ default: '' })
zip_code: string;

@Column({ default: '' })
postal_code: string;

@Column({ default: '' })
line1: string;

@Column({ default: '' })
line2: string;

@ManyToOne(() => StudentEntity)
@JoinColumn({ name: 'student_id', referencedColumnName: 'id' })
student: StudentEntity;

@ManyToOne(() => ParentEntity)
@JoinColumn({ name: 'parent_id', referencedColumnName: 'id' })
parent: ParentEntity;

@ManyToOne(() => TutorEntity)
@JoinColumn({ name: 'tutor_id', referencedColumnName: 'id' })
tutor: TutorEntity;
}
48 changes: 48 additions & 0 deletions src/entities/attendance.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { AbstractEntity } from './abstract-entity';
import { Column, Entity, JoinTable, ManyToMany, ManyToOne } from 'typeorm';
import { SemesterEntity } from './semester.entity';
import { StudentEntity } from './student.entity';
import { TutorEntity } from './tutor.entity';
import { SubjectEntity } from './subject.entity';

@Entity({ name: 'attendance' })
export class AttendanceEntity extends AbstractEntity {
@Column()
status: string;

@Column()
month: string;

@ManyToMany(() => SemesterEntity)
@JoinTable({
name: 'subject_attendance',
joinColumn: { name: 'subject_id', referencedColumnName: 'id' },
inverseJoinColumn: { name: 'attendance_id', referencedColumnName: 'id' },
})
subject: SubjectEntity[];

@ManyToMany(() => SemesterEntity)
@JoinTable({
name: 'semester_attendance',
joinColumn: { name: 'semester_id', referencedColumnName: 'id' },
inverseJoinColumn: { name: 'attendance_id', referencedColumnName: 'id' },
})
semester: SemesterEntity[];

@ManyToMany(() => StudentEntity)
@JoinTable({
name: 'student_attendance',
joinColumn: { name: 'student_id', referencedColumnName: 'id' },
inverseJoinColumn: { name: 'attendance_id', referencedColumnName: 'id' },
})
student: StudentEntity[];

@ManyToMany(() => TutorEntity)
@JoinTable({
name: 'tutor_attendance',
joinColumn: { name: 'tutor_id', referencedColumnName: 'id' },
inverseJoinColumn: { name: 'attendance_id', referencedColumnName: 'id' },
})
tutor: TutorEntity[];

}
27 changes: 27 additions & 0 deletions src/entities/class.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { AbstractEntity } from './abstract-entity';
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
import { ClassroomEntity } from './classroom.entity';
import { SubjectEntity } from './subject.entity';
import { TutorEntity } from './tutor.entity';

@Entity({ name: 'class' })
export class ClassEntity extends AbstractEntity {
@Column()
period: number;

@Column()
time: Date;

@ManyToOne(() => ClassroomEntity)
@JoinColumn({ name: 'classroom_id', referencedColumnName: 'id' })
classroom: ClassroomEntity;

@ManyToOne(() => SubjectEntity)
@JoinColumn({ name: 'subject_id', referencedColumnName: 'id' })
subject: SubjectEntity;

@ManyToOne(() => TutorEntity)
@JoinColumn({ name: 'tutor_id', referencedColumnName: 'id' })
tutor: TutorEntity;

}
12 changes: 12 additions & 0 deletions src/entities/classroom.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { AbstractEntity } from './abstract-entity';
import { Column, Entity } from 'typeorm';

@Entity({ name: 'classroom' })
export class ClassroomEntity extends AbstractEntity {
@Column()
name: string;
@Column()
capacity: number;
@Column()
type: string;
}
15 changes: 15 additions & 0 deletions src/entities/course.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { AbstractEntity } from './abstract-entity';
import { Column, Entity } from 'typeorm';

@Entity({ name: 'course' })
export class CourseEntity extends AbstractEntity {
@Column()
name: string;

@Column()
code: string;

@Column()
capacity:number

}
8 changes: 8 additions & 0 deletions src/entities/department.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Column, Entity } from 'typeorm';
import { AbstractEntity } from './abstract-entity';

@Entity({ name: 'department' })
export class DepartmentEntity extends AbstractEntity {
@Column()
name: string;
}
11 changes: 11 additions & 0 deletions src/entities/exam-type.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Column, Entity } from 'typeorm';
import { AbstractEntity } from './abstract-entity';

@Entity({ name: 'exam_type' })
export class ExamTypeEntity extends AbstractEntity {
@Column()
name: string;

@Column({ default: '' })
description?: string;
}
17 changes: 17 additions & 0 deletions src/entities/exam.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Column, Entity, JoinColumn, OneToOne } from 'typeorm';
import { AbstractEntity } from './abstract-entity';
import { YearLevelEntity } from './year-level.entity';

@Entity({ name: 'exam' })
export class ExamEntity extends AbstractEntity {
@Column()
name: string;

@Column()
start_date: Date;

@OneToOne(() => YearLevelEntity)
@JoinColumn({ name: 'year_level_id', referencedColumnName: 'id' })
year: YearLevelEntity;

}
8 changes: 8 additions & 0 deletions src/entities/forum-status.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { AbstractEntity } from './abstract-entity';
import { Column, Entity } from 'typeorm';

@Entity({ name: 'forum_status' })
export class ForumStatusEntity extends AbstractEntity {
@Column()
name: string;
}
28 changes: 28 additions & 0 deletions src/entities/forum_post.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { AbstractEntity } from './abstract-entity';
import { Column, Entity, JoinColumn, ManyToOne, OneToOne } from 'typeorm';
import { StudentEntity } from './student.entity';
import { TutorEntity } from './tutor.entity';
import { ForumStatusEntity } from './forum-status.entity';
import { Forum_threadEntity } from './forum_thread.entity';

@Entity({ name: 'forum_post' })
export class Forum_postEntity extends AbstractEntity {
@Column({ type: 'text' })
content: string;

@OneToOne(() => ForumStatusEntity)
@JoinColumn({ name: 'forum_status_id', referencedColumnName: 'id' })
status: ForumStatusEntity;

@ManyToOne(() => Forum_threadEntity)
@JoinColumn({ name: 'forum_thread_id', referencedColumnName: 'id' })
thread: Forum_threadEntity;

@ManyToOne(() => StudentEntity)
@JoinColumn({ name: 'student_id', referencedColumnName: 'id' })
student: StudentEntity;

@ManyToOne(() => TutorEntity)
@JoinColumn({ name: 'tutor_id', referencedColumnName: 'id' })
tutor: TutorEntity;
}
9 changes: 9 additions & 0 deletions src/entities/forum_thread.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Column, Entity } from 'typeorm';
import { AbstractEntity } from './abstract-entity';

@Entity({ name: 'forum_thread' })
export class Forum_threadEntity extends AbstractEntity {
@Column()
title: string;

}
7 changes: 7 additions & 0 deletions src/entities/grades.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Entity } from 'typeorm';
import { AbstractEntity } from './abstract-entity';

@Entity({ name: 'grade' })
export class GradesEntity extends AbstractEntity {

}
38 changes: 38 additions & 0 deletions src/entities/parent.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
import { AbstractEntity } from './abstract-entity';
import { AddressEntity } from './address.entity';
import { StudentEntity } from './student.entity';

@Entity({ name: 'parent' })
export class ParentEntity extends AbstractEntity {
@Column()
first_name: string;

@Column()
last_name: string;

@Column()
email: string;

@Column()
contact: string;

@Column()
type: string;

@Column({ default: '' })
title: string;

@Column()
gender: string;

@Column({ default: '' })
occupation: string;

@OneToMany(() => AddressEntity, address => address.parent)
addresses: AddressEntity[];

@ManyToOne(() => StudentEntity)
@JoinColumn({ name: 'student_id', referencedColumnName: 'id' })
student: StudentEntity;
}
8 changes: 8 additions & 0 deletions src/entities/semester.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { AbstractEntity } from './abstract-entity';
import { Column, Entity } from 'typeorm';

@Entity({ name: 'semester' })
export class SemesterEntity extends AbstractEntity {
@Column()
name: string;
}
Loading

0 comments on commit 25a53cd

Please sign in to comment.