├── .env.example ├── .prettierrc.json ├── nest-cli.json ├── tsconfig.build.json ├── src ├── user │ ├── dto │ │ ├── update-user.dto.ts │ │ └── create-user.dto.ts │ ├── user.module.ts │ ├── user.service.spec.ts │ ├── entities │ │ └── user.entity.ts │ ├── user.controller.spec.ts │ ├── user.controller.ts │ └── user.service.ts ├── products │ ├── dto │ │ └── product │ │ │ ├── update-product.dto.ts │ │ │ └── create-product.dto.ts │ ├── entities │ │ └── product.entity.ts │ ├── products.module.ts │ ├── products.controller.spec.ts │ ├── products.service.spec.ts │ ├── products.controller.ts │ └── products.service.ts ├── supplier │ ├── dto │ │ ├── update-supplier.dto.ts │ │ └── create-supplier.dto.ts │ ├── supplier.service.spec.ts │ ├── supplier.module.ts │ ├── supplier.controller.spec.ts │ ├── entities │ │ └── supplier.entity.ts │ ├── supplier.controller.ts │ └── supplier.service.ts ├── main.ts └── app.module.ts ├── test ├── jest-e2e.json └── app.e2e-spec.ts ├── .gitignore ├── tsconfig.json ├── .eslintrc.js ├── README.md ├── package.json └── Insomnia.json /.env.example: -------------------------------------------------------------------------------- 1 | DB_MONGO_URI=example -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "collection": "@nestjs/schematics", 3 | "sourceRoot": "src" 4 | } 5 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /src/user/dto/update-user.dto.ts: -------------------------------------------------------------------------------- 1 | import { PartialType } from '@nestjs/mapped-types'; 2 | import { CreateUserDto } from './create-user.dto'; 3 | 4 | export class UpdateUserDto extends PartialType(CreateUserDto) {} 5 | -------------------------------------------------------------------------------- /src/products/dto/product/update-product.dto.ts: -------------------------------------------------------------------------------- 1 | import { PartialType } from '@nestjs/mapped-types'; 2 | import { CreateProductDto } from './create-product.dto'; 3 | 4 | export class UpdateProductDto extends PartialType(CreateProductDto) {} 5 | -------------------------------------------------------------------------------- /src/supplier/dto/update-supplier.dto.ts: -------------------------------------------------------------------------------- 1 | import { PartialType } from '@nestjs/mapped-types'; 2 | import { CreateSupplierDto } from './create-supplier.dto'; 3 | 4 | export class UpdateSupplierDto extends PartialType(CreateSupplierDto) {} 5 | -------------------------------------------------------------------------------- /test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(process.env.PORT || 3000); 7 | } 8 | bootstrap(); 9 | -------------------------------------------------------------------------------- /src/products/entities/product.entity.ts: -------------------------------------------------------------------------------- 1 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; 2 | import { Document } from 'mongoose'; 3 | 4 | export type ProductDocument = Product & Document; 5 | 6 | @Schema() 7 | export class Product { 8 | @Prop() 9 | name: string; 10 | 11 | @Prop() 12 | quantity: number; 13 | 14 | @Prop() 15 | price: number; 16 | 17 | @Prop() 18 | description: string; 19 | } 20 | 21 | export const ProductSchema = SchemaFactory.createForClass(Product); 22 | -------------------------------------------------------------------------------- /src/user/user.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { UserService } from './user.service'; 3 | import { UserController } from './user.controller'; 4 | import { MongooseModule } from '@nestjs/mongoose'; 5 | import { User, UserSchema } from './entities/user.entity'; 6 | 7 | @Module({ 8 | imports: [ 9 | MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]), 10 | ], 11 | controllers: [UserController], 12 | providers: [UserService], 13 | }) 14 | export class UserModule {} 15 | -------------------------------------------------------------------------------- /src/products/dto/product/create-product.dto.ts: -------------------------------------------------------------------------------- 1 | export interface Product { 2 | description: string; 3 | name: string; 4 | price: number; 5 | quantity: number; 6 | } 7 | 8 | export class CreateProductDto { 9 | description: string; 10 | name: string; 11 | price: number; 12 | quantity: number; 13 | 14 | constructor({ description, name, price, quantity }: Product) { 15 | (this.description = description), 16 | (this.name = name), 17 | (this.price = price), 18 | (this.quantity = quantity); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/products/products.module.ts: -------------------------------------------------------------------------------- 1 | import { Product, ProductSchema } from './entities/product.entity'; 2 | import { Module } from '@nestjs/common'; 3 | import { ProductsService } from './products.service'; 4 | import { ProductsController } from './products.controller'; 5 | import { MongooseModule } from '@nestjs/mongoose'; 6 | 7 | @Module({ 8 | imports: [MongooseModule.forFeature([{ name: Product.name, schema: ProductSchema }])], 9 | controllers: [ProductsController], 10 | providers: [ProductsService] 11 | }) 12 | export class ProductsModule {} 13 | -------------------------------------------------------------------------------- /src/user/user.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { UserService } from './user.service'; 3 | 4 | describe('UserService', () => { 5 | let service: UserService; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | providers: [UserService], 10 | }).compile(); 11 | 12 | service = module.get(UserService); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(service).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist 3 | /node_modules 4 | 5 | # env 6 | .env 7 | 8 | # Logs 9 | logs 10 | *.log 11 | npm-debug.log* 12 | pnpm-debug.log* 13 | yarn-debug.log* 14 | yarn-error.log* 15 | lerna-debug.log* 16 | 17 | # OS 18 | .DS_Store 19 | 20 | # Tests 21 | /coverage 22 | /.nyc_output 23 | 24 | # IDEs and editors 25 | /.idea 26 | .project 27 | .classpath 28 | .c9/ 29 | *.launch 30 | .settings/ 31 | *.sublime-workspace 32 | 33 | # IDE - VSCode 34 | .vscode/* 35 | !.vscode/settings.json 36 | !.vscode/tasks.json 37 | !.vscode/launch.json 38 | !.vscode/extensions.json -------------------------------------------------------------------------------- /src/supplier/supplier.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { SupplierService } from './supplier.service'; 3 | 4 | describe('SupplierService', () => { 5 | let service: SupplierService; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | providers: [SupplierService], 10 | }).compile(); 11 | 12 | service = module.get(SupplierService); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(service).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /src/supplier/supplier.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { SupplierService } from './supplier.service'; 3 | import { SupplierController } from './supplier.controller'; 4 | import { MongooseModule } from '@nestjs/mongoose'; 5 | import { Supplier, SupplierSchema } from './entities/supplier.entity'; 6 | 7 | @Module({ 8 | imports: [ 9 | MongooseModule.forFeature([ 10 | { name: Supplier.name, schema: SupplierSchema }, 11 | ]), 12 | ], 13 | controllers: [SupplierController], 14 | providers: [SupplierService], 15 | }) 16 | export class SupplierModule {} 17 | -------------------------------------------------------------------------------- /src/user/entities/user.entity.ts: -------------------------------------------------------------------------------- 1 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; 2 | import { Document } from 'mongoose'; 3 | 4 | export type UserDocument = User & Document; 5 | 6 | @Schema() 7 | export class User { 8 | @Prop() 9 | completeName: string; 10 | 11 | @Prop() 12 | gender: string; 13 | 14 | @Prop() 15 | birthday: string; 16 | 17 | @Prop() 18 | CPF: string; 19 | 20 | @Prop() 21 | telephone: string; 22 | 23 | @Prop() 24 | email: string; 25 | 26 | @Prop() 27 | password: string; 28 | } 29 | 30 | export const UserSchema = SchemaFactory.createForClass(User); 31 | -------------------------------------------------------------------------------- /src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { ConfigModule } from '@nestjs/config'; 3 | import { MongooseModule } from '@nestjs/mongoose'; 4 | import { ProductsModule } from './products/products.module'; 5 | import { SupplierModule } from './supplier/supplier.module'; 6 | import { UserModule } from './user/user.module'; 7 | 8 | @Module({ 9 | imports: [ 10 | ConfigModule.forRoot(), 11 | MongooseModule.forRoot(process.env.DB_MONGO_URI), 12 | ProductsModule, 13 | SupplierModule, 14 | UserModule, 15 | ], 16 | controllers: [], 17 | providers: [], 18 | }) 19 | export class AppModule {} 20 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "target": "es2017", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true, 14 | "skipLibCheck": true, 15 | "strictNullChecks": false, 16 | "noImplicitAny": false, 17 | "strictBindCallApply": false, 18 | "forceConsistentCasingInFileNames": false, 19 | "noFallthroughCasesInSwitch": false 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/user/user.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { UserController } from './user.controller'; 3 | import { UserService } from './user.service'; 4 | 5 | describe('UserController', () => { 6 | let controller: UserController; 7 | 8 | beforeEach(async () => { 9 | const module: TestingModule = await Test.createTestingModule({ 10 | controllers: [UserController], 11 | providers: [UserService], 12 | }).compile(); 13 | 14 | controller = module.get(UserController); 15 | }); 16 | 17 | it('should be defined', () => { 18 | expect(controller).toBeDefined(); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /src/products/products.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { ProductsController } from './products.controller'; 3 | import { ProductsService } from './products.service'; 4 | 5 | describe('ProductsController', () => { 6 | let controller: ProductsController; 7 | 8 | beforeEach(async () => { 9 | const module: TestingModule = await Test.createTestingModule({ 10 | controllers: [ProductsController], 11 | providers: [ProductsService], 12 | }).compile(); 13 | 14 | controller = module.get(ProductsController); 15 | }); 16 | 17 | it('should be defined', () => { 18 | expect(controller).toBeDefined(); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /src/supplier/supplier.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { SupplierController } from './supplier.controller'; 3 | import { SupplierService } from './supplier.service'; 4 | 5 | describe('SupplierController', () => { 6 | let controller: SupplierController; 7 | 8 | beforeEach(async () => { 9 | const module: TestingModule = await Test.createTestingModule({ 10 | controllers: [SupplierController], 11 | providers: [SupplierService], 12 | }).compile(); 13 | 14 | controller = module.get(SupplierController); 15 | }); 16 | 17 | it('should be defined', () => { 18 | expect(controller).toBeDefined(); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | parserOptions: { 4 | project: 'tsconfig.json', 5 | sourceType: 'module', 6 | }, 7 | plugins: ['@typescript-eslint/eslint-plugin'], 8 | extends: [ 9 | 'plugin:@typescript-eslint/recommended', 10 | 'plugin:prettier/recommended', 11 | ], 12 | root: true, 13 | env: { 14 | node: true, 15 | jest: true, 16 | }, 17 | ignorePatterns: ['.eslintrc.js'], 18 | rules: { 19 | '@typescript-eslint/interface-name-prefix': 'off', 20 | '@typescript-eslint/explicit-function-return-type': 'off', 21 | '@typescript-eslint/explicit-module-boundary-types': 'off', 22 | '@typescript-eslint/no-explicit-any': 'off', 23 | }, 24 | }; 25 | -------------------------------------------------------------------------------- /src/supplier/entities/supplier.entity.ts: -------------------------------------------------------------------------------- 1 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; 2 | import { Document } from 'mongoose'; 3 | 4 | export type SupplierDocument = Supplier & Document; 5 | 6 | @Schema() 7 | export class Supplier { 8 | @Prop() 9 | CNPJ: string; 10 | 11 | @Prop() 12 | corporateName: string; 13 | 14 | @Prop() 15 | fantasyName: string; 16 | 17 | @Prop() 18 | mainContact: string; 19 | 20 | @Prop() 21 | telephone: string; 22 | 23 | @Prop() 24 | completeName: string; 25 | 26 | @Prop() 27 | email: string; 28 | 29 | @Prop() 30 | password: string; 31 | 32 | @Prop() 33 | cellphone: string; 34 | } 35 | 36 | export const SupplierSchema = SchemaFactory.createForClass(Supplier); 37 | -------------------------------------------------------------------------------- /test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { INestApplication } from '@nestjs/common'; 3 | import * as request from 'supertest'; 4 | import { AppModule } from './../src/app.module'; 5 | 6 | describe('AppController (e2e)', () => { 7 | let app: INestApplication; 8 | 9 | beforeEach(async () => { 10 | const moduleFixture: TestingModule = await Test.createTestingModule({ 11 | imports: [AppModule], 12 | }).compile(); 13 | 14 | app = moduleFixture.createNestApplication(); 15 | await app.init(); 16 | }); 17 | 18 | it('/ (GET)', () => { 19 | return request(app.getHttpServer()) 20 | .get('/') 21 | .expect(200) 22 | .expect('Hello World!'); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /src/user/dto/create-user.dto.ts: -------------------------------------------------------------------------------- 1 | export interface User { 2 | completeName: string; 3 | gender: string; 4 | birthday: string; 5 | CPF: string; 6 | telephone: string; 7 | email: string; 8 | password: string; 9 | } 10 | 11 | export class CreateUserDto { 12 | completeName: string; 13 | gender: string; 14 | birthday: string; 15 | CPF: string; 16 | telephone: string; 17 | email: string; 18 | password: string; 19 | 20 | constructor({ 21 | completeName, 22 | CPF, 23 | gender, 24 | birthday, 25 | telephone, 26 | email, 27 | password, 28 | }: User) { 29 | this.completeName = completeName; 30 | this.CPF = CPF; 31 | this.gender = gender; 32 | this.birthday = birthday; 33 | this.telephone = telephone; 34 | this.email = email; 35 | this.password = password; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/products/products.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { Product } from './entities/product.entity'; 3 | import { ProductsService } from './products.service'; 4 | 5 | describe('ProductsService', () => { 6 | let service: ProductsService; 7 | 8 | beforeEach(async () => { 9 | const module: TestingModule = await Test.createTestingModule({ 10 | providers: [ProductsService], 11 | }).compile(); 12 | 13 | service = module.get(ProductsService); 14 | }); 15 | 16 | describe('find', () => { 17 | 18 | // it('should return an array of products', async () => { 19 | // let result: Array; 20 | // jest.spyOn(service, 'findAll').mockImplementation(() => result); 21 | 22 | // expect(await catsController.findAll()).toBe(result); 23 | // }); 24 | }) 25 | 26 | 27 | it('should be defined', () => { 28 | expect(service).toBeDefined(); 29 | }); 30 | }); 31 | -------------------------------------------------------------------------------- /src/supplier/dto/create-supplier.dto.ts: -------------------------------------------------------------------------------- 1 | export interface Supplier { 2 | CNPJ: string; 3 | corporateName: string; 4 | fantasyName: string; 5 | telephone: string; 6 | completeName: string; 7 | email: string; 8 | cellphone: string; 9 | password: string; 10 | } 11 | 12 | export class CreateSupplierDto { 13 | CNPJ: string; 14 | cellphone: string; 15 | completeName: string; 16 | corporateName: string; 17 | email: string; 18 | fantasyName: string; 19 | password: string; 20 | telephone: string; 21 | 22 | constructor({ 23 | CNPJ, 24 | cellphone, 25 | completeName, 26 | corporateName, 27 | email, 28 | fantasyName, 29 | password, 30 | telephone, 31 | }: Supplier) { 32 | this.CNPJ = CNPJ; 33 | this.cellphone = cellphone; 34 | this.completeName = completeName; 35 | this.corporateName = corporateName; 36 | this.email = email; 37 | this.fantasyName = fantasyName; 38 | this.password = password; 39 | this.telephone = telephone; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/user/user.controller.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Controller, 3 | Get, 4 | Post, 5 | Body, 6 | Patch, 7 | Param, 8 | Delete, 9 | } from '@nestjs/common'; 10 | import { UserService } from './user.service'; 11 | import { CreateUserDto } from './dto/create-user.dto'; 12 | import { UpdateUserDto } from './dto/update-user.dto'; 13 | 14 | @Controller('user') 15 | export class UserController { 16 | constructor(private readonly userService: UserService) {} 17 | 18 | @Post() 19 | create(@Body() createUserDto: CreateUserDto) { 20 | return this.userService.create(createUserDto); 21 | } 22 | 23 | @Get() 24 | findAll() { 25 | return this.userService.findAll(); 26 | } 27 | 28 | @Get(':id') 29 | findOne(@Param('id') id: string) { 30 | return this.userService.findOne(id); 31 | } 32 | 33 | @Patch(':id') 34 | update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) { 35 | return this.userService.update(id, updateUserDto); 36 | } 37 | 38 | @Delete(':id') 39 | remove(@Param('id') id: string) { 40 | return this.userService.remove(id); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/products/products.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; 2 | import { ProductsService } from './products.service'; 3 | import { CreateProductDto } from './dto/product/create-product.dto'; 4 | import { UpdateProductDto } from './dto/product/update-product.dto'; 5 | 6 | @Controller('products') 7 | export class ProductsController { 8 | constructor(private readonly productsService: ProductsService) {} 9 | 10 | @Post() 11 | create(@Body() createProductDto: CreateProductDto) { 12 | return this.productsService.create(createProductDto); 13 | } 14 | 15 | @Get() 16 | findAll() { 17 | return this.productsService.findAll(); 18 | } 19 | 20 | @Get(':id') 21 | findOne(@Param('id') id: string) { 22 | return this.productsService.findOne(id); 23 | } 24 | 25 | @Patch(':id') 26 | update(@Param('id') id: string, @Body() updateProductDto: UpdateProductDto) { 27 | return this.productsService.update(id, updateProductDto); 28 | } 29 | 30 | @Delete(':id') 31 | remove(@Param('id') id: string) { 32 | return this.productsService.remove(id); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/user/user.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { InjectModel } from '@nestjs/mongoose'; 3 | import { Model } from 'mongoose'; 4 | import { CreateUserDto } from './dto/create-user.dto'; 5 | import { UpdateUserDto } from './dto/update-user.dto'; 6 | import { User, UserDocument } from './entities/user.entity'; 7 | 8 | @Injectable() 9 | export class UserService { 10 | constructor(@InjectModel(User.name) private userModel: Model) {} 11 | 12 | create(createUserDto: CreateUserDto) { 13 | const user = new this.userModel(createUserDto); 14 | return user.save(); 15 | } 16 | 17 | findAll() { 18 | return this.userModel.find(); 19 | } 20 | 21 | findOne(id: string) { 22 | return this.userModel.findById(id); 23 | } 24 | 25 | update(id: string, updateUserDto: UpdateUserDto) { 26 | return this.userModel.findByIdAndUpdate( 27 | { 28 | _id: id, 29 | }, 30 | { 31 | $set: updateUserDto, 32 | }, 33 | { 34 | new: true, 35 | }, 36 | ); 37 | } 38 | 39 | remove(id: string) { 40 | return this.userModel.deleteOne({ 41 | _id: id, 42 | }); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/supplier/supplier.controller.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Controller, 3 | Get, 4 | Post, 5 | Body, 6 | Patch, 7 | Param, 8 | Delete, 9 | } from '@nestjs/common'; 10 | import { SupplierService } from './supplier.service'; 11 | import { CreateSupplierDto } from './dto/create-supplier.dto'; 12 | import { UpdateSupplierDto } from './dto/update-supplier.dto'; 13 | 14 | @Controller('supplier') 15 | export class SupplierController { 16 | constructor(private readonly supplierService: SupplierService) {} 17 | 18 | @Post() 19 | create(@Body() createSupplierDto: CreateSupplierDto) { 20 | return this.supplierService.create(createSupplierDto); 21 | } 22 | 23 | @Get() 24 | findAll() { 25 | return this.supplierService.findAll(); 26 | } 27 | 28 | @Get(':id') 29 | findOne(@Param('id') id: string) { 30 | return this.supplierService.findOne(id); 31 | } 32 | 33 | @Patch(':id') 34 | update( 35 | @Param('id') id: string, 36 | @Body() updateSupplierDto: UpdateSupplierDto, 37 | ) { 38 | return this.supplierService.update(id, updateSupplierDto); 39 | } 40 | 41 | @Delete(':id') 42 | remove(@Param('id') id: string) { 43 | return this.supplierService.remove(id); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/products/products.service.ts: -------------------------------------------------------------------------------- 1 | import { Product, ProductDocument } from './entities/product.entity'; 2 | import { Injectable } from '@nestjs/common'; 3 | import { InjectModel } from '@nestjs/mongoose'; 4 | import { CreateProductDto } from './dto/product/create-product.dto'; 5 | import { UpdateProductDto } from './dto/product/update-product.dto'; 6 | import { Model } from 'mongoose'; 7 | 8 | @Injectable() 9 | export class ProductsService { 10 | 11 | constructor(@InjectModel(Product.name) private productModel: Model) { } 12 | 13 | create(createProductDto: CreateProductDto) { 14 | const product = new this.productModel(createProductDto); 15 | return product.save(); 16 | } 17 | 18 | findAll() { 19 | return this.productModel.find(); 20 | } 21 | 22 | findOne(id: string) { 23 | return this.productModel.findById(id); 24 | } 25 | 26 | update(id: string, updateProductDto: UpdateProductDto) { 27 | return this.productModel.findByIdAndUpdate({ 28 | _id: id 29 | }, { 30 | $set: updateProductDto 31 | }, 32 | { 33 | new: true 34 | }); 35 | } 36 | 37 | remove(id: string) { 38 | return this.productModel.deleteOne({ 39 | _id: id 40 | }); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/supplier/supplier.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { InjectModel } from '@nestjs/mongoose'; 3 | import { Model } from 'mongoose'; 4 | import { CreateSupplierDto } from './dto/create-supplier.dto'; 5 | import { UpdateSupplierDto } from './dto/update-supplier.dto'; 6 | import { Supplier, SupplierDocument } from './entities/supplier.entity'; 7 | 8 | @Injectable() 9 | export class SupplierService { 10 | constructor( 11 | @InjectModel(Supplier.name) private supplierModel: Model, 12 | ) {} 13 | 14 | create(createSupplierDto: CreateSupplierDto) { 15 | const supplier = new this.supplierModel(createSupplierDto); 16 | return supplier.save(); 17 | } 18 | 19 | findAll() { 20 | return this.supplierModel.find(); 21 | } 22 | 23 | findOne(id: string) { 24 | return this.supplierModel.findById(id); 25 | } 26 | 27 | update(id: string, updateSupplierDto: UpdateSupplierDto) { 28 | return this.supplierModel.findByIdAndUpdate( 29 | { 30 | _id: id, 31 | }, 32 | { 33 | $set: updateSupplierDto, 34 | }, 35 | { 36 | new: true, 37 | }, 38 | ); 39 | } 40 | 41 | remove(id: string) { 42 | return this.supplierModel.deleteOne({ 43 | _id: id, 44 | }); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Buysilia 2 | 3 | > Nova aplicação se baseando em um [projeto](https://github.com/Felipe-Streva/Buysilia) que participei em 2020. 4 | 5 | 6 | ## Inicialização do projeto 7 | 8 | No terminal digite o comando `npm install` para baixar as dependências desse projeto. Depois do download, use o comando `npm run start:dev` para iniciar. 9 | 10 | 11 | ## Buysilia é um e-commerce que vende: 12 | 13 | 1. eletrônicos 14 | - celulares 15 | - computadores 16 | - kindle 17 | 2. livros 18 | - ficção científica 19 | - romance 20 | - desenvolvimento pessoal 21 | 22 | ## Cliente 23 | 24 | - O cliente pode visualizar o produto logado ou não. 25 | 26 | - O cliente pode comprar o produto se estiver logado; 27 | 28 | - O cliente pode adicionar o produto em um carrinho de compra 29 | 30 | - O cliente pode remover o item do carrinho de compra 31 | 32 | - Para cadastrar o cliente será necessário os dados: 33 | 34 | - nome completo 35 | - gênero 36 | - data de nascimento 37 | - CPF 38 | - telefone 39 | - e-mail 40 | - senha 41 | 42 | ## Fornecedor 43 | 44 | - O cliente pode visualizar o produto logado ou não. 45 | - O fornecedor pode cadastrar o produto se estiver logado 46 | - O fornecedor pode excluir o produto se estiver logado. 47 | - Para cadastrar o fornecedor será necessário os dados: 48 | 49 | - cnpj 50 | - razão social 51 | - nome fantasia 52 | - contato principal 53 | - telefone 54 | - nome completo 55 | - email 56 | - celular 57 | - senha 58 | 59 | ## Tecnologias 60 | 61 | - NestJS com Typescript 62 | - Mongoose 63 | - Jest 64 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "buysilia-backend", 3 | "version": "0.0.1", 4 | "description": "", 5 | "author": "", 6 | "private": true, 7 | "license": "UNLICENSED", 8 | "scripts": { 9 | "prebuild": "rimraf dist", 10 | "build": "nest build", 11 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 12 | "start": "nest start", 13 | "start:dev": "nest start --watch", 14 | "start:debug": "nest start --debug --watch", 15 | "start:prod": "node dist/main", 16 | "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", 17 | "test": "jest", 18 | "test:watch": "jest --watch", 19 | "test:cov": "jest --coverage", 20 | "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", 21 | "test:e2e": "jest --config ./test/jest-e2e.json" 22 | }, 23 | "dependencies": { 24 | "@nestjs/common": "^8.0.0", 25 | "@nestjs/config": "^2.0.0", 26 | "@nestjs/core": "^8.0.0", 27 | "@nestjs/mapped-types": "*", 28 | "@nestjs/mongoose": "^9.0.2", 29 | "@nestjs/platform-express": "^8.0.0", 30 | "mongoose": "^6.1.7", 31 | "reflect-metadata": "^0.1.13", 32 | "rimraf": "^3.0.2", 33 | "rxjs": "^7.2.0" 34 | }, 35 | "devDependencies": { 36 | "@nestjs/cli": "^8.0.0", 37 | "@nestjs/schematics": "^8.0.0", 38 | "@nestjs/testing": "^8.0.0", 39 | "@types/express": "^4.17.13", 40 | "@types/jest": "27.0.2", 41 | "@types/node": "^16.0.0", 42 | "@types/supertest": "^2.0.11", 43 | "@typescript-eslint/eslint-plugin": "^5.0.0", 44 | "@typescript-eslint/parser": "^5.0.0", 45 | "eslint": "^8.0.1", 46 | "eslint-config-prettier": "^8.3.0", 47 | "eslint-plugin-prettier": "^4.0.0", 48 | "jest": "^27.2.5", 49 | "prettier": "^2.3.2", 50 | "source-map-support": "^0.5.20", 51 | "supertest": "^6.1.3", 52 | "ts-jest": "^27.0.3", 53 | "ts-loader": "^9.2.3", 54 | "ts-node": "^10.0.0", 55 | "tsconfig-paths": "^3.10.1", 56 | "typescript": "^4.3.5" 57 | }, 58 | "jest": { 59 | "moduleFileExtensions": [ 60 | "js", 61 | "json", 62 | "ts" 63 | ], 64 | "rootDir": "src", 65 | "testRegex": ".*\\.spec\\.ts$", 66 | "transform": { 67 | "^.+\\.(t|j)s$": "ts-jest" 68 | }, 69 | "collectCoverageFrom": [ 70 | "**/*.(t|j)s" 71 | ], 72 | "coverageDirectory": "../coverage", 73 | "testEnvironment": "node" 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Insomnia.json: -------------------------------------------------------------------------------- 1 | {"_type":"export","__export_format":4,"__export_date":"2022-04-14T23:18:18.053Z","__export_source":"insomnia.desktop.app:v2022.2.1","resources":[{"_id":"req_dfcf8917d29a4de6ac6ca0f0f9c75996","parentId":"fld_02130903a0ea4acebddb620048c4bffd","modified":1648514698321,"created":1648514691020,"url":"{{ _.base_url }}/products","name":"Products","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1648514691020,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_02130903a0ea4acebddb620048c4bffd","parentId":"wrk_db1511c08bb84a9a82880906b40a1123","modified":1649977845339,"created":1648514683368,"name":"Products","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1649972669884,"_type":"request_group"},{"_id":"wrk_db1511c08bb84a9a82880906b40a1123","parentId":null,"modified":1648513009188,"created":1648513009188,"name":"Buysilia","description":"","scope":"collection","_type":"workspace"},{"_id":"req_b1de1f8b7bf64d2ab0a379bd61de3b0c","parentId":"fld_02130903a0ea4acebddb620048c4bffd","modified":1649977858686,"created":1649974757153,"url":"{{ _.base_url }}/products","name":"Post Products","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n\t\"description\": \"Notebook i7 10º geração\",\n \"name\": \"Lenovo Ideapad S145\",\n \"price\": 5000,\n \"quantity\": 50\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json","id":"pair_b49ac4b0935a4795bf869bc80b1fba55"}],"authentication":{},"metaSortKey":-1648514690995,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_1ebdd87e65c64b2aaa8d88c079831512","parentId":"fld_02130903a0ea4acebddb620048c4bffd","modified":1649974777800,"created":1649974749005,"url":"{{ _.base_url }}/products/{{ _.id }}","name":"Delete Products","description":"","method":"DELETE","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1648514690970,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_b449b8b9b4df451582ce775e45499f00","parentId":"fld_8756b2df37a74208b3ada24ab9078983","modified":1649976208046,"created":1649976185171,"url":"{{ _.base_url }}/user","name":"Get User","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1649973617743,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_8756b2df37a74208b3ada24ab9078983","parentId":"wrk_db1511c08bb84a9a82880906b40a1123","modified":1649977852072,"created":1649976185161,"name":"User","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1649972669859,"_type":"request_group"},{"_id":"req_af4796d1796544958f725ae950f6e656","parentId":"fld_8756b2df37a74208b3ada24ab9078983","modified":1649977825834,"created":1649976185182,"url":"{{ _.base_url }}/user","name":"Post User","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n\t\"completeName\": \"Nedal Siemaogi\",\n \"gender\": \"male\",\n \"birthday\": \"30/07/2000\",\n \"CPF\": \"964.380.920-02\",\n \"telephone\": \"471944923955\",\n \"email\": \"nedal@email.com\",\n \"password\": \"password\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json","id":"pair_b49ac4b0935a4795bf869bc80b1fba55"}],"authentication":{},"metaSortKey":-1649973617718,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_5d9de1ee4abe4648a690b85cda9fcfb2","parentId":"fld_8756b2df37a74208b3ada24ab9078983","modified":1649976204025,"created":1649976185186,"url":"{{ _.base_url }}/user/{{ _.id }}","name":"Delete User","description":"","method":"DELETE","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1649973617693,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_00d481628a71460cac740a92f063be96","parentId":"fld_8f26fbc937a440f7b34b7fd952e56cd1","modified":1649974726938,"created":1649972673409,"url":"{{ _.base_url }}/supplier","name":"Get Supplier","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1649973617743,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_8f26fbc937a440f7b34b7fd952e56cd1","parentId":"wrk_db1511c08bb84a9a82880906b40a1123","modified":1649972669834,"created":1649972669834,"name":"Supplier","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1649972669834,"_type":"request_group"},{"_id":"req_dd1033e9a080403abe848a7a1c41f74f","parentId":"fld_8f26fbc937a440f7b34b7fd952e56cd1","modified":1649974752461,"created":1649972958452,"url":"{{ _.base_url }}/supplier","name":"Post Supplier","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n\t\"CNPJ\": \"98.301.268/0001-68\",\n \"cellphone\": \"(12) 99649-6613\",\n \"completeName\": \"Giovana Ferragens\",\n \"corporateName\": \"Giovana e Diogo Ferragens ME\",\n \"email\":\"fabricacao@giovanaediogoferragensme.com.br\",\n \"fantasyName\": \"Giovana e Diogo Ferragens ME\",\n \"password\": \"password\",\n \"telephone\": \"(12) 99649-6613\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json","id":"pair_b49ac4b0935a4795bf869bc80b1fba55"}],"authentication":{},"metaSortKey":-1649973617718,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_f03d132dc0804d18b7e9193341f779ff","parentId":"fld_8f26fbc937a440f7b34b7fd952e56cd1","modified":1649974739763,"created":1649973617693,"url":"{{ _.base_url }}/supplier/{{ _.id }}","name":"Delete Supplier","description":"","method":"DELETE","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1649973617693,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"env_235b8bf0f5f1cb479f491ac215a5b8a475ada5ed","parentId":"wrk_db1511c08bb84a9a82880906b40a1123","modified":1649977866676,"created":1648513009207,"name":"Base Environment","data":{"base_url":"http://localhost:3000","id":"62589824c027a28a962a32e0"},"dataPropertyOrder":{"&":["base_url","id"]},"color":null,"isPrivate":false,"metaSortKey":1648513009207,"_type":"environment"},{"_id":"jar_235b8bf0f5f1cb479f491ac215a5b8a475ada5ed","parentId":"wrk_db1511c08bb84a9a82880906b40a1123","modified":1648513009208,"created":1648513009208,"name":"Default Jar","cookies":[],"_type":"cookie_jar"},{"_id":"spc_8bc6a6c31c7a4a13b11adb77d8853af9","parentId":"wrk_db1511c08bb84a9a82880906b40a1123","modified":1648513009201,"created":1648513009201,"fileName":"Buysilia","contents":"","contentType":"yaml","_type":"api_spec"}]} --------------------------------------------------------------------------------