Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
957b4dd
[Backend] Create Course Module
amanyih Feb 15, 2023
2bee00d
feat(backend):add user and department
Danitilahun Feb 16, 2023
d2cdb2b
Merge pull request #28 from Rate-The-Instructor/backend.merwan.rating
Merwan-J Feb 16, 2023
ebcf8dc
Backend, Create Instructors Module
amanyih Feb 16, 2023
84f47fb
[Backend] created reports module
Merwan-J Feb 15, 2023
e7cf890
feat(backend):add user and department
Danitilahun Feb 16, 2023
5270da2
feat(backend):add user and department
Danitilahun Feb 16, 2023
bded9e3
[backend] created rating module
Merwan-J Feb 16, 2023
b14e959
[backend] implemented auth
Merwan-J Feb 17, 2023
de59175
Merge pull request #35 from Rate-The-Instructor/backend.merwan.auth
Merwan-J Feb 17, 2023
be5d868
adding admin module
Danitilahun Feb 17, 2023
4d21703
Merge branch 'backend' into instructors
Merwan-J Feb 17, 2023
9198dc1
Merge pull request #31 from Rate-The-Instructor/instructors
Merwan-J Feb 17, 2023
6cf5fc1
Merge branch 'backend' into backend.dani.admin
Merwan-J Feb 17, 2023
e4c9bce
Merge pull request #36 from Rate-The-Instructor/backend.dani.admin
Merwan-J Feb 17, 2023
e381f94
Merge branch 'backend' of https://github.com/Rate-The-Instructor/Rate…
Merwan-J Feb 17, 2023
b5bda3b
[backend] models relations well connected
Merwan-J Feb 18, 2023
8a961bd
Merge pull request #41 from Rate-The-Instructor/backend.merwan.models…
Merwan-J Feb 18, 2023
3fa6602
Create relationship between instructors and rating
amanyih Feb 18, 2023
da10ff3
Merge pull request #44 from Rate-The-Instructor/backend.aman.instruct…
Merwan-J Feb 18, 2023
31499f6
[backend] changed some routes
Merwan-J Feb 19, 2023
5b7bebe
Co-authored-by: NAME amanuelyihunie27@gmail.com
Merwan-J Feb 19, 2023
266a27a
Co-authored-by: amanyih amanuelyihunie27@gmail.com
Merwan-J Feb 19, 2023
5b03a15
[backend]
Merwan-J Feb 19, 2023
f3ea4e2
[backend] deployment issues fixed
Merwan-J Feb 19, 2023
4958bfe
[backend] updated user service
Merwan-J Feb 19, 2023
681c480
[backend] populated instructor detail with ratings
Merwan-J Feb 19, 2023
4516106
[backend] added comment module
Epyuel Feb 20, 2023
ff82193
[backend] courses populated for instructor
Merwan-J Feb 20, 2023
6fdf0cb
sort rating by date, populate course and department of users
amanyih Feb 20, 2023
7793ea4
Merge branch 'backend' into backend.aman.searchAndFilter
Merwan-J Feb 20, 2023
148ecbe
Merge pull request #54 from Rate-The-Instructor/backend.aman.searchAn…
Merwan-J Feb 20, 2023
e777848
[backend] getAllInstructors populated
Merwan-J Feb 20, 2023
5ef743c
[backend] fixed model typos
Merwan-J Feb 20, 2023
4d0f8b7
[backend] set default for tagsCounter
Merwan-J Feb 20, 2023
2bf5885
Backend Comment Relations
amanyih Feb 20, 2023
d6905ba
Backend Rating Restriction
amanyih Feb 21, 2023
a2d8da9
Merge pull request #51 from Rate-The-Instructor/backend.eyuel.comment
Merwan-J Feb 21, 2023
cfd758f
Merge pull request #57 from Rate-The-Instructor/backend.aman.rating.r…
Merwan-J Feb 21, 2023
c71e08a
Populate data
amanyih Feb 21, 2023
4ff6a4d
Populate data
amanyih Feb 21, 2023
2cd5a87
Merge pull request #59 from Rate-The-Instructor/backend.aman.populate
Merwan-J Feb 21, 2023
c855599
[backend] fixed comment ref
Merwan-J Feb 21, 2023
69ff278
[backend] added roles and guards
Merwan-J Feb 21, 2023
f64bedb
[backend] signup field changed and reports populated
Merwan-J Feb 21, 2023
2e24343
[backend] isntructors not required on dept schema
Merwan-J Feb 21, 2023
95aa43a
[backend] one of the last
Merwan-J Feb 21, 2023
a85046d
[backend] two of the last
Merwan-J Feb 21, 2023
a1eb69f
[backend] there of the last
Merwan-J Feb 21, 2023
1de6517
[backend] four of the last
Merwan-J Feb 21, 2023
de75af7
[backend] five of the last
Merwan-J Feb 21, 2023
d74d2c3
[backend] five of the last
Merwan-J Feb 21, 2023
2984a56
[backend] six of the last
Merwan-J Feb 21, 2023
a7a1889
[backend] seven of the last
Merwan-J Feb 21, 2023
54292ff
[backend] added grades to answers
Merwan-J Feb 23, 2023
e44d1e7
[backend] added grades to answers
Merwan-J Feb 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,921 changes: 2,103 additions & 1,818 deletions backend/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
"class-validator": "^0.14.0",
"cloudinary": "^1.33.0",
"mongoose": "^6.9.0",
"multer": "^1.4.5-lts.1",
"passport": "^0.6.0",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"multer": "^1.4.5-lts.1",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0",
"swagger-ui-express": "^4.6.0"
Expand All @@ -53,6 +53,7 @@
"@types/jest": "29.2.4",
"@types/multer": "^1.4.7",
"@types/node": "18.11.18",
"@types/passport-jwt": "^3.0.8",
"@types/passport-local": "^1.0.35",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
Expand Down
13 changes: 13 additions & 0 deletions backend/src/admin/admin.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { AdminController } from './controller/admin.controller';
import { AdminSchema } from './schema/admin.schema';
import { AdminService } from './service/admin.service';

@Module({
imports:[
MongooseModule.forFeature([{name:"Admin",schema:AdminSchema}])],
controllers: [AdminController],
providers: [AdminService]
})
export class AdminModule {}
45 changes: 45 additions & 0 deletions backend/src/admin/controller/admin.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Admin } from '../schema/admin.schema';
import { AdminService } from '../service/admin.service';
import {
Controller,
Post,
Body,
Get,
Delete,
Param,
Put,
} from '@nestjs/common';
import { CreateAdminDto } from '../dto/admin.dto';

@Controller('admin')
export class AdminController {
constructor(private readonly adminService: AdminService) {}

@Get()
findAll(): Promise<Admin[]> {
return this.adminService.findAll();
}

@Get(':id')
findOne(@Param() Param) {
return this.adminService.findOne(Param.id);
}

@Post()
create(@Body() createAdminDto: CreateAdminDto): Promise<Admin> {
return this.adminService.create(createAdminDto);
}

@Delete(':id')
delete(@Param() Param): Promise<Admin> {
return this.adminService.delete(Param.id);
}

@Put(':id')
update(
@Param('id') id,
@Body() updateAdmindto: CreateAdminDto,
): Promise<Admin> {
return this.adminService.update(id, updateAdmindto);
}
}
36 changes: 36 additions & 0 deletions backend/src/admin/dto/admin.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
IsEmail,
IsNotEmpty,
IsString,
IsNumber,
IsBoolean,
} from 'class-validator';
export class CreateAdminDto {
@IsNotEmpty()
@IsString()
readonly firstname: string;

@IsNotEmpty()
@IsString()
readonly lastname: string;

@IsNotEmpty()
@IsString()
readonly username: string;

@IsNotEmpty()
@IsString()
readonly role: string;

@IsNotEmpty()
@IsString()
readonly password: string;

@IsNotEmpty()
@IsBoolean()
readonly status: boolean;

@IsNotEmpty()
@IsString()
readonly email: string;
}
10 changes: 10 additions & 0 deletions backend/src/admin/interface/admin.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface Admin {
id?:string;
firstname: string,
lastname: string,
username:string;
password:string;
email:string;
role:string;
status: string;
}
20 changes: 20 additions & 0 deletions backend/src/admin/schema/admin.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';

@Schema({ timestamps: true})
export class Admin {
@Prop({ required: true })
firstname: string;
@Prop({ required: true })
lastname: string;
@Prop({ required: true })
username: string;
@Prop({ required: true })
email: string;
@Prop({ required: true , default:false})
status: boolean;
@Prop({ required: true })
role: string;
@Prop({ required: true })
password: string;
}
export const AdminSchema = SchemaFactory.createForClass(Admin);
55 changes: 55 additions & 0 deletions backend/src/admin/service/admin.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { Admin } from '../schema/admin.schema';

@Injectable()
export class AdminService {
constructor( @InjectModel("Admin") private adminModel : Model<Admin>){}
async findAll():Promise<Admin[]>{
try{

return await this.adminModel.find();
}
catch (err){
throw err;
}

}
async findOne(id:string):Promise<Admin>{
try{
return await this.adminModel.findOne({_id:id});
}
catch (err){
throw err
}
}

async create(admin:Admin):Promise<Admin>{
try{
const new_admin= new this.adminModel(admin);
return await new_admin.save();
}
catch (err){
throw err;
}
}
async delete(id:string):Promise<Admin>{
try{
return await this.adminModel.findByIdAndDelete({_id:id})
}
catch (err){
throw err;
}
}

async update(id:string, admin:Admin):Promise<Admin>{
try{
return await this.adminModel.findByIdAndUpdate(id,admin,{new:true})
}
catch (err){
throw err;
}
}

}
22 changes: 0 additions & 22 deletions backend/src/app.controller.spec.ts

This file was deleted.

25 changes: 21 additions & 4 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ReportsModule } from './reports/reports.module';
import { MongooseModule } from '@nestjs/mongoose';
import { AuthModule } from './auth/auth.module';
import { UserModule } from './user/user.module';
import { ReportsModule } from './reports/reports.module';
import { RatingsModule } from './ratings/ratings.module';
import { CoursesModule } from './courses/courses.module';
import { InstructorsModule } from './instructors/instructors.module';
import { AdminModule } from './admin/admin.module';
import { DepartmentModule } from './department/department.module';
import { CommentModule } from './comment/comment.module';

@Module({
imports: [
MongooseModule.forRoot('mongodb://localhost:27017', {
dbName: 'RateTheInstructor',
}),
MongooseModule.forRoot(
'mongodb+srv://amanuel:test1234@cluster0.8yo5agg.mongodb.net/?retryWrites=true&w=majority',
{
dbName: 'RateTheInstructor',
},
),
ReportsModule,
RatingsModule,
AdminModule,
AuthModule,
UserModule,
CoursesModule,
InstructorsModule,
DepartmentModule,
CommentModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
5 changes: 1 addition & 4 deletions backend/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {

}
export class AppService {}
19 changes: 19 additions & 0 deletions backend/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Module } from '@nestjs/common';
import { AuthController } from './controllers/auth/auth.controller';
import { AuthService } from './services/auth/auth.service';
import { JwtModule, JwtService } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { JwtStrategy } from './strategies/jwt.strategy';

@Module({
imports: [
JwtModule.register({
secret: 'SECRET',
signOptions: { expiresIn: '60s' },
}),
PassportModule,
],
controllers: [AuthController],
providers: [AuthService, JwtStrategy],
})
export class AuthModule {}
18 changes: 18 additions & 0 deletions backend/src/auth/controllers/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthController } from './auth.controller';

describe('AuthController', () => {
let controller: AuthController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AuthController],
}).compile();

controller = module.get<AuthController>(AuthController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
29 changes: 29 additions & 0 deletions backend/src/auth/controllers/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Controller, Post, Body, UseGuards, Get, Req } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { Request } from 'express';
import { AuthService } from 'src/auth/services/auth/auth.service';
import { CreateUserDto } from 'src/user/dto/user.dto';

@Controller('auth')
export class AuthController {
constructor(private authService: AuthService) {}

@Post('/login')
async login(@Body() loginData) {
return this.authService.login(loginData);
}
@Post('/signup')
async signup(@Body() authDto: CreateUserDto) {
return this.authService.signup(authDto);
}
@Post('/logout')
async logout() {
return this.authService.logout();
}

@UseGuards(AuthGuard('jwt'))
@Get('/protected')
async protected(@Req() req: Request) {
return req.user;
}
}
24 changes: 24 additions & 0 deletions backend/src/auth/guards/roles.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { SetMetadata } from '@nestjs/common';

export const Roles = (...roles: string[]) => SetMetadata('roles', roles);

@Injectable()
export class RoleGuard implements CanActivate {
constructor(private readonly reflector: Reflector) {}

canActivate(context: ExecutionContext): boolean {
const roles = this.reflector.get<string[]>('roles', context.getHandler());
if (!roles) {
return true;
}
const request = context.switchToHttp().getRequest();
const user = request.user;
return this.matchRoles(roles, user.role);
}

private matchRoles(roles: string[], userRole: string) {
return roles.includes(userRole);
}
}
18 changes: 18 additions & 0 deletions backend/src/auth/services/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthService } from './auth.service';

describe('AuthService', () => {
let service: AuthService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AuthService],
}).compile();

service = module.get<AuthService>(AuthService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
Loading