Skip to content

Commit

Permalink
initial impl test
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinmarshall committed Apr 19, 2021
1 parent 4d8ec53 commit 2c6db62
Show file tree
Hide file tree
Showing 19 changed files with 2,725 additions and 8,710 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
start-prod:
docker-compose up -d

stop-prod:
docker-compose down

start:
docker-compose -f docker-compose.dev.yml up -d

stop:
docker-compose -f docker-compose.dev.yml down

5,407 changes: 0 additions & 5,407 deletions mysql-dump/sms_db.sql

This file was deleted.

7 changes: 5 additions & 2 deletions nest-cli.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
"sourceRoot": "src",
"compilerOptions": {
"webpack": false
}
}
65 changes: 29 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,58 +25,51 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/bull": "^0.2.2",
"@nestjs/common": "^7.0.0",
"@nestjs/config": "^0.5.0",
"@nestjs/core": "^7.0.0",
"@nestjs/cqrs": "^7.0.1",
"@nestjs/bull": "^0.3.1",
"@nestjs/common": "^7.6.15",
"@nestjs/config": "^0.6.3",
"@nestjs/core": "^7.6.15",
"@nestjs/jwt": "^7.0.0",
"@nestjs/passport": "^7.1.0",
"@nestjs/platform-express": "^7.0.0",
"@nestjs/typeorm": "^7.1.0",
"@nestjs/mapped-types": "*",
"@nestjs/platform-express": "^7.6.15",
"@nestjs/typeorm": "7.1.5",
"bcryptjs": "^2.4.3",
"bull": "^3.18.0",
"class-transformer": "^0.3.1",
"class-validator": "^0.12.2",
"date-fns": "^2.16.1",
"moment": "^2.27.0",
"date-fns": "^2.21.1",
"mysql2": "^2.1.0",
"nest-winston": "^1.4.0",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.5.4",
"typeorm": "^0.2.25",
"rxjs": "^6.6.6",
"typeorm": "^0.2.32",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.0"
},
"devDependencies": {
"@nestjs/cli": "^7.0.0",
"@nestjs/schematics": "^7.0.0",
"@nestjs/testing": "^7.0.0",
"@types/bcryptjs": "^2.4.2",
"@types/bull": "^3.14.4",
"@types/express": "^4.17.3",
"@types/jest": "25.2.3",
"@types/node": "^13.9.1",
"@types/passport-jwt": "^3.0.3",
"@types/supertest": "^2.0.8",
"@types/winston": "^2.4.4",
"@typescript-eslint/eslint-plugin": "3.0.2",
"@typescript-eslint/parser": "3.0.2",
"eslint": "7.1.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.20.1",
"jest": "26.0.1",
"node-mocks-http": "^1.8.1",
"prettier": "^1.19.1",
"supertest": "^4.0.2",
"ts-jest": "26.1.0",
"ts-loader": "^6.2.1",
"ts-node": "^8.6.2",
"@nestjs/cli": "^7.6.0",
"@nestjs/schematics": "^7.3.0",
"@nestjs/testing": "^7.6.15",
"@types/express": "^4.17.11",
"@types/jest": "^26.0.22",
"@types/node": "^14.14.36",
"@types/supertest": "^2.0.10",
"@typescript-eslint/eslint-plugin": "^4.19.0",
"@typescript-eslint/parser": "^4.19.0",
"eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"supertest": "^6.1.3",
"ts-jest": "^26.5.4",
"ts-loader": "^8.0.18",
"ts-node": "^9.1.1",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.7.4"
"typescript": "^4.2.3"
},
"jest": {
"setupFiles": [
Expand Down
17 changes: 17 additions & 0 deletions src/module/student/dto/create-student.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { PartialType } from '@nestjs/mapped-types';
import { StudentEntity } from '../../../entities/student.entity';
import { Gender, ParentType } from '../../../libs';
import { ParentEntity } from '../../../entities/parent.entity';

export class CreateStudentDto extends PartialType(StudentEntity) {
first_name: string;
last_name: string;
contact: string;
email: string;
gender: Gender;
date_of_birth: string;
}

export class CreateParentDto extends PartialType(ParentEntity){

}
4 changes: 4 additions & 0 deletions src/module/student/dto/update-student.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateStudentDto } from './create-student.dto';

export class UpdateStudentDto extends PartialType(CreateStudentDto) {}
11 changes: 11 additions & 0 deletions src/module/student/parent/dto/create-parent.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Gender, ParentType } from '../../../../libs';

export class CreateParentDto {
first_name: string;
last_name: string;
contact: string;
email: string;
type: ParentType;
gender: Gender;
student_id: number;
}
4 changes: 4 additions & 0 deletions src/module/student/parent/dto/update-parent.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateParentDto } from './create-parent.dto';

export class UpdateParentDto extends PartialType(CreateParentDto) {}
20 changes: 20 additions & 0 deletions src/module/student/parent/parent.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ParentController } from './parent.controller';
import { ParentService } from './parent.service';

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

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

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

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
34 changes: 34 additions & 0 deletions src/module/student/parent/parent.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { ParentService } from './parent.service';
import { CreateParentDto } from './dto/create-parent.dto';
import { UpdateParentDto } from './dto/update-parent.dto';

@Controller('student/parent')
export class ParentController {
constructor(private readonly parentService: ParentService) {}

@Post()
create(@Body() createParentDto: CreateParentDto) {
return this.parentService.create(createParentDto);
}

@Get()
findAll() {
return this.parentService.findAll();
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.parentService.findOne(+id);
}

@Patch(':id')
update(@Param('id') id: string, @Body() updateParentDto: UpdateParentDto) {
return this.parentService.update(+id, updateParentDto);
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.parentService.remove(+id);
}
}
14 changes: 14 additions & 0 deletions src/module/student/parent/parent.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Module } from '@nestjs/common';
import { ParentService } from './parent.service';
import { ParentController } from './parent.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ParentRepository } from './parent.repository';
import { StudentRepository } from '../student.repository';

@Module({
imports: [TypeOrmModule.forFeature([ParentRepository, StudentRepository])],
controllers: [ParentController],
providers: [ParentService],
})
export class ParentModule {
}
18 changes: 18 additions & 0 deletions src/module/student/parent/parent.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ParentService } from './parent.service';

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

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

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

it('should be defined', () => {
expect(service).toBeDefined();
});
});
47 changes: 47 additions & 0 deletions src/module/student/parent/parent.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Injectable } from '@nestjs/common';
import { CreateParentDto } from './dto/create-parent.dto';
import { UpdateParentDto } from './dto/update-parent.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { ParentRepository } from './parent.repository';
import { ParentEntity } from '../../../entities/parent.entity';
import { StudentEntity } from '../../../entities/student.entity';
import { StudentRepository } from '../student.repository';

@Injectable()
export class ParentService {
constructor(
@InjectRepository(ParentRepository)
private readonly parentRepository: ParentRepository,
@InjectRepository(StudentRepository)
private readonly studentRepository: StudentRepository) {
}

async create(createParentDto: CreateParentDto) {
const entity = this.parentRepository.create(createParentDto);
if (createParentDto.student_id) {
entity.student = await this.studentRepository
.findOne({ id: createParentDto.student_id });
}
return this.parentRepository.save(entity);
}

async findAll(): Promise<ParentEntity[]> {
return this.parentRepository.find();
}

async findOne(id: number) {
return this.parentRepository.findOne({ id });
}

async update(id: number, updateParentDto: UpdateParentDto): Promise<ParentEntity> {
const parent = await this.findOne(id);
console.log(parent);
if (!parent) return null;
parent.student = await this.studentRepository.findOne(updateParentDto.student_id);
return this.parentRepository.save(parent);
}

remove(id: number) {
return `This action removes a #${id} parent`;
}
}
20 changes: 20 additions & 0 deletions src/module/student/student.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { StudentController } from './student.controller';
import { StudentService } from './student.service';

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

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

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

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
34 changes: 34 additions & 0 deletions src/module/student/student.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { StudentService } from './student.service';
import { CreateStudentDto } from './dto/create-student.dto';
import { UpdateStudentDto } from './dto/update-student.dto';

@Controller('student')
export class StudentController {
constructor(private readonly studentService: StudentService) {}

@Post()
create(@Body() createStudentDto: CreateStudentDto) {
return this.studentService.create(createStudentDto);
}

@Get()
findAll() {
return this.studentService.findAll();
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.studentService.findOne(+id);
}

@Patch(':id')
update(@Param('id') id: string, @Body() updateStudentDto: UpdateStudentDto) {
return this.studentService.update(+id, updateStudentDto);
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.studentService.remove(+id);
}
}
14 changes: 14 additions & 0 deletions src/module/student/student.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Module } from '@nestjs/common';
import { StudentService } from './student.service';
import { StudentController } from './student.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { StudentRepository } from './student.repository';
import { ParentModule } from './parent/parent.module';

@Module({
imports:[TypeOrmModule.forFeature([StudentRepository]), ParentModule],
controllers: [StudentController],
providers: [StudentService],
})
export class StudentModule {
}
18 changes: 18 additions & 0 deletions src/module/student/student.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { StudentService } from './student.service';

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

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

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

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

0 comments on commit 2c6db62

Please sign in to comment.