Merge branch 'development' into 'devops-staging'
add: member by superrior See merge request empatnusabangsa/ppob/ppob-backend!7
This commit is contained in:
		| @@ -2,17 +2,15 @@ import { | ||||
|   Entity, | ||||
|   Column, | ||||
|   PrimaryGeneratedColumn, | ||||
|   UpdateDateColumn, | ||||
|   DeleteDateColumn, | ||||
|   VersionColumn, | ||||
|   CreateDateColumn, | ||||
|   ManyToOne, | ||||
|   OneToMany, | ||||
| } from 'typeorm'; | ||||
| import { ProductCategories } from './product-category.entity'; | ||||
| import { BaseModel } from '../../config/basemodel.entity'; | ||||
| import { Product } from './product.entity'; | ||||
|  | ||||
| @Entity() | ||||
| export class ProductSubCategories extends BaseModel{ | ||||
| export class ProductSubCategories extends BaseModel { | ||||
|   @PrimaryGeneratedColumn('uuid') | ||||
|   id: string; | ||||
|  | ||||
| @@ -21,4 +19,7 @@ export class ProductSubCategories extends BaseModel{ | ||||
|  | ||||
|   @ManyToOne(() => ProductCategories, (categories) => categories.subCategories) | ||||
|   category: ProductCategories; | ||||
|  | ||||
|   @OneToMany(() => Product, (product) => product.subCategories) | ||||
|   product: Product; | ||||
| } | ||||
|   | ||||
| @@ -13,7 +13,7 @@ import { ProductSubCategories } from './product-sub-category.entity'; | ||||
| import { BaseModel } from '../../config/basemodel.entity'; | ||||
|  | ||||
| @Entity() | ||||
| export class Product extends BaseModel{ | ||||
| export class Product extends BaseModel { | ||||
|   @PrimaryGeneratedColumn('uuid') | ||||
|   id: string; | ||||
|  | ||||
| @@ -30,13 +30,17 @@ export class Product extends BaseModel{ | ||||
|   price: number; | ||||
|  | ||||
|   @Column({ | ||||
|     nullable:true | ||||
|     nullable: true, | ||||
|   }) | ||||
|   basePrice: number; | ||||
|  | ||||
|   @ManyToOne( | ||||
|     () => ProductSubCategories, | ||||
|     (subCategories) => subCategories.category, | ||||
|     () => { | ||||
|       return ProductSubCategories; | ||||
|     }, | ||||
|     (subCategories) => { | ||||
|       return subCategories.product; | ||||
|     }, | ||||
|   ) | ||||
|   subCategories: ProductSubCategories; | ||||
| } | ||||
|   | ||||
| @@ -55,8 +55,9 @@ export class ProductService { | ||||
|  | ||||
|   findAllByCategories(page, categories) { | ||||
|     return this.productRepository.findAndCount({ | ||||
|       where: { | ||||
|         subCategories: categories, | ||||
|       join: { | ||||
|         alias: 'subCategories', | ||||
|         innerJoin: { subCategories: 'roles.users' }, | ||||
|       }, | ||||
|       skip: page * 10, | ||||
|       take: 10, | ||||
| @@ -130,7 +131,7 @@ export class ProductService { | ||||
|       endDate: updatePriceProductDto.endDate, | ||||
|     }); | ||||
|  | ||||
|     return | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
|   async remove(id: string) { | ||||
|   | ||||
| @@ -1,9 +1,5 @@ | ||||
| import { Roles } from 'src/configurable/entities/roles.entity'; | ||||
| import { | ||||
|   Entity, | ||||
|   Column, | ||||
|   PrimaryGeneratedColumn, ManyToOne, | ||||
| } from 'typeorm'; | ||||
| import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm'; | ||||
| import { BaseModel } from '../../config/basemodel.entity'; | ||||
| import { hashPassword } from '../../helper/hash_password'; | ||||
|  | ||||
| @@ -33,7 +29,7 @@ export class User extends BaseModel { | ||||
|     }, | ||||
|   ) | ||||
|   superior: User; | ||||
|    | ||||
|  | ||||
|   @ManyToOne( | ||||
|     () => { | ||||
|       return Roles; | ||||
|   | ||||
| @@ -9,12 +9,12 @@ import { | ||||
|   ParseUUIDPipe, | ||||
|   HttpStatus, | ||||
|   Query, | ||||
|   Request | ||||
|   Request, | ||||
| } from '@nestjs/common'; | ||||
| import { UsersService } from './users.service'; | ||||
| import { CreateUserDto } from './dto/create-user.dto'; | ||||
| import { UpdateUserDto } from './dto/update-user.dto'; | ||||
| import {Public} from "../auth/public.decorator"; | ||||
| import { Public } from '../auth/public.decorator'; | ||||
|  | ||||
| @Controller({ | ||||
|   path: 'users', | ||||
| @@ -24,12 +24,9 @@ export class UsersController { | ||||
|   constructor(private readonly usersService: UsersService) {} | ||||
|  | ||||
|   @Post() | ||||
|   async create( | ||||
|     @Request() req, | ||||
|     @Body() createUserDto: CreateUserDto | ||||
|   ) { | ||||
|   async create(@Request() req, @Body() createUserDto: CreateUserDto) { | ||||
|     return { | ||||
|       data: await this.usersService.create(createUserDto,req.user), | ||||
|       data: await this.usersService.create(createUserDto, req.user), | ||||
|       statusCode: HttpStatus.CREATED, | ||||
|       message: 'success', | ||||
|     }; | ||||
| @@ -48,13 +45,22 @@ export class UsersController { | ||||
|     }; | ||||
|   } | ||||
|  | ||||
|   @Get('find-by-supperior') | ||||
|   async findBySuperrior(@Request() req, @Query('page') page: number) { | ||||
|     return { | ||||
|       data: await this.usersService.findBySuperrior(req.user.id, page), | ||||
|       statusCode: HttpStatus.OK, | ||||
|       message: 'success', | ||||
|     }; | ||||
|   } | ||||
|  | ||||
|   @Get('find-by-roles/:id') | ||||
|   async findByRoles( | ||||
|       @Param('id', ParseUUIDPipe) id: string, | ||||
|       @Query('page') page: number | ||||
|       ) { | ||||
|     @Param('id', ParseUUIDPipe) id: string, | ||||
|     @Query('page') page: number, | ||||
|   ) { | ||||
|     return { | ||||
|       data: await this.usersService.findByRoles(id,page), | ||||
|       data: await this.usersService.findByRoles(id, page), | ||||
|       statusCode: HttpStatus.OK, | ||||
|       message: 'success', | ||||
|     }; | ||||
|   | ||||
| @@ -41,11 +41,11 @@ export class UsersService { | ||||
|     const userData = new User(); | ||||
|  | ||||
|     userData.id = uuid.v4(); | ||||
|     (userData.username = createUserDto.username), | ||||
|     (userData.password = await hashPassword(createUserDto.password, salt)), | ||||
|     (userData.salt = salt), | ||||
|     (userData.superior = superior), | ||||
|     (userData.roles = roles); | ||||
|     userData.username = createUserDto.username; | ||||
|     userData.password = await hashPassword(createUserDto.password, salt); | ||||
|     userData.salt = salt; | ||||
|     userData.superior = superior; | ||||
|     userData.roles = roles; | ||||
|  | ||||
|     await this.connection.transaction(async (manager) => { | ||||
|       const result = await manager.insert(User, userData); | ||||
| @@ -107,6 +107,20 @@ export class UsersService { | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   findBySuperrior(superriorId: string, page: number) { | ||||
|     return this.usersRepository.findAndCount({ | ||||
|       skip: page * 10, | ||||
|       take: 10, | ||||
|       where: { | ||||
|         superior: superriorId, | ||||
|       }, | ||||
|       relations: ['roles'], | ||||
|       order: { | ||||
|         updatedAt: 'DESC', | ||||
|       }, | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   async findExist(id: string) { | ||||
|     try { | ||||
|       return await this.usersRepository.findOneOrFail(id); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user