add: progress authentication
This commit is contained in:
@@ -8,6 +8,7 @@ import { LoggerModule } from 'nestjs-pino';
|
||||
import { TransactionModule } from './transaction/transaction.module';
|
||||
import { ProductModule } from './product/product.module';
|
||||
import { ConfigurableModule } from './configurable/configurable.module';
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
import configuration from './config/configuration';
|
||||
|
||||
@Module({
|
||||
@@ -50,6 +51,7 @@ import configuration from './config/configuration';
|
||||
UsersModule,
|
||||
TransactionModule,
|
||||
ConfigurableModule,
|
||||
AuthModule,
|
||||
// ProductModule,
|
||||
],
|
||||
})
|
||||
|
||||
9
src/auth/dto/input-login.dto.ts
Normal file
9
src/auth/dto/input-login.dto.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class InputLoginDto {
|
||||
@IsNotEmpty()
|
||||
username: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
password: string;
|
||||
}
|
||||
9
src/auth/dto/response-login.dto.ts
Normal file
9
src/auth/dto/response-login.dto.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class ResponseLoginDto {
|
||||
@IsNotEmpty()
|
||||
username: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
jwt: string;
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
Param,
|
||||
Delete,
|
||||
ParseUUIDPipe,
|
||||
HttpStatus,
|
||||
HttpStatus, Query,
|
||||
} from '@nestjs/common';
|
||||
import { ConfigurableService } from './configurable.service';
|
||||
|
||||
@@ -19,8 +19,8 @@ export class ConfigurableController {
|
||||
constructor(private readonly usersService: ConfigurableService) {}
|
||||
|
||||
@Get()
|
||||
async findAll() {
|
||||
const [data, count] = await this.usersService.findAll();
|
||||
async findAll(@Query('page') page: number) {
|
||||
const [data, count] = await this.usersService.findAllRoles(page);
|
||||
|
||||
return {
|
||||
data,
|
||||
|
||||
@@ -10,8 +10,14 @@ export class ConfigurableService {
|
||||
private rolesRepository: Repository<Roles>,
|
||||
) {}
|
||||
|
||||
findAll() {
|
||||
return this.rolesRepository.findAndCount();
|
||||
findAllRoles(page) {
|
||||
return this.rolesRepository.findAndCount({
|
||||
skip: page * 10,
|
||||
take: 10,
|
||||
order: {
|
||||
version: 'DESC',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
|
||||
10
src/helper/hash_password.ts
Normal file
10
src/helper/hash_password.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
export function hashPassword(password, salt): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
crypto.pbkdf2(password, salt, 50, 100, 'sha512', (err, values) => {
|
||||
if (err) return reject(err);
|
||||
resolve(values.toString('hex'));
|
||||
});
|
||||
});
|
||||
}
|
||||
22
src/helper/jwt.strategy.ts
Normal file
22
src/helper/jwt.strategy.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
|
||||
@Injectable()
|
||||
export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
constructor(private readonly authService: AuthService) {
|
||||
super({
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
secretOrKey: process.env.SECRETKEY,
|
||||
});
|
||||
}
|
||||
|
||||
async validate(payload: JwtPayload): Promise<UserDto> {
|
||||
const user = await this.authService.validateUser(payload);
|
||||
if (!user) {
|
||||
throw new HttpException('Invalid token', HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,10 @@ import {
|
||||
UpdateDateColumn,
|
||||
DeleteDateColumn,
|
||||
VersionColumn,
|
||||
CreateDateColumn, ManyToOne, ManyToMany, JoinTable,
|
||||
CreateDateColumn,
|
||||
ManyToOne,
|
||||
ManyToMany,
|
||||
JoinTable,
|
||||
} from 'typeorm';
|
||||
import { Product } from '../../product/entities/product.entity';
|
||||
import { User } from '../../users/entities/user.entity';
|
||||
@@ -22,10 +25,7 @@ enum balanceType {
|
||||
}
|
||||
|
||||
@Entity()
|
||||
export class Roles extends BaseModel{
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
export class COA extends BaseModel {
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@@ -1 +1,38 @@
|
||||
export class Transaction {}
|
||||
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';
|
||||
import { COA } from './coa.entity';
|
||||
import { ProductHistoryPrice } from '../../product/entities/product-history-price.entity';
|
||||
|
||||
enum status {
|
||||
PENDING,
|
||||
SUCCESS,
|
||||
FAILED,
|
||||
}
|
||||
|
||||
@Entity()
|
||||
export class Transaction extends BaseModel {
|
||||
@Column()
|
||||
amount: number;
|
||||
|
||||
@Column()
|
||||
status: status;
|
||||
|
||||
@ManyToOne(() => User, (user) => user.id)
|
||||
user: User;
|
||||
|
||||
@ManyToOne(() => ProductHistoryPrice, (productHistory) => productHistory.id)
|
||||
product: ProductHistoryPrice;
|
||||
}
|
||||
|
||||
36
src/transaction/entities/transaction_journal.entity.ts
Normal file
36
src/transaction/entities/transaction_journal.entity.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
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';
|
||||
import { ProductCategories } from '../../product/entities/product-category.entity';
|
||||
import { COA } from './coa.entity';
|
||||
|
||||
enum type {
|
||||
SYSTEM_BANk,
|
||||
INCOME,
|
||||
}
|
||||
|
||||
enum balanceType {
|
||||
DEBIT,
|
||||
CREDIT,
|
||||
}
|
||||
|
||||
@Entity()
|
||||
export class TransactionJournal extends BaseModel {
|
||||
@Column('text')
|
||||
type: type;
|
||||
|
||||
@Column()
|
||||
amount: number;
|
||||
|
||||
@ManyToOne(() => COA, (coa) => coa.id)
|
||||
coa: COA;
|
||||
}
|
||||
@@ -1,45 +1,25 @@
|
||||
import {
|
||||
Entity,
|
||||
Column,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
DeleteDateColumn,
|
||||
VersionColumn,
|
||||
CreateDateColumn,
|
||||
PrimaryGeneratedColumn, BeforeInsert,
|
||||
} from 'typeorm';
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
import { hashPassword } from '../../helper/hash_password';
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
export class User extends BaseModel {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column()
|
||||
firstName: string;
|
||||
username: string;
|
||||
|
||||
@Column()
|
||||
lastName: string;
|
||||
password: string;
|
||||
|
||||
@Column()
|
||||
salt: string;
|
||||
|
||||
@Column({ default: true })
|
||||
isActive: boolean;
|
||||
|
||||
@CreateDateColumn({
|
||||
type: 'timestamp with time zone',
|
||||
nullable: false,
|
||||
})
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn({
|
||||
type: 'timestamp with time zone',
|
||||
nullable: false,
|
||||
})
|
||||
updatedAt: Date;
|
||||
|
||||
@DeleteDateColumn({
|
||||
type: 'timestamp with time zone',
|
||||
nullable: true,
|
||||
})
|
||||
deletedAt: Date;
|
||||
|
||||
@VersionColumn()
|
||||
version: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user