From bccd68e9a369a376a891865c626afc6a3521d9b7 Mon Sep 17 00:00:00 2001 From: Giovanna Esmeralda Chavez Espino <79319097+gio-gigi@users.noreply.github.com> Date: Tue, 23 Apr 2024 09:44:12 -0600 Subject: [PATCH] =?UTF-8?q?Creaci=C3=B3n=20de=20entidades=20usuario/=20adm?= =?UTF-8?q?in?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package-lock.json | 20 +++++++++++++ backend/package.json | 1 + backend/src/admin/admin.controller.spec.ts | 20 +++++++++++++ backend/src/admin/admin.controller.ts | 34 ++++++++++++++++++++++ backend/src/admin/admin.module.ts | 9 ++++++ backend/src/admin/admin.service.spec.ts | 18 ++++++++++++ backend/src/admin/admin.service.ts | 26 +++++++++++++++++ backend/src/admin/dto/create-admin.dto.ts | 1 + backend/src/admin/dto/update-admin.dto.ts | 4 +++ backend/src/admin/entities/admin.entity.ts | 15 ++++++++++ backend/src/app.controller.ts | 2 +- backend/src/app.module.ts | 12 ++++++-- backend/src/app.service.ts | 3 +- backend/src/user/dto/create-user.dto.ts | 1 + backend/src/user/dto/update-user.dto.ts | 4 +++ backend/src/user/entities/user.entity.ts | 22 ++++++++++++++ backend/src/user/user.controller.spec.ts | 20 +++++++++++++ backend/src/user/user.controller.ts | 34 ++++++++++++++++++++++ backend/src/user/user.module.ts | 9 ++++++ backend/src/user/user.service.spec.ts | 18 ++++++++++++ backend/src/user/user.service.ts | 26 +++++++++++++++++ 21 files changed, 294 insertions(+), 5 deletions(-) create mode 100644 backend/src/admin/admin.controller.spec.ts create mode 100644 backend/src/admin/admin.controller.ts create mode 100644 backend/src/admin/admin.module.ts create mode 100644 backend/src/admin/admin.service.spec.ts create mode 100644 backend/src/admin/admin.service.ts create mode 100644 backend/src/admin/dto/create-admin.dto.ts create mode 100644 backend/src/admin/dto/update-admin.dto.ts create mode 100644 backend/src/admin/entities/admin.entity.ts create mode 100644 backend/src/user/dto/create-user.dto.ts create mode 100644 backend/src/user/dto/update-user.dto.ts create mode 100644 backend/src/user/entities/user.entity.ts create mode 100644 backend/src/user/user.controller.spec.ts create mode 100644 backend/src/user/user.controller.ts create mode 100644 backend/src/user/user.module.ts create mode 100644 backend/src/user/user.service.spec.ts create mode 100644 backend/src/user/user.service.ts diff --git a/backend/package-lock.json b/backend/package-lock.json index 165a7bf..c32687d 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@nestjs/common": "^10.0.0", "@nestjs/core": "^10.0.0", + "@nestjs/mapped-types": "*", "@nestjs/platform-express": "^10.0.0", "@nestjs/typeorm": "^10.0.2", "dotenv": "^16.4.5", @@ -1793,6 +1794,25 @@ } } }, + "node_modules/@nestjs/mapped-types": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@nestjs/mapped-types/-/mapped-types-2.0.5.tgz", + "integrity": "sha512-bSJv4pd6EY99NX9CjBIyn4TVDoSit82DUZlL4I3bqNfy5Gt+gXTa86i3I/i0iIV9P4hntcGM5GyO+FhZAhxtyg==", + "peerDependencies": { + "@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0", + "class-transformer": "^0.4.0 || ^0.5.0", + "class-validator": "^0.13.0 || ^0.14.0", + "reflect-metadata": "^0.1.12 || ^0.2.0" + }, + "peerDependenciesMeta": { + "class-transformer": { + "optional": true + }, + "class-validator": { + "optional": true + } + } + }, "node_modules/@nestjs/platform-express": { "version": "10.3.7", "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-10.3.7.tgz", diff --git a/backend/package.json b/backend/package.json index 6d4af5b..4a3449a 100644 --- a/backend/package.json +++ b/backend/package.json @@ -22,6 +22,7 @@ "dependencies": { "@nestjs/common": "^10.0.0", "@nestjs/core": "^10.0.0", + "@nestjs/mapped-types": "*", "@nestjs/platform-express": "^10.0.0", "@nestjs/typeorm": "^10.0.2", "dotenv": "^16.4.5", diff --git a/backend/src/admin/admin.controller.spec.ts b/backend/src/admin/admin.controller.spec.ts new file mode 100644 index 0000000..714d356 --- /dev/null +++ b/backend/src/admin/admin.controller.spec.ts @@ -0,0 +1,20 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { AdminController } from './admin.controller'; +import { AdminService } from './admin.service'; + +describe('AdminController', () => { + let controller: AdminController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [AdminController], + providers: [AdminService], + }).compile(); + + controller = module.get(AdminController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/backend/src/admin/admin.controller.ts b/backend/src/admin/admin.controller.ts new file mode 100644 index 0000000..367bac5 --- /dev/null +++ b/backend/src/admin/admin.controller.ts @@ -0,0 +1,34 @@ +import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { AdminService } from './admin.service'; +import { CreateAdminDto } from './dto/create-admin.dto'; +import { UpdateAdminDto } from './dto/update-admin.dto'; + +@Controller('admin') +export class AdminController { + constructor(private readonly adminService: AdminService) {} + + @Post() + create(@Body() createAdminDto: CreateAdminDto) { + return this.adminService.create(createAdminDto); + } + + @Get() + findAll() { + return this.adminService.findAll(); + } + + @Get(':id') + findOne(@Param('id') id: string) { + return this.adminService.findOne(+id); + } + + @Patch(':id') + update(@Param('id') id: string, @Body() updateAdminDto: UpdateAdminDto) { + return this.adminService.update(+id, updateAdminDto); + } + + @Delete(':id') + remove(@Param('id') id: string) { + return this.adminService.remove(+id); + } +} diff --git a/backend/src/admin/admin.module.ts b/backend/src/admin/admin.module.ts new file mode 100644 index 0000000..2926ee8 --- /dev/null +++ b/backend/src/admin/admin.module.ts @@ -0,0 +1,9 @@ +import { Module } from '@nestjs/common'; +import { AdminService } from './admin.service'; +import { AdminController } from './admin.controller'; + +@Module({ + controllers: [AdminController], + providers: [AdminService], +}) +export class AdminModule {} diff --git a/backend/src/admin/admin.service.spec.ts b/backend/src/admin/admin.service.spec.ts new file mode 100644 index 0000000..5e5e153 --- /dev/null +++ b/backend/src/admin/admin.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { AdminService } from './admin.service'; + +describe('AdminService', () => { + let service: AdminService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [AdminService], + }).compile(); + + service = module.get(AdminService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/backend/src/admin/admin.service.ts b/backend/src/admin/admin.service.ts new file mode 100644 index 0000000..f4dbcf1 --- /dev/null +++ b/backend/src/admin/admin.service.ts @@ -0,0 +1,26 @@ +import { Injectable } from '@nestjs/common'; +import { CreateAdminDto } from './dto/create-admin.dto'; +import { UpdateAdminDto } from './dto/update-admin.dto'; + +@Injectable() +export class AdminService { + create(createAdminDto: CreateAdminDto) { + return 'This action adds a new admin'; + } + + findAll() { + return `This action returns all admin`; + } + + findOne(id: number) { + return `This action returns a #${id} admin`; + } + + update(id: number, updateAdminDto: UpdateAdminDto) { + return `This action updates a #${id} admin`; + } + + remove(id: number) { + return `This action removes a #${id} admin`; + } +} diff --git a/backend/src/admin/dto/create-admin.dto.ts b/backend/src/admin/dto/create-admin.dto.ts new file mode 100644 index 0000000..233a7df --- /dev/null +++ b/backend/src/admin/dto/create-admin.dto.ts @@ -0,0 +1 @@ +export class CreateAdminDto {} diff --git a/backend/src/admin/dto/update-admin.dto.ts b/backend/src/admin/dto/update-admin.dto.ts new file mode 100644 index 0000000..74613de --- /dev/null +++ b/backend/src/admin/dto/update-admin.dto.ts @@ -0,0 +1,4 @@ +import { PartialType } from '@nestjs/mapped-types'; +import { CreateAdminDto } from './create-admin.dto'; + +export class UpdateAdminDto extends PartialType(CreateAdminDto) {} diff --git a/backend/src/admin/entities/admin.entity.ts b/backend/src/admin/entities/admin.entity.ts new file mode 100644 index 0000000..9f47fe0 --- /dev/null +++ b/backend/src/admin/entities/admin.entity.ts @@ -0,0 +1,15 @@ +import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; +@Entity() +export class Admin { + @PrimaryGeneratedColumn() + id: number + + @Column() + name: string + + @Column() + email: string + + @Column() + password: string +} diff --git a/backend/src/app.controller.ts b/backend/src/app.controller.ts index cce879e..1739a15 100644 --- a/backend/src/app.controller.ts +++ b/backend/src/app.controller.ts @@ -5,7 +5,7 @@ import { AppService } from './app.service'; export class AppController { constructor(private readonly appService: AppService) {} - @Get() + @Get()//decorador getHello(): string { return this.appService.getHello(); } diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index abee43c..ed8a642 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -2,7 +2,11 @@ import { Module } from '@nestjs/common'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { TypeOrmModule } from '@nestjs/typeorm'; +import { AdminModule } from './admin/admin.module'; +import { UserModule } from './user/user.module'; import * as dotenv from 'dotenv'; +import { Admin } from './admin/entities/admin.entity'; +import { User } from './user/entities/user.entity'; dotenv.config() @Module({ imports: [ @@ -13,11 +17,13 @@ dotenv.config() username: process.env.DATABASE_USER, password: process.env.DATABASE_PASSWORD, database: process.env.DATABASE_NAME, - entities: [], + entities: [Admin, User], synchronize: true, }), + AdminModule, + UserModule, ], - controllers: [AppController], - providers: [AppService], + controllers: [AppController], //rutas + providers: [AppService], //funciones para comunicarse en la bd }) export class AppModule {} diff --git a/backend/src/app.service.ts b/backend/src/app.service.ts index 927d7cc..137a42f 100644 --- a/backend/src/app.service.ts +++ b/backend/src/app.service.ts @@ -3,6 +3,7 @@ import { Injectable } from '@nestjs/common'; @Injectable() export class AppService { getHello(): string { - return 'Hello World!'; + return 'Adios'; } + } diff --git a/backend/src/user/dto/create-user.dto.ts b/backend/src/user/dto/create-user.dto.ts new file mode 100644 index 0000000..0311be1 --- /dev/null +++ b/backend/src/user/dto/create-user.dto.ts @@ -0,0 +1 @@ +export class CreateUserDto {} diff --git a/backend/src/user/dto/update-user.dto.ts b/backend/src/user/dto/update-user.dto.ts new file mode 100644 index 0000000..dfd37fb --- /dev/null +++ b/backend/src/user/dto/update-user.dto.ts @@ -0,0 +1,4 @@ +import { PartialType } from '@nestjs/mapped-types'; +import { CreateUserDto } from './create-user.dto'; + +export class UpdateUserDto extends PartialType(CreateUserDto) {} diff --git a/backend/src/user/entities/user.entity.ts b/backend/src/user/entities/user.entity.ts new file mode 100644 index 0000000..4f58986 --- /dev/null +++ b/backend/src/user/entities/user.entity.ts @@ -0,0 +1,22 @@ +import { Column, Entity, PrimaryColumn } from "typeorm"; + +@Entity() +export class User { + @PrimaryColumn() + idUser: number + + @Column() + name: string + + @Column() + lastname: string + + @Column() + password: string + + @Column() + email: string + + @Column() + phone: number +} diff --git a/backend/src/user/user.controller.spec.ts b/backend/src/user/user.controller.spec.ts new file mode 100644 index 0000000..1f38440 --- /dev/null +++ b/backend/src/user/user.controller.spec.ts @@ -0,0 +1,20 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { UserController } from './user.controller'; +import { UserService } from './user.service'; + +describe('UserController', () => { + let controller: UserController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [UserController], + providers: [UserService], + }).compile(); + + controller = module.get(UserController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/backend/src/user/user.controller.ts b/backend/src/user/user.controller.ts new file mode 100644 index 0000000..995519c --- /dev/null +++ b/backend/src/user/user.controller.ts @@ -0,0 +1,34 @@ +import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { UserService } from './user.service'; +import { CreateUserDto } from './dto/create-user.dto'; +import { UpdateUserDto } from './dto/update-user.dto'; + +@Controller('user') +export class UserController { + constructor(private readonly userService: UserService) {} + + @Post() + create(@Body() createUserDto: CreateUserDto) { + return this.userService.create(createUserDto); + } + + @Get() + findAll() { + return this.userService.findAll(); + } + + @Get(':id') + findOne(@Param('id') id: string) { + return this.userService.findOne(+id); + } + + @Patch(':id') + update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) { + return this.userService.update(+id, updateUserDto); + } + + @Delete(':id') + remove(@Param('id') id: string) { + return this.userService.remove(+id); + } +} diff --git a/backend/src/user/user.module.ts b/backend/src/user/user.module.ts new file mode 100644 index 0000000..e21d51f --- /dev/null +++ b/backend/src/user/user.module.ts @@ -0,0 +1,9 @@ +import { Module } from '@nestjs/common'; +import { UserService } from './user.service'; +import { UserController } from './user.controller'; + +@Module({ + controllers: [UserController], + providers: [UserService], +}) +export class UserModule {} diff --git a/backend/src/user/user.service.spec.ts b/backend/src/user/user.service.spec.ts new file mode 100644 index 0000000..873de8a --- /dev/null +++ b/backend/src/user/user.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { UserService } from './user.service'; + +describe('UserService', () => { + let service: UserService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [UserService], + }).compile(); + + service = module.get(UserService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/backend/src/user/user.service.ts b/backend/src/user/user.service.ts new file mode 100644 index 0000000..95707d7 --- /dev/null +++ b/backend/src/user/user.service.ts @@ -0,0 +1,26 @@ +import { Injectable } from '@nestjs/common'; +import { CreateUserDto } from './dto/create-user.dto'; +import { UpdateUserDto } from './dto/update-user.dto'; + +@Injectable() +export class UserService { + create(createUserDto: CreateUserDto) { + return 'This action adds a new user'; + } + + findAll() { + return `This action returns all user`; + } + + findOne(id: number) { + return `This action returns a #${id} user`; + } + + update(id: number, updateUserDto: UpdateUserDto) { + return `This action updates a #${id} user`; + } + + remove(id: number) { + return `This action removes a #${id} user`; + } +} -- GitLab