Skip to content

Commit

Permalink
feat(global): add apps
Browse files Browse the repository at this point in the history
  • Loading branch information
letovsk1y committed Feb 28, 2024
1 parent 65f85d4 commit 7a7f8f9
Show file tree
Hide file tree
Showing 63 changed files with 3,003 additions and 184 deletions.
61 changes: 1 addition & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,3 @@
# PetMis

<a alt="Nx logo" href="https://nx.dev" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.png" width="45"></a>

**This workspace has been generated by [Nx, Smart Monorepos · Fast CI.](https://nx.dev)**

## Integrate with editors

Enhance your Nx experience by installing [Nx Console](https://nx.dev/nx-console) for your favorite editor. Nx Console
provides an interactive UI to view your projects, run tasks, generate code, and more! Available for VSCode, IntelliJ and
comes with a LSP for Vim users.

## Start the application

Run `npx nx serve pet-mis` to start the development server. Happy coding!

## Build for production

Run `npx nx build pet-mis` to build the application. The build artifacts are stored in the output directory (e.g. `dist/` or `build/`), ready to be deployed.

## Running tasks

To execute tasks with Nx use the following syntax:

```
npx nx <target> <project> <...options>
```

You can also run multiple targets:

```
npx nx run-many -t <target1> <target2>
```

..or add `-p` to filter specific projects

```
npx nx run-many -t <target1> <target2> -p <proj1> <proj2>
```

Targets can be defined in the `package.json` or `projects.json`. Learn more [in the docs](https://nx.dev/features/run-tasks).

## Set up CI!

Nx comes with local caching already built-in (check your `nx.json`). On CI you might want to go a step further.

- [Set up remote caching](https://nx.dev/features/share-your-cache)
- [Set up task distribution across multiple machines](https://nx.dev/nx-cloud/features/distribute-task-execution)
- [Learn more how to setup CI](https://nx.dev/recipes/ci)

## Explore the project graph

Run `npx nx graph` to show the graph of the workspace.
It will show tasks that you can run with Nx.

- [Learn more about Exploring the Project Graph](https://nx.dev/core-features/explore-graph)

## Connect with us!

- [Join the community](https://nx.dev/community)
- [Subscribe to the Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
- [Follow us on Twitter](https://twitter.com/nxdevtools)
TODO WRITE README
2 changes: 1 addition & 1 deletion apps/mis-api-e2e/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export default {
],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/pet-mis-e2e',
coverageDirectory: '../../coverage/mis-api-e2e',
};
2 changes: 1 addition & 1 deletion apps/mis-api-e2e/src/pet-mis/pet-mis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios';

describe('GET /api', () => {
it('should return a message', async () => {
const res = await axios.get(`/api`);
const res = await axios.get(`/api/v1`);

expect(res.status).toBe(200);
expect(res.data).toEqual({ message: 'Hello API' });
Expand Down
20 changes: 19 additions & 1 deletion apps/mis-api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,27 @@ import { Module } from '@nestjs/common';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { PatientModule } from '../patients/patient.module';
import { DoctorModule } from '../doctor/doctor.module';
import { ScheduleModule } from '../schedule/schedule.module';

@Module({
imports: [],
imports: [
TypeOrmModule.forRoot({
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'admin',
password: 'admin',
database: 'misapi',
synchronize: true,
autoLoadEntities: true,
}),
PatientModule,
DoctorModule,
ScheduleModule
],
controllers: [AppController],
providers: [AppService],
})
Expand Down
18 changes: 18 additions & 0 deletions apps/mis-api/src/doctor/doctor.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { DoctorController } from './doctor.controller';

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

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

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

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
16 changes: 16 additions & 0 deletions apps/mis-api/src/doctor/doctor.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Body, Controller, Post, ValidationPipe } from '@nestjs/common';
import { DoctorService } from './doctor.service';
import { CreateDoctorDto } from './dto';
import { Doctor } from './entities';
import { ApiTags } from '@nestjs/swagger';

@ApiTags("doctor")
@Controller('doctor')
export class DoctorController {
constructor(private doctorService: DoctorService) {}
@Post()
async createPatient(@Body(new ValidationPipe()) createDoctorDto: CreateDoctorDto): Promise<Doctor> {
return await this.doctorService.create(createDoctorDto);
}
}

13 changes: 13 additions & 0 deletions apps/mis-api/src/doctor/doctor.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { DoctorService } from './doctor.service';
import { DoctorController } from './doctor.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Doctor } from './entities';

@Module({
imports: [TypeOrmModule.forFeature([Doctor])],
exports: [TypeOrmModule],
providers: [DoctorService],
controllers: [DoctorController]
})
export class DoctorModule {}
18 changes: 18 additions & 0 deletions apps/mis-api/src/doctor/doctor.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { DoctorService } from './doctor.service';

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

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

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

it('should be defined', () => {
expect(service).toBeDefined();
});
});
22 changes: 22 additions & 0 deletions apps/mis-api/src/doctor/doctor.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Doctor } from './entities';
import { CreateDoctorDto } from './dto';

@Injectable()
export class DoctorService {
constructor(
@InjectRepository(Doctor)
private doctorRepository: Repository<Doctor>,
) {}

async create(createDoctorDto: CreateDoctorDto): Promise<Doctor> {
const entity = this.doctorRepository.create(createDoctorDto);
if (entity.price < 0) {
throw new HttpException("price can not be less than 0", HttpStatus.BAD_REQUEST);
}

return await this.doctorRepository.save(entity);
}
}
19 changes: 19 additions & 0 deletions apps/mis-api/src/doctor/dto/create-doctor.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { IsInt, IsNotEmpty, IsString, Min } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';

export class CreateDoctorDto {
@IsString()
@IsNotEmpty()
@ApiProperty()
name: string;

@IsString()
@IsNotEmpty()
@ApiProperty()
spec: string;

@IsInt()
@Min(0)
@ApiProperty()
price: number;
}
3 changes: 3 additions & 0 deletions apps/mis-api/src/doctor/dto/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { CreateDoctorDto } from "./create-doctor.dto";

export { CreateDoctorDto }
16 changes: 16 additions & 0 deletions apps/mis-api/src/doctor/entities/doctor.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';

@Entity("doctors")
export class Doctor {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column()
name: string;

@Column()
spec: string;

@Column()
price: number;
}
3 changes: 3 additions & 0 deletions apps/mis-api/src/doctor/entities/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Doctor } from "./doctor.entity";

export { Doctor }
16 changes: 14 additions & 2 deletions apps/mis-api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
* This is only a minimal backend to get started.
*/

import { Logger } from '@nestjs/common';
import { INestApplication, Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';

import { AppModule } from './app/app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const globalPrefix = 'api';

const globalPrefix = 'api/v1';
app.setGlobalPrefix(globalPrefix);

setupOpenApi(app);

const port = process.env.PORT || 3000;
await app.listen(port);
Logger.log(
Expand All @@ -20,3 +25,10 @@ async function bootstrap() {
}

bootstrap();


function setupOpenApi(app: INestApplication) {
const config = new DocumentBuilder().setTitle('API Documentation').setVersion('1.0').build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('swagger', app, document);
}
31 changes: 31 additions & 0 deletions apps/mis-api/src/patients/dto/create-patient.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Gender } from '../enums';
import { IsEmail, IsEnum, IsNotEmpty, IsString, Matches } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';

export class CreatePatientDto {
@IsNotEmpty()
@IsString()
@ApiProperty()
firstName: string;

@IsNotEmpty()
@IsString()
@ApiProperty()
lastName: string;

@Matches(/^\+\d+/, {
message: "phone must be valid phone format: +123456789..."
})
@IsString()
@ApiProperty()
phone: string;

@IsNotEmpty()
@IsEmail()
@ApiProperty()
email: string;

@IsEnum(Gender)
@ApiProperty({ enum: Gender })
gender: Gender;
}
3 changes: 3 additions & 0 deletions apps/mis-api/src/patients/dto/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { CreatePatientDto } from "./create-patient.dto";

export { CreatePatientDto }
3 changes: 3 additions & 0 deletions apps/mis-api/src/patients/entities/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Patient } from "./patient.entity";

export { Patient }
20 changes: 20 additions & 0 deletions apps/mis-api/src/patients/entities/patient.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
import { Gender } from '../enums';

@Entity("patients")
export class Patient {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column()
name: string;

@Column({ unique: true })
phone: string;

@Column({ unique: true })
email: string;

@Column({ type: "enum", enum: Gender })
gender: Gender;
}
4 changes: 4 additions & 0 deletions apps/mis-api/src/patients/enums/gender.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum Gender {
MALE = 'male',
FEMALE = 'female'
}
3 changes: 3 additions & 0 deletions apps/mis-api/src/patients/enums/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Gender } from "./gender.enum";

export { Gender }
18 changes: 18 additions & 0 deletions apps/mis-api/src/patients/patient.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { PatientController } from './patient.controller';

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

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

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

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
16 changes: 16 additions & 0 deletions apps/mis-api/src/patients/patient.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Body, Controller, Post, ValidationPipe } from '@nestjs/common';
import { CreatePatientDto } from './dto';
import { ApiTags } from '@nestjs/swagger';
import { PatientService } from './patient.service';
import { Patient } from './entities';

@ApiTags("patient")
@Controller('patient')
export class PatientController {
constructor(private patientService: PatientService) {}

@Post()
async createPatient(@Body(new ValidationPipe()) createPatientDto: CreatePatientDto): Promise<Patient> {
return await this.patientService.create(createPatientDto);
}
}
13 changes: 13 additions & 0 deletions apps/mis-api/src/patients/patient.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Patient } from './entities';
import { PatientController } from './patient.controller';
import { PatientService } from './patient.service';

@Module({
imports: [TypeOrmModule.forFeature([Patient])],
exports: [TypeOrmModule, PatientService],
controllers: [PatientController],
providers: [PatientService]
})
export class PatientModule {}
Loading

0 comments on commit 7a7f8f9

Please sign in to comment.