fix: product create duplicated issue
This commit is contained in:
parent
2d71fdf001
commit
2df310b1c0
|
@ -57,7 +57,6 @@ export class ProductService {
|
||||||
keyword: `%${keyword}%`
|
keyword: `%${keyword}%`
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
return paginate<ProductEntity>(sqb, {
|
return paginate<ProductEntity>(sqb, {
|
||||||
page,
|
page,
|
||||||
|
@ -69,9 +68,9 @@ export class ProductService {
|
||||||
* 新增
|
* 新增
|
||||||
*/
|
*/
|
||||||
async create(dto: ProductDto): Promise<void> {
|
async create(dto: ProductDto): Promise<void> {
|
||||||
const { name, companyId } = dto;
|
const { name, companyId, productSpecification } = dto;
|
||||||
const isExsit = await this.productRepository.findOne({
|
const isExsit = await this.productRepository.findOne({
|
||||||
where: { name, company: { id: companyId } }
|
where: { productSpecification, name, company: { id: companyId } }
|
||||||
});
|
});
|
||||||
if (isExsit) {
|
if (isExsit) {
|
||||||
throw new BusinessException(ErrorEnum.PRODUCT_EXIST);
|
throw new BusinessException(ErrorEnum.PRODUCT_EXIST);
|
||||||
|
@ -86,6 +85,13 @@ export class ProductService {
|
||||||
*/
|
*/
|
||||||
async update(id: number, { fileIds, ...data }: Partial<ProductUpdateDto>): Promise<void> {
|
async update(id: number, { fileIds, ...data }: Partial<ProductUpdateDto>): Promise<void> {
|
||||||
await this.entityManager.transaction(async manager => {
|
await this.entityManager.transaction(async manager => {
|
||||||
|
const { name, companyId, productSpecification } = data;
|
||||||
|
const isExsit = await this.productRepository.findOne({
|
||||||
|
where: { productSpecification, name, company: { id: companyId } }
|
||||||
|
});
|
||||||
|
if (isExsit) {
|
||||||
|
throw new BusinessException(ErrorEnum.PRODUCT_EXIST);
|
||||||
|
}
|
||||||
await manager.update(
|
await manager.update(
|
||||||
ProductEntity,
|
ProductEntity,
|
||||||
id,
|
id,
|
||||||
|
|
|
@ -116,7 +116,6 @@ export class DeptService {
|
||||||
}
|
}
|
||||||
|
|
||||||
const deptTree = await this.deptRepository.findTrees({
|
const deptTree = await this.deptRepository.findTrees({
|
||||||
depth: 2,
|
|
||||||
relations: ['parent']
|
relations: ['parent']
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
|
import { ApiHideProperty } from '@nestjs/swagger';
|
||||||
import { Exclude } from 'class-transformer';
|
import { Exclude } from 'class-transformer';
|
||||||
|
import pinyin from 'pinyin';
|
||||||
import {
|
import {
|
||||||
|
BeforeInsert,
|
||||||
|
BeforeUpdate,
|
||||||
Column,
|
Column,
|
||||||
Entity,
|
Entity,
|
||||||
JoinColumn,
|
JoinColumn,
|
||||||
|
@ -32,6 +36,25 @@ export class UserEntity extends CommonEntity {
|
||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
nickname: string;
|
nickname: string;
|
||||||
|
|
||||||
|
@ApiHideProperty()
|
||||||
|
@Column({
|
||||||
|
name: 'name_pinyin',
|
||||||
|
type: 'varchar',
|
||||||
|
length: 255,
|
||||||
|
nullable: true,
|
||||||
|
comment: '产品名称的拼音'
|
||||||
|
})
|
||||||
|
namePinyin: string;
|
||||||
|
|
||||||
|
@BeforeInsert()
|
||||||
|
@BeforeUpdate()
|
||||||
|
updateNamePinyin() {
|
||||||
|
this.namePinyin = pinyin(this.nickname, {
|
||||||
|
style: pinyin.STYLE_NORMAL,
|
||||||
|
heteronym: false
|
||||||
|
}).join('');
|
||||||
|
}
|
||||||
|
|
||||||
@Column({ name: 'avatar', nullable: true })
|
@Column({ name: 'avatar', nullable: true })
|
||||||
avatar: string;
|
avatar: string;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import Redis from 'ioredis';
|
||||||
import { isEmpty, isNil, isNumber } from 'lodash';
|
import { isEmpty, isNil, isNumber } from 'lodash';
|
||||||
|
|
||||||
import { EntityManager, In, Like, Repository } from 'typeorm';
|
import { EntityManager, In, Like, Repository } from 'typeorm';
|
||||||
|
import pinyin from 'pinyin';
|
||||||
import { BusinessException } from '~/common/exceptions/biz.exception';
|
import { BusinessException } from '~/common/exceptions/biz.exception';
|
||||||
import { ErrorEnum } from '~/constants/error-code.constant';
|
import { ErrorEnum } from '~/constants/error-code.constant';
|
||||||
import { ROOT_ROLE_ID, SYS_USER_INITPASSWORD } from '~/constants/system.constant';
|
import { ROOT_ROLE_ID, SYS_USER_INITPASSWORD } from '~/constants/system.constant';
|
||||||
|
@ -268,7 +268,7 @@ export class UserService {
|
||||||
if (keyword) {
|
if (keyword) {
|
||||||
//关键字模糊查询product的name,productNumber,productSpecification
|
//关键字模糊查询product的name,productNumber,productSpecification
|
||||||
queryBuilder.andWhere(
|
queryBuilder.andWhere(
|
||||||
'(user.nickname like :keyword or dept.name like :keyword)',
|
'(user.nickname like :keyword or user.namePinyin like :keyword or dept.name like :keyword)',
|
||||||
{
|
{
|
||||||
keyword: `%${keyword}%`
|
keyword: `%${keyword}%`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue