add:product price

This commit is contained in:
ilham 2021-12-06 23:15:26 +07:00
parent f1594ebd96
commit 77db83490f
8 changed files with 80 additions and 36 deletions

View File

@ -50,10 +50,9 @@ import configuration from './config/configuration';
inject: [ConfigService], inject: [ConfigService],
}), }),
UsersModule, UsersModule,
// TransactionModule, TransactionModule,
// ConfigurableModule, ConfigurableModule,
// ProductModule, ProductModule,
AuthModule,
], ],
}) })
export class AppModule {} export class AppModule {}

View File

@ -13,17 +13,9 @@ import { AuthController } from './auth.controller';
property: 'user', property: 'user',
session: false, session: false,
}), }),
JwtModule.register({
secret: process.env.SECRETKEY, signOptions: {
expiresIn: process.env.EXPIRESIN,
},
}),
], ],
controllers: [AuthController], controllers: [AuthController],
providers: [AuthService, JwtStrategy], providers: [AuthService, JwtStrategy],
exports: [ exports: [PassportModule, JwtModule],
PassportModule,
JwtModule
],
}) })
export class AuthModule {} export class AuthModule {}

View File

@ -10,19 +10,19 @@ export class LocalStrategy extends PassportStrategy(Strategy) {
super(); super();
} }
async validate( // async validate(
username: string, // username: string,
password: string, // password: string,
): Promise<Omit<User, 'password'>> { // ): Promise<Omit<User, 'password'>> {
const user = await this.authService.validateUser({ // const user = await this.authService.validateUser({
username, // username,
password, // password,
}); // });
//
if (!user) { // if (!user) {
throw new UnauthorizedException(); // throw new UnauthorizedException();
} // }
//
return user; // return user;
} // }
} }

View File

@ -10,6 +10,9 @@ export class CreateProductDto {
@IsNotEmpty() @IsNotEmpty()
status: string; status: string;
@IsNotEmpty()
price: number;
@IsUUID() @IsUUID()
subCategoriesId: string; subCategoriesId: string;
} }

View File

@ -2,11 +2,6 @@ import {
Entity, Entity,
Column, Column,
PrimaryGeneratedColumn, PrimaryGeneratedColumn,
UpdateDateColumn,
DeleteDateColumn,
VersionColumn,
CreateDateColumn,
OneToMany,
ManyToOne, ManyToOne,
} from 'typeorm'; } from 'typeorm';
import { Product } from './product.entity'; import { Product } from './product.entity';
@ -23,13 +18,16 @@ export class ProductHistoryPrice extends BaseModel {
id: string; id: string;
@ManyToOne(() => Product, (product) => product.id) @ManyToOne(() => Product, (product) => product.id)
productId: string; product: Product;
@Column()
price: number;
@Column({ type: 'date' }) @Column({ type: 'date' })
startDate: string; startDate: Date;
@Column({ type: 'date' }) @Column({ type: 'date' })
endDate: string; endDate: Date;
@Column('text') @Column('text')
type: Type; type: Type;

View File

@ -26,6 +26,9 @@ export class Product extends BaseModel{
@Column() @Column()
status: string; status: string;
@Column()
price: number;
@ManyToOne( @ManyToOne(
() => ProductSubCategories, () => ProductSubCategories,
(subCategories) => subCategories.category, (subCategories) => subCategories.category,

View File

@ -5,11 +5,18 @@ import { InjectRepository } from '@nestjs/typeorm';
import { CreateProductDto } from '../product/dto/product/create-product.dto'; import { CreateProductDto } from '../product/dto/product/create-product.dto';
import { ProductSubCategoriesService } from './product-sub-categories.service'; import { ProductSubCategoriesService } from './product-sub-categories.service';
import { UpdateProductDto } from './dto/product/update-product.dto'; import { UpdateProductDto } from './dto/product/update-product.dto';
import { ProductHistoryPrice } from './entities/product-history-price.entity';
enum Type {
NORMAL,
PROMO,
}
export class ProductService { export class ProductService {
constructor( constructor(
@InjectRepository(Product) @InjectRepository(Product)
private productRepository: Repository<Product>, private productRepository: Repository<Product>,
private productHistoryPrice: Repository<ProductHistoryPrice>,
private productSubCategoriesService: ProductSubCategoriesService, private productSubCategoriesService: ProductSubCategoriesService,
) {} ) {}
@ -23,6 +30,14 @@ export class ProductService {
code: createProductDto.code, code: createProductDto.code,
status: createProductDto.status, status: createProductDto.status,
subCategories: subCategories, subCategories: subCategories,
price: createProductDto.price,
});
await this.productHistoryPrice.insert({
product: result.identifiers[0],
type: Type.NORMAL,
startDate: new Date(),
endDate: null,
}); });
return this.productRepository.findOneOrFail(result.identifiers[0].id); return this.productRepository.findOneOrFail(result.identifiers[0].id);
@ -81,6 +96,7 @@ export class ProductService {
code: updateProductDto.code, code: updateProductDto.code,
status: updateProductDto.status, status: updateProductDto.status,
subCategories: subCategories, subCategories: subCategories,
price: updateProductDto.price,
}); });
return this.productRepository.findOneOrFail(id); return this.productRepository.findOneOrFail(id);

View File

@ -0,0 +1,33 @@
import {
Entity,
Column,
PrimaryGeneratedColumn,
UpdateDateColumn,
DeleteDateColumn,
VersionColumn,
CreateDateColumn,
ManyToOne,
ManyToMany,
JoinTable,
} from 'typeorm';
import { Product } from '../../product/entities/product.entity';
import { User } from '../../users/entities/user.entity';
import { BaseModel } from '../../config/basemodel.entity';
enum balanceType {
DEBIT,
CREDIT,
}
@Entity()
export class CoaType extends BaseModel {
@Column()
name: string;
@Column('text')
normalBalance: balanceType;
@ManyToMany(() => User)
@JoinTable()
user: User[];
}