Browse Source

add entities and some cruds

entities
zarsa 2 years ago
parent
commit
8598f332ca
  1. 12
      src/entities/group.entity.ts
  2. 27
      src/entities/person.entity.ts
  3. 9
      src/entities/point-type.entity.ts
  4. 14
      src/entities/point.entity.ts
  5. 15
      src/entities/user.entity.ts
  6. 1
      src/groups/dto/create-group.dto.ts
  7. 4
      src/groups/dto/update-group.dto.ts
  8. 34
      src/groups/groups.controller.ts
  9. 9
      src/groups/groups.module.ts
  10. 26
      src/groups/groups.service.ts
  11. 1
      src/persons/dto/create-person.dto.ts
  12. 4
      src/persons/dto/update-person.dto.ts
  13. 34
      src/persons/persons.controller.ts
  14. 9
      src/persons/persons.module.ts
  15. 26
      src/persons/persons.service.ts
  16. 1
      src/users/dto/create-user.dto.ts
  17. 4
      src/users/dto/update-user.dto.ts
  18. 42
      src/users/users.controller.ts
  19. 9
      src/users/users.module.ts
  20. 26
      src/users/users.service.ts

12
src/entities/group.entity.ts

@ -0,0 +1,12 @@
import { Column, Entity, ManyToMany, PrimaryGeneratedColumn } from 'typeorm';
import { Person } from './person.entity';
@Entity()
export class Group {
@PrimaryGeneratedColumn()
id: number;
@Column('nvarchar')
name: string;
@ManyToMany(() => Person, (person) => person.groups)
persons: Person[];
}

27
src/entities/person.entity.ts

@ -0,0 +1,27 @@
import {
Column,
Entity,
JoinTable,
ManyToMany,
OneToMany,
PrimaryGeneratedColumn,
} from 'typeorm';
import { Point } from './point.entity';
import { Group } from './group.entity';
@Entity()
export class Person {
@PrimaryGeneratedColumn()
id: number;
@Column({ length: 25, type: 'nvarchar' })
firstName: string;
@Column({ length: 25, type: 'nvarchar' })
lastName: string;
@Column('int')
phoneNumber: number;
@OneToMany(() => Point, (point) => point.person)
points: Point[];
@ManyToMany(() => Group, (group) => group.persons)
@JoinTable()
groups: Group[];
}

9
src/entities/point-type.entity.ts

@ -0,0 +1,9 @@
import { Column, Entity, PrimaryColumn } from 'typeorm';
@Entity()
export class PointType {
@PrimaryColumn()
code: number;
@Column({ length: 25, type: 'nvarchar' })
name: string;
}

14
src/entities/point.entity.ts

@ -0,0 +1,14 @@
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { Person } from './person.entity';
@Entity()
export class Point {
@PrimaryGeneratedColumn()
id: number;
@Column('text')
desc: string;
@Column('int')
numOf: number;
@ManyToOne(() => Person, (person) => person.points)
person: Person;
}

15
src/entities/user.entity.ts

@ -0,0 +1,15 @@
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number;
@Column({ length: 25, type: 'nvarchar' })
firstName: string;
@Column({ length: 25, type: 'nvarchar' })
lastName: string;
@Column({ length: 25 })
username: string;
@Column({ length: 25 })
password: string;
}

1
src/groups/dto/create-group.dto.ts

@ -0,0 +1 @@
export class CreateGroupDto {}

4
src/groups/dto/update-group.dto.ts

@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateGroupDto } from './create-group.dto';
export class UpdateGroupDto extends PartialType(CreateGroupDto) {}

34
src/groups/groups.controller.ts

@ -0,0 +1,34 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { GroupsService } from './groups.service';
import { CreateGroupDto } from './dto/create-group.dto';
import { UpdateGroupDto } from './dto/update-group.dto';
@Controller('groups')
export class GroupsController {
constructor(private readonly groupsService: GroupsService) {}
@Post()
create(@Body() createGroupDto: CreateGroupDto) {
return this.groupsService.create(createGroupDto);
}
@Get()
findAll() {
return this.groupsService.findAll();
}
@Get(':id')
findOne(@Param('id') id: string) {
return this.groupsService.findOne(+id);
}
@Patch(':id')
update(@Param('id') id: string, @Body() updateGroupDto: UpdateGroupDto) {
return this.groupsService.update(+id, updateGroupDto);
}
@Delete(':id')
remove(@Param('id') id: string) {
return this.groupsService.remove(+id);
}
}

9
src/groups/groups.module.ts

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { GroupsService } from './groups.service';
import { GroupsController } from './groups.controller';
@Module({
controllers: [GroupsController],
providers: [GroupsService]
})
export class GroupsModule {}

26
src/groups/groups.service.ts

@ -0,0 +1,26 @@
import { Injectable } from '@nestjs/common';
import { CreateGroupDto } from './dto/create-group.dto';
import { UpdateGroupDto } from './dto/update-group.dto';
@Injectable()
export class GroupsService {
create(createGroupDto: CreateGroupDto) {
return 'This action adds a new group';
}
findAll() {
return `This action returns all groups`;
}
findOne(id: number) {
return `This action returns a #${id} group`;
}
update(id: number, updateGroupDto: UpdateGroupDto) {
return `This action updates a #${id} group`;
}
remove(id: number) {
return `This action removes a #${id} group`;
}
}

1
src/persons/dto/create-person.dto.ts

@ -0,0 +1 @@
export class CreatePersonDto {}

4
src/persons/dto/update-person.dto.ts

@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreatePersonDto } from './create-person.dto';
export class UpdatePersonDto extends PartialType(CreatePersonDto) {}

34
src/persons/persons.controller.ts

@ -0,0 +1,34 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { PersonsService } from './persons.service';
import { CreatePersonDto } from './dto/create-person.dto';
import { UpdatePersonDto } from './dto/update-person.dto';
@Controller('persons')
export class PersonsController {
constructor(private readonly personsService: PersonsService) {}
@Post()
create(@Body() createPersonDto: CreatePersonDto) {
return this.personsService.create(createPersonDto);
}
@Get()
findAll() {
return this.personsService.findAll();
}
@Get(':id')
findOne(@Param('id') id: string) {
return this.personsService.findOne(+id);
}
@Patch(':id')
update(@Param('id') id: string, @Body() updatePersonDto: UpdatePersonDto) {
return this.personsService.update(+id, updatePersonDto);
}
@Delete(':id')
remove(@Param('id') id: string) {
return this.personsService.remove(+id);
}
}

9
src/persons/persons.module.ts

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { PersonsService } from './persons.service';
import { PersonsController } from './persons.controller';
@Module({
controllers: [PersonsController],
providers: [PersonsService]
})
export class PersonsModule {}

26
src/persons/persons.service.ts

@ -0,0 +1,26 @@
import { Injectable } from '@nestjs/common';
import { CreatePersonDto } from './dto/create-person.dto';
import { UpdatePersonDto } from './dto/update-person.dto';
@Injectable()
export class PersonsService {
create(createPersonDto: CreatePersonDto) {
return 'This action adds a new person';
}
findAll() {
return `This action returns all persons`;
}
findOne(id: number) {
return `This action returns a #${id} person`;
}
update(id: number, updatePersonDto: UpdatePersonDto) {
return `This action updates a #${id} person`;
}
remove(id: number) {
return `This action removes a #${id} person`;
}
}

1
src/users/dto/create-user.dto.ts

@ -0,0 +1 @@
export class CreateUserDto {}

4
src/users/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) {}

42
src/users/users.controller.ts

@ -0,0 +1,42 @@
import {
Controller,
Get,
Post,
Body,
Patch,
Param,
Delete,
} from '@nestjs/common';
import { UsersService } from './users.service';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
@Controller('users')
export class UsersController {
constructor(private readonly usersService: UsersService) {}
@Post()
create(@Body() createUserDto: CreateUserDto) {
return this.usersService.create(createUserDto);
}
@Get()
findAll() {
return this.usersService.findAll();
}
@Get(':id')
findOne(@Param('id') id: string) {
return this.usersService.findOne(+id);
}
@Patch(':id')
update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
return this.usersService.update(+id, updateUserDto);
}
@Delete(':id')
remove(@Param('id') id: string) {
return this.usersService.remove(+id);
}
}

9
src/users/users.module.ts

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { UsersService } from './users.service';
import { UsersController } from './users.controller';
@Module({
controllers: [UsersController],
providers: [UsersService]
})
export class UsersModule {}

26
src/users/users.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 UsersService {
create(createUserDto: CreateUserDto) {
return 'This action adds a new user';
}
findAll() {
return `This action returns all users`;
}
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`;
}
}
Loading…
Cancel
Save