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