-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b83c368
commit cce8e6f
Showing
17 changed files
with
687 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Request, Response } from 'express'; | ||
import asyncHandler from 'express-async-handler'; | ||
import { getAllCourses, | ||
getCourseById, | ||
createCourse, | ||
deleteCourse, | ||
updateCourse, | ||
} from '../services/course.service'; | ||
|
||
export const courseList = | ||
asyncHandler(async (req: Request, res: Response) => { | ||
const courses = await getAllCourses(); | ||
res.status(200).json(courses); | ||
}); | ||
|
||
export const courseDetails = | ||
asyncHandler(async (req: Request, res: Response) => { | ||
const courseId = parseInt(req.params.id); | ||
const course = await getCourseById(courseId); | ||
|
||
if (course) { | ||
res.status(200).json(course); | ||
} else { | ||
res.status(404).json({ message: 'Course not found' }); | ||
} | ||
}); | ||
|
||
export const createCourseGet = | ||
asyncHandler(async (req: Request, res: Response) => { | ||
res.status(200).json({ message: 'Provide course data to create a course' }); | ||
}); | ||
|
||
export const createCoursePost = | ||
asyncHandler(async (req: Request, res: Response) => { | ||
const courseData = req.body; | ||
const newCourse = await createCourse(courseData); | ||
res.status(201).json(newCourse); | ||
}); | ||
|
||
export const deleteCourseGet = | ||
asyncHandler(async (req: Request, res: Response) => { | ||
res.status(200).json({ message: 'Confirm course deletion' }); | ||
}); | ||
|
||
export const deleteCoursePost = | ||
asyncHandler(async (req: Request, res: Response) => { | ||
const courseId = parseInt(req.params.id); | ||
const course = await getCourseById(courseId); | ||
|
||
if (course) { | ||
await deleteCourse(course); | ||
res.status(200).json({ message: 'Course deleted' }); | ||
} else { | ||
res.status(404).json({ message: 'Course not found' }); | ||
} | ||
}); | ||
|
||
export const updateCourseGet = | ||
asyncHandler(async (req: Request, res: Response) => { | ||
res.status(200).json({ message: 'Provide updated course data' }); | ||
}); | ||
|
||
export const updateCoursePost = | ||
asyncHandler(async (req: Request, res: Response) => { | ||
const courseId = parseInt(req.params.id); | ||
const course = await getCourseById(courseId); | ||
|
||
if (course) { | ||
const updatedData = req.body; | ||
const updatedCourse = await updateCourse(course, updatedData); | ||
res.status(200).json(updatedCourse); | ||
} else { | ||
res.status(404).json({ message: 'Course not found' }); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { getAllUsers, | ||
getUserById, | ||
createUser, | ||
updateUser, | ||
deleteUser | ||
} from '../services/user.service'; | ||
import { Request, Response } from 'express'; | ||
import asyncHandler from 'express-async-handler'; | ||
|
||
export const userList = | ||
asyncHandler(async (req: Request, res: Response) => { | ||
const users = await getAllUsers(); | ||
res.status(200).json(users); | ||
}); | ||
|
||
export const userDetails = | ||
asyncHandler(async (req: Request, res: Response) => { | ||
const userId = parseInt(req.params.id); | ||
const user = await getUserById(userId); | ||
|
||
if (user) { | ||
res.status(200).json(user); | ||
} else { | ||
res.status(404).json({ message: 'User not found' }); | ||
} | ||
}); | ||
|
||
export const userCreateGet = | ||
asyncHandler(async (req: Request, res: Response) => { | ||
res.status(200).json({ message: 'Display user creation form' }); | ||
}); | ||
|
||
export const userCreatePost = | ||
asyncHandler(async (req: Request, res: Response) => { | ||
const newUserData = req.body; | ||
const newUser = await createUser(newUserData); | ||
res.status(201).json(newUser); | ||
}); | ||
|
||
export const userDeleteGet = | ||
asyncHandler(async (req: Request, res: Response) => { | ||
const userId = parseInt(req.params.id); | ||
const user = await getUserById(userId); | ||
|
||
if (user) { | ||
res.status(200).json({ message: 'Confirm deletion of user', user }); | ||
} else { | ||
res.status(404).json({ message: 'User not found' }); | ||
} | ||
}); | ||
|
||
export const userDeletePost = | ||
asyncHandler(async (req: Request, res: Response) => { | ||
const userId = parseInt(req.params.id); | ||
await deleteUser(userId); | ||
res.status(204).send(); | ||
}); | ||
|
||
export const userUpdateGet = | ||
asyncHandler(async (req: Request, res: Response) => { | ||
const userId = parseInt(req.params.id); | ||
const user = await getUserById(userId); | ||
|
||
if (user) { | ||
res.status(200).json(user); | ||
} else { | ||
res.status(404).json({ message: 'User not found' }); | ||
} | ||
}); | ||
|
||
export const userUpdatePost = | ||
asyncHandler(async (req: Request, res: Response) => { | ||
const userToUpdate = await getUserById(parseInt(req.params.id)); | ||
const updatedUserData = req.body; | ||
if (!userToUpdate) { | ||
throw new Error('User not found'); | ||
} | ||
const updatedUser = await updateUser(userToUpdate, updatedUserData); | ||
|
||
if (updatedUser) { | ||
res.status(200).json(updatedUser); | ||
} else { | ||
res.status(404).json({ message: 'User not found' }); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Entity, | ||
Column, | ||
PrimaryGeneratedColumn, | ||
ManyToOne, | ||
CreateDateColumn, | ||
UpdateDateColumn, | ||
JoinColumn | ||
} from 'typeorm'; | ||
import { Lesson } from './Lesson'; | ||
|
||
@Entity('components') | ||
export class Component { | ||
@PrimaryGeneratedColumn('increment', { type: 'bigint' }) | ||
id!: number; | ||
|
||
@ManyToOne(() => Lesson) | ||
@JoinColumn({ name: 'lesson_id' }) | ||
lesson!: Lesson; | ||
|
||
@Column({ | ||
type: 'enum', | ||
enum: ['video', 'url', 'pdf', 'text'], | ||
}) | ||
type!: string; | ||
|
||
@Column('text') | ||
content!: string; | ||
|
||
@CreateDateColumn({ type: 'datetime' }) | ||
created_at!: Date; | ||
|
||
@UpdateDateColumn({ type: 'datetime' }) | ||
updated_at!: Date; | ||
|
||
constructor(componentData?: Partial<Component>) { | ||
componentData && Object.assign(this, componentData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Entity, | ||
Column, | ||
PrimaryGeneratedColumn, | ||
ManyToOne, | ||
CreateDateColumn, | ||
UpdateDateColumn, | ||
JoinColumn | ||
} from 'typeorm'; | ||
import { User } from './User'; | ||
|
||
@Entity('courses') | ||
export class Course { | ||
@PrimaryGeneratedColumn('increment', { type: 'bigint' }) | ||
id!: number; | ||
|
||
@ManyToOne(() => User) | ||
@JoinColumn({ name: 'professor_id' }) | ||
professor!: User; | ||
|
||
@Column() | ||
name!: string; | ||
|
||
@Column('double') | ||
price!: number; | ||
|
||
@Column('text') | ||
description!: string; | ||
|
||
@Column('float') | ||
average_rating!: number; | ||
|
||
@Column({ type: 'bigint' }) | ||
professor_id!: number; | ||
|
||
@CreateDateColumn({ type: 'datetime' }) | ||
created_at!: Date; | ||
|
||
@UpdateDateColumn({ type: 'datetime' }) | ||
updated_at!: Date; | ||
|
||
constructor(courseData?: Partial<Course>) { | ||
courseData && Object.assign(this, courseData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Entity, | ||
Column, | ||
PrimaryGeneratedColumn, | ||
ManyToOne, | ||
CreateDateColumn, | ||
UpdateDateColumn, | ||
JoinColumn | ||
} from 'typeorm'; | ||
import { User } from './User'; | ||
import { Course } from './Course'; | ||
|
||
@Entity('enrollments') | ||
export class Enrollment { | ||
@PrimaryGeneratedColumn('increment', { type: 'bigint' }) | ||
id!: number; | ||
|
||
@ManyToOne(() => User) | ||
@JoinColumn({ name: 'user_id' }) | ||
user!: User; | ||
|
||
@ManyToOne(() => Course) | ||
@JoinColumn({ name: 'course_id' }) | ||
course!: Course; | ||
|
||
@Column({ type: 'datetime' }) | ||
enrollment_date!: Date; | ||
|
||
@Column('integer') | ||
progress!: number; | ||
|
||
@Column({ type: 'datetime' }) | ||
completion_date!: Date; | ||
|
||
@Column({ type: 'bigint' }) | ||
user_id!: number; | ||
|
||
@Column({ type: 'bigint' }) | ||
course_id!: number; | ||
|
||
@CreateDateColumn({ type: 'datetime' }) | ||
created_at!: Date; | ||
|
||
@UpdateDateColumn({ type: 'datetime' }) | ||
updated_at!: Date; | ||
|
||
constructor(enrollmentData?: Partial<Enrollment>) { | ||
enrollmentData && Object.assign(this, enrollmentData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Entity, | ||
Column, | ||
PrimaryGeneratedColumn, | ||
ManyToOne, | ||
CreateDateColumn, | ||
UpdateDateColumn, | ||
JoinColumn | ||
} from 'typeorm'; | ||
import { Enrollment } from './Enrollment'; | ||
import { Lesson } from './Lesson'; | ||
|
||
@Entity('enrollments_lessons') | ||
export class EnrollmentLesson { | ||
@PrimaryGeneratedColumn('increment', { type: 'bigint' }) | ||
id!: number; | ||
|
||
@ManyToOne(() => Enrollment) | ||
@JoinColumn({ name: 'enrollment_id' }) | ||
enrollment!: Enrollment; | ||
|
||
@ManyToOne(() => Lesson) | ||
@JoinColumn({ name: 'lesson_id' }) | ||
lesson!: Lesson; | ||
|
||
@Column('integer') | ||
progress!: number; | ||
|
||
@Column({ type: 'datetime' }) | ||
completion_date!: Date; | ||
|
||
@Column({ type: 'bigint' }) | ||
enrollment_id!: number; | ||
|
||
@Column({ type: 'bigint' }) | ||
lesson_id!: number; | ||
|
||
@CreateDateColumn({ type: 'datetime' }) | ||
created_at!: Date; | ||
|
||
@UpdateDateColumn({ type: 'datetime' }) | ||
updated_at!: Date; | ||
|
||
constructor(enrollmentLessonData?: Partial<EnrollmentLesson>) { | ||
enrollmentLessonData && Object.assign(this, enrollmentLessonData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Entity, | ||
Column, | ||
PrimaryGeneratedColumn, | ||
ManyToOne, | ||
CreateDateColumn, | ||
UpdateDateColumn, | ||
JoinColumn | ||
} from 'typeorm'; | ||
import { Section } from './Section'; | ||
|
||
@Entity('lessons') | ||
export class Lesson { | ||
@PrimaryGeneratedColumn('increment', { type: 'bigint' }) | ||
id!: number; | ||
|
||
@ManyToOne(() => Section) | ||
@JoinColumn({ name: 'section_id' }) | ||
section!: Section; | ||
|
||
@Column() | ||
name!: string; | ||
|
||
@Column('text') | ||
description!: string; | ||
|
||
@Column('integer') | ||
time!: number; | ||
|
||
@Column({ type: 'bigint' }) | ||
section_id!: number; | ||
|
||
@CreateDateColumn({ type: 'datetime' }) | ||
created_at!: Date; | ||
|
||
@UpdateDateColumn({ type: 'datetime' }) | ||
updated_at!: Date; | ||
|
||
constructor(lessonData?: Partial<Lesson>) { | ||
lessonData && Object.assign(this, lessonData); | ||
} | ||
} |
Oops, something went wrong.